diff options
author | Thong Kuah <tkuah@gitlab.com> | 2019-04-10 14:50:14 +1200 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-04-29 22:55:11 -0700 |
commit | 938e90f47288901790a96c50a8c0dfa2b7eab137 (patch) | |
tree | b7496ad378885c6aee32b199906386812cedf9d8 /app/services | |
parent | 33a765c17a246e4a2376056b1c301707c78806d0 (diff) | |
download | gitlab-ce-938e90f47288901790a96c50a8c0dfa2b7eab137.tar.gz |
Services to uninstall cluster application
+ to monitor progress of uninstallation pod
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/clusters/applications/check_uninstall_progress_service.rb | 62 | ||||
-rw-r--r-- | app/services/clusters/applications/uninstall_service.rb | 29 |
2 files changed, 91 insertions, 0 deletions
diff --git a/app/services/clusters/applications/check_uninstall_progress_service.rb b/app/services/clusters/applications/check_uninstall_progress_service.rb new file mode 100644 index 00000000000..2a2594a30c8 --- /dev/null +++ b/app/services/clusters/applications/check_uninstall_progress_service.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +module Clusters + module Applications + class CheckUninstallProgressService < BaseHelmService + def execute + return unless app.uninstalling? + + case installation_phase + when Gitlab::Kubernetes::Pod::SUCCEEDED + on_success + when Gitlab::Kubernetes::Pod::FAILED + on_failed + else + check_timeout + end + rescue Kubeclient::HttpError => e + log_error(e) + + app.make_errored!("Kubernetes error: #{e.error_code}") + end + + private + + def on_success + app.make_uninstalled! + ensure + remove_installation_pod + end + + def on_failed + app.make_errored!("Operation failed. Check pod logs for #{pod_name} for more details.") + end + + def check_timeout + if timeouted? + begin + app.make_errored!("Operation timed out. Check pod logs for #{pod_name} for more details.") + end + else + WaitForUninstallAppWorker.perform_in(WaitForUninstallAppWorker::INTERVAL, app.name, app.id) + end + end + + def pod_name + app.uninstall_command.pod_name + end + + def timeouted? + Time.now.utc - app.updated_at.to_time.utc > WaitForUninstallAppWorker::TIMEOUT + end + + def remove_installation_pod + helm_api.delete_pod!(pod_name) + end + + def installation_phase + helm_api.status(pod_name) + end + end + end +end diff --git a/app/services/clusters/applications/uninstall_service.rb b/app/services/clusters/applications/uninstall_service.rb new file mode 100644 index 00000000000..50c8d806c14 --- /dev/null +++ b/app/services/clusters/applications/uninstall_service.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Clusters + module Applications + class UninstallService < BaseHelmService + def execute + return unless app.scheduled? + + app.make_uninstalling! + uninstall + end + + private + + def uninstall + helm_api.uninstall(app.uninstall_command) + + Clusters::Applications::WaitForUninstallAppWorker.perform_in( + Clusters::Applications::WaitForUninstallAppWorker::INTERVAL, app.name, app.id) + rescue Kubeclient::HttpError => e + log_error(e) + app.make_errored!("Kubernetes error: #{e.error_code}") + rescue StandardError => e + log_error(e) + app.make_errored!('Failed to uninstall.') + end + end + end +end |