diff options
author | Thong Kuah <tkuah@gitlab.com> | 2018-09-07 22:24:39 +1200 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2018-09-14 16:26:51 +1200 |
commit | 8c8ccd3167ddb63485aa9e71affc737832d3846a (patch) | |
tree | 435781d5270a1f17c1733e45b69b18728eb820b0 /lib | |
parent | 9c5050b12226781d49d2ce25d47477eab6a4354b (diff) | |
download | gitlab-ce-8c8ccd3167ddb63485aa9e71affc737832d3846a.tar.gz |
Teach GitLab how to create Secret of type ServiceAccountToken
Add create_secret to KubeClient
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/kubernetes/kube_client.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/kubernetes/service_account_token.rb | 36 |
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/gitlab/kubernetes/kube_client.rb b/lib/gitlab/kubernetes/kube_client.rb index 8312b901524..2f03d73dfb4 100644 --- a/lib/gitlab/kubernetes/kube_client.rb +++ b/lib/gitlab/kubernetes/kube_client.rb @@ -31,6 +31,7 @@ module Gitlab :create_config_map, :create_namespace, :create_pod, + :create_secret, :create_service_account, :update_config_map, :update_service_account, diff --git a/lib/gitlab/kubernetes/service_account_token.rb b/lib/gitlab/kubernetes/service_account_token.rb new file mode 100644 index 00000000000..2e912b26c09 --- /dev/null +++ b/lib/gitlab/kubernetes/service_account_token.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Gitlab + module Kubernetes + class ServiceAccountToken + attr_reader :name, :service_account_name, :namespace_name + + def initialize(name, service_account_name, namespace_name) + @name = name + @service_account_name = service_account_name + @namespace_name = namespace_name + end + + def generate + ::Kubeclient::Resource.new(metadata: metadata, type: service_acount_token_type) + end + + private + + # as per https://kubernetes.io/docs/reference/access-authn-authz/service-accounts-admin/#to-create-additional-api-tokens + def service_acount_token_type + 'kubernetes.io/service-account-token' + end + + def metadata + { + name: name, + namespace: namespace_name, + annotations: { + "kubernetes.io/service-account.name": service_account_name + } + } + end + end + end +end |