Class: Kube::Cluster::Standard::ServiceAccountWithRole

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

Overview

Bundles a ServiceAccount, a Role, and the RoleBinding that ties them together into one Manifest. The Role and RoleBinding take the ServiceAccount’s name unless a name is given explicitly:

ServiceAccountWithRole.new(
  service_account: ServiceAccount.new(name: "glauth-config-builder"),
  role: Role.new(rules: [
    "secrets"        => %w[get list],
    "batch/cronjobs" => %w[get],
  ]),
)

Instance Attribute Summary

Attributes inherited from Manifest

#resources

Instance Method Summary collapse

Methods inherited from Manifest

#<<

Constructor Details

#initialize(service_account:, role:, name: nil, &block) ⇒ ServiceAccountWithRole

Returns a new instance of ServiceAccountWithRole.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kube/cluster/standard/service_account_with_role.rb', line 22

def initialize(service_account:, role:, name: nil, &block)
  name ||= .name

  # Rebuild the Role with the derived name (a Standard::Role, so the
  # binding's role.name reader works).
  named_role = Kube::Cluster::Standard::Role.new(name: name, rules: role.rules_input)

  role_binding = Kube::Cluster::Standard::RoleBinding.new(
    role: named_role,
    service_account: ,
    name: name,
  )

  super(, named_role, role_binding)

  instance_exec(&block) if block
end