Class: Kube::Cluster::Standard::RoleBinding

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

Overview

A RoleBinding that wires a Role to a ServiceAccount. This is just the binding resource – the Role and ServiceAccount are defined separately (and emitted together by ServiceAccountWithRole):

RoleBinding.new(role: MyRole, service_account: MyServiceAccount)

The subject namespace is left blank when the ServiceAccount has none, so the SetNamespace middleware fills it with the target namespace.

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RoleBinding.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kube/cluster/standard/role_binding.rb', line 18

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

  subject = { kind: "ServiceAccount", name: .name }
  subject[:namespace] = .namespace if .namespace

  super() do
    .name = name
    self.roleRef = {
      apiGroup: "rbac.authorization.k8s.io",
      kind: "Role",
      name: role_name,
    }
    self.subjects = [subject]
    instance_exec(&block) if block
  end
end