diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-27 21:06:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-27 21:06:30 +0300 |
commit | 20758bc3b33c04121d214cb89646baf880037a27 (patch) | |
tree | 66b821724d9e050002a956acefc1111c2ef0feab /lib | |
parent | a98649b71085bcd21af674a47d6a746336c56a65 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/quality/kubernetes_client.rb | 36 | ||||
-rw-r--r-- | lib/tasks/gitlab/cleanup.rake | 2 |
2 files changed, 34 insertions, 4 deletions
diff --git a/lib/quality/kubernetes_client.rb b/lib/quality/kubernetes_client.rb index cc899bf9374..db21c0b013b 100644 --- a/lib/quality/kubernetes_client.rb +++ b/lib/quality/kubernetes_client.rb @@ -4,6 +4,7 @@ require_relative '../gitlab/popen' unless defined?(Gitlab::Popen) module Quality class KubernetesClient + RESOURCE_LIST = 'ingress,svc,pdb,hpa,deploy,statefulset,job,pod,secret,configmap,pvc,secret,clusterrole,clusterrolebinding,role,rolebinding,sa,crd' CommandFailedError = Class.new(StandardError) attr_reader :namespace @@ -13,6 +14,13 @@ module Quality end def cleanup(release_name:, wait: true) + delete_by_selector(release_name: release_name, wait: wait) + delete_by_matching_name(release_name: release_name) + end + + private + + def delete_by_selector(release_name:, wait:) selector = case release_name when String %(-l release="#{release_name}") @@ -23,9 +31,9 @@ module Quality end command = [ - %(--namespace "#{namespace}"), 'delete', - 'ingress,svc,pdb,hpa,deploy,statefulset,job,pod,secret,configmap,pvc,secret,clusterrole,clusterrolebinding,role,rolebinding,sa', + RESOURCE_LIST, + %(--namespace "#{namespace}"), '--now', '--ignore-not-found', '--include-uninitialized', @@ -36,7 +44,29 @@ module Quality run_command(command) end - private + def delete_by_matching_name(release_name:) + resource_names = raw_resource_names + command = [ + 'delete', + %(--namespace "#{namespace}") + ] + + Array(release_name).each do |release| + resource_names + .select { |resource_name| resource_name.include?(release) } + .each { |matching_resource| run_command(command + [matching_resource]) } + end + end + + def raw_resource_names + command = [ + 'get', + RESOURCE_LIST, + %(--namespace "#{namespace}"), + '-o custom-columns=NAME:.metadata.name' + ] + run_command(command).lines.map(&:strip) + end def run_command(command) final_command = ['kubectl', *command].join(' ') diff --git a/lib/tasks/gitlab/cleanup.rake b/lib/tasks/gitlab/cleanup.rake index 0a0ee7b4bfa..63f5d7f2740 100644 --- a/lib/tasks/gitlab/cleanup.rake +++ b/lib/tasks/gitlab/cleanup.rake @@ -92,7 +92,7 @@ namespace :gitlab do lookup_key_count = redis.scard(key) session_ids = ActiveSession.session_ids_for_user(user_id) - entries = ActiveSession.raw_active_session_entries(session_ids, user_id) + entries = ActiveSession.raw_active_session_entries(redis, session_ids, user_id) session_ids_and_entries = session_ids.zip(entries) inactive_session_ids = session_ids_and_entries.map do |session_id, session| |