debian-mirror-gitlab/lib/gitlab/kubernetes/role_binding.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.1 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
module Gitlab
module Kubernetes
class RoleBinding
2019-09-30 21:07:59 +05:30
def initialize(name:, role_name:, role_kind:, namespace:, service_account_name:)
2018-12-13 13:39:08 +05:30
@name = name
@role_name = role_name
2019-09-30 21:07:59 +05:30
@role_kind = role_kind
2018-12-13 13:39:08 +05:30
@namespace = namespace
@service_account_name = service_account_name
end
def generate
::Kubeclient::Resource.new.tap do |resource|
resource.metadata = metadata
resource.roleRef = role_ref
resource.subjects = subjects
end
end
private
2019-09-30 21:07:59 +05:30
attr_reader :name, :role_name, :role_kind, :namespace, :service_account_name
2018-12-13 13:39:08 +05:30
def metadata
{ name: name, namespace: namespace }
end
def role_ref
{
apiGroup: 'rbac.authorization.k8s.io',
2019-09-30 21:07:59 +05:30
kind: role_kind,
2018-12-13 13:39:08 +05:30
name: role_name
}
end
def subjects
[
{
kind: 'ServiceAccount',
name: service_account_name,
namespace: namespace
}
]
end
end
end
end