summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2018-09-07 22:24:39 +1200
committerThong Kuah <tkuah@gitlab.com>2018-09-14 16:26:51 +1200
commit8c8ccd3167ddb63485aa9e71affc737832d3846a (patch)
tree435781d5270a1f17c1733e45b69b18728eb820b0 /lib
parent9c5050b12226781d49d2ce25d47477eab6a4354b (diff)
downloadgitlab-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.rb1
-rw-r--r--lib/gitlab/kubernetes/service_account_token.rb36
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