diff options
author | Thong Kuah <tkuah@gitlab.com> | 2018-08-09 20:51:29 +1200 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2018-08-09 22:27:32 +1200 |
commit | 30dfe78b34de49da3de6fc5f8386930b8435c947 (patch) | |
tree | 8162b738644101737b033699284974204322cdb9 | |
parent | 68082d352516b5367fce76453b8992f4e44d127e (diff) | |
download | gitlab-ce-delete-config-maps-once-installed.tar.gz |
Delete config maps after we are done installing or we have errored or timed outdelete-config-maps-once-installed
4 files changed, 30 insertions, 0 deletions
diff --git a/app/services/clusters/applications/check_installation_progress_service.rb b/app/services/clusters/applications/check_installation_progress_service.rb index 35f5cff0e0c..b17f65cc4c8 100644 --- a/app/services/clusters/applications/check_installation_progress_service.rb +++ b/app/services/clusters/applications/check_installation_progress_service.rb @@ -24,12 +24,14 @@ module Clusters app.make_installed! ensure remove_installation_pod + remove_config_map end def on_failed app.make_errored!(installation_errors || 'Installation silently failed') ensure remove_installation_pod + remove_config_map end def check_timeout @@ -38,6 +40,7 @@ module Clusters app.make_errored!('Installation timed out') ensure remove_installation_pod + remove_config_map end else ClusterWaitForAppInstallationWorker.perform_in( @@ -49,6 +52,12 @@ module Clusters Time.now.utc - app.updated_at.to_time.utc > ClusterWaitForAppInstallationWorker::TIMEOUT end + # FIXME Prometheus relies on config maps! + def remove_config_map + config_map_name = ::Gitlab::Kubernetes::ConfigMap.new(app.name, app.files).config_map_name + helm_api.delete_config_map(config_map_name) + end + def remove_installation_pod helm_api.delete_pod!(install_command.pod_name) rescue diff --git a/lib/gitlab/kubernetes/helm/api.rb b/lib/gitlab/kubernetes/helm/api.rb index d65374cc23b..c55bcce9669 100644 --- a/lib/gitlab/kubernetes/helm/api.rb +++ b/lib/gitlab/kubernetes/helm/api.rb @@ -32,6 +32,10 @@ module Gitlab kubeclient.delete_pod(pod_name, namespace.name) end + def delete_config_map(config_map_name) + kubeclient.delete_config_map(config_map_name, namespace.name) + end + private attr_reader :kubeclient, :namespace diff --git a/spec/lib/gitlab/kubernetes/helm/api_spec.rb b/spec/lib/gitlab/kubernetes/helm/api_spec.rb index 341f71a3e49..91a324ea7e8 100644 --- a/spec/lib/gitlab/kubernetes/helm/api_spec.rb +++ b/spec/lib/gitlab/kubernetes/helm/api_spec.rb @@ -78,4 +78,13 @@ describe Gitlab::Kubernetes::Helm::Api do subject.delete_pod!(command.pod_name) end end + + describe '#delete_config_map' do + it 'deletes the ConfigMap from the kubernetes cluster' do + config_map_name = 'values-content-configuration-helm' + expect(client).to receive(:delete_config_map).with(config_map_name, gitlab_namespace).once + + subject.delete_config_map(config_map_name) + end + end end diff --git a/spec/services/clusters/applications/check_installation_progress_service_spec.rb b/spec/services/clusters/applications/check_installation_progress_service_spec.rb index 986f11410fd..b6408816395 100644 --- a/spec/services/clusters/applications/check_installation_progress_service_spec.rb +++ b/spec/services/clusters/applications/check_installation_progress_service_spec.rb @@ -14,6 +14,12 @@ describe Clusters::Applications::CheckInstallationProgressService do service.execute end + + it 'removes the config maps' do + expect(service).to receive(:remove_config_map).once + + service.execute + end end shared_examples 'a not yet terminated installation' do |a_phase| @@ -24,6 +30,7 @@ describe Clusters::Applications::CheckInstallationProgressService do it 'reschedule a new check' do expect(ClusterWaitForAppInstallationWorker).to receive(:perform_in).once expect(service).not_to receive(:remove_installation_pod) + expect(service).not_to receive(:remove_config_map) service.execute @@ -54,6 +61,7 @@ describe Clusters::Applications::CheckInstallationProgressService do allow(service).to receive(:installation_errors).and_return(errors) allow(service).to receive(:remove_installation_pod).and_return(nil) + allow(service).to receive(:remove_config_map).and_return(nil) end describe '#execute' do |