diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-12-05 12:28:28 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-12-05 12:28:28 +0300 |
commit | 9a563b1b42642a502e1238ee12f0a1a09dd8a6b2 (patch) | |
tree | 42825c0f15433d68ab78a71a29b3db9cf0ace317 /lib | |
parent | b53ebd93b15b2fb9eba7c9d6e31b1ffffe073912 (diff) | |
parent | c0c75c80008a3aab832860fd8e12dfe88f1e7fde (diff) |
Merge branch 'retryable_create_or_update_kubernetes_namespace' into 'master'
Update K8s project namespace and ServiceAccount if exist
See merge request gitlab-org/gitlab-ce!23525
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/kubernetes/kube_client.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/gitlab/kubernetes/kube_client.rb b/lib/gitlab/kubernetes/kube_client.rb index b947f6b551e..fe839940f74 100644 --- a/lib/gitlab/kubernetes/kube_client.rb +++ b/lib/gitlab/kubernetes/kube_client.rb @@ -46,6 +46,7 @@ module Gitlab :create_secret, :create_service_account, :update_config_map, + :update_secret, :update_service_account, to: :core_client @@ -80,8 +81,64 @@ module Gitlab @kubeclient_options = kubeclient_options end + def create_or_update_cluster_role_binding(resource) + if cluster_role_binding_exists?(resource) + update_cluster_role_binding(resource) + else + create_cluster_role_binding(resource) + end + end + + def create_or_update_role_binding(resource) + if role_binding_exists?(resource) + update_role_binding(resource) + else + create_role_binding(resource) + end + end + + def create_or_update_service_account(resource) + if service_account_exists?(resource) + update_service_account(resource) + else + create_service_account(resource) + end + end + + def create_or_update_secret(resource) + if secret_exists?(resource) + update_secret(resource) + else + create_secret(resource) + end + end + private + def cluster_role_binding_exists?(resource) + get_cluster_role_binding(resource.metadata.name) + rescue ::Kubeclient::ResourceNotFoundError + false + end + + def role_binding_exists?(resource) + get_role_binding(resource.metadata.name, resource.metadata.namespace) + rescue ::Kubeclient::ResourceNotFoundError + false + end + + def service_account_exists?(resource) + get_service_account(resource.metadata.name, resource.metadata.namespace) + rescue ::Kubeclient::ResourceNotFoundError + false + end + + def secret_exists?(resource) + get_secret(resource.metadata.name, resource.metadata.namespace) + rescue ::Kubeclient::ResourceNotFoundError + false + end + def build_kubeclient(api_group, api_version) ::Kubeclient::Client.new( join_api_url(api_prefix, api_group), |