diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-06-16 22:15:40 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-06-16 22:15:40 +0800 |
commit | 07a65da1d96a71474f6997aed95bac6290d81a42 (patch) | |
tree | eb45df72c20e76d087a0ee4fe8e1bbbe7efb19c9 /lib | |
parent | bcb7d88504f4f99a4e359730f342e1a88392508a (diff) | |
download | gitlab-ce-07a65da1d96a71474f6997aed95bac6290d81a42.tar.gz |
Generate KUBECONFIG in KubernetesService#predefined_variables
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/kubernetes.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/gitlab/kubernetes.rb b/lib/gitlab/kubernetes.rb index c56c1a4322f..cedef9b65ba 100644 --- a/lib/gitlab/kubernetes.rb +++ b/lib/gitlab/kubernetes.rb @@ -76,5 +76,44 @@ module Gitlab url.to_s end + + def to_kubeconfig(url:, namespace:, token:, ca_pem: nil) + config = { + apiVersion: 'v1', + clusters: [ + name: 'gitlab-deploy', + cluster: { + server: url + }, + ], + contexts: [ + name: 'gitlab-deploy', + context: { + cluster: 'gitlab-deploy', + namespace: namespace, + user: 'gitlab-deploy' + }, + ], + :'current-context' => 'gitlab-deploy', + kind: 'Config', + users: [ + { + name: 'gitlab-deploy', + user: {token: token} + } + ] + } + + kubeconfig_embed_ca_pem(config, ca_pem) if ca_pem + + config.deep_stringify_keys + end + + private + + def kubeconfig_embed_ca_pem(config, ca_pem) + cluster = config.dig(:clusters, 0, :cluster) + cluster[:'certificate-authority-data'] = ca_pem + end end end |