2018-10-22 17:47:54 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Kubernetes
|
|
|
|
class RoleBinding
|
2019-07-11 07:26:15 -04:00
|
|
|
def initialize(name:, role_name:, role_kind:, namespace:, service_account_name:)
|
2018-11-02 11:46:15 -04:00
|
|
|
@name = name
|
2018-10-22 17:47:54 -04:00
|
|
|
@role_name = role_name
|
2019-07-11 07:26:15 -04:00
|
|
|
@role_kind = role_kind
|
2018-10-22 17:47:54 -04:00
|
|
|
@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-07-11 07:26:15 -04:00
|
|
|
attr_reader :name, :role_name, :role_kind, :namespace, :service_account_name
|
2018-11-02 11:46:15 -04:00
|
|
|
|
2018-10-22 17:47:54 -04:00
|
|
|
def metadata
|
2018-11-02 11:46:15 -04:00
|
|
|
{ name: name, namespace: namespace }
|
2018-10-22 17:47:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def role_ref
|
|
|
|
{
|
|
|
|
apiGroup: 'rbac.authorization.k8s.io',
|
2019-07-11 07:26:15 -04:00
|
|
|
kind: role_kind,
|
2018-10-22 17:47:54 -04:00
|
|
|
name: role_name
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def subjects
|
|
|
|
[
|
|
|
|
{
|
|
|
|
kind: 'ServiceAccount',
|
|
|
|
name: service_account_name,
|
|
|
|
namespace: namespace
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|