Class: Kube::Cluster::Standard::JobWithServiceAccount

Inherits:
Manifest
  • Object
show all
Defined in:
lib/kube/cluster/standard/job_with_service_account.rb

Overview

A one-shot Job plus the ServiceAccount/Role/RoleBinding it runs as, bundled into one Manifest. The RBAC rules use the Role shorthand; the Job’s serviceAccountName is wired to the generated ServiceAccount. Everything is named after name.

JobWithServiceAccount.new(
  name:  "glauth-config-seed",
  image: "nixery.dev/shell/kubectl",
  rules: [
    "batch/cronjobs" => %w[get],
    "batch/jobs"     => %w[create],
  ],
  command: BashScript(<<~'SEED'),
    ...
  SEED
)

Instance Attribute Summary

Attributes inherited from Manifest

#resources

Instance Method Summary collapse

Methods inherited from Manifest

#<<

Constructor Details

#initialize(name:, image:, rules:, env: {}, command: nil, backoff_limit: 3, ttl: 300, &block) ⇒ JobWithServiceAccount

Returns a new instance of JobWithServiceAccount.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kube/cluster/standard/job_with_service_account.rb', line 27

def initialize(name:, image:, rules:, env: {}, command: nil,
               backoff_limit: 3, ttl: 300, &block)
   = Kube::Cluster::Standard::ServiceAccountWithRole.new(
    service_account: Kube::Cluster::Standard::ServiceAccount.new(name: name),
    role: Kube::Cluster::Standard::Role.new(rules: rules),
  )

  job = Kube::Cluster::Standard::Job.new(
    name: name,
    image: image,
    env: env,
    command: command,
    backoff_limit: backoff_limit,
    ttl: ttl,
  ) do
    spec.template.spec.serviceAccountName = name
  end

  super(*.to_a, job)

  instance_exec(&block) if block
end