diff options
author | João Cunha <j.a.cunha@gmail.com> | 2019-07-05 12:49:08 +0100 |
---|---|---|
committer | João Cunha <j.a.cunha@gmail.com> | 2019-07-08 11:14:09 +0100 |
commit | 7319368fc75c95ad30324bf6405ec821b2159e3f (patch) | |
tree | 620152d4c4feee77cc25aeb2929b3500ba899ac9 | |
parent | 83154e0c076b652a360b1abf292024b82578e6a3 (diff) | |
download | gitlab-ce-7319368fc75c95ad30324bf6405ec821b2159e3f.tar.gz |
Implements post_uninstall in favor of dependent destroy
- We want to avoid having future problem with a dependent destroy
after hook.
5 files changed, 20 insertions, 4 deletions
diff --git a/app/models/clusters/applications/runner.rb b/app/models/clusters/applications/runner.rb index 1995b0f2cb3..7f6d95f59f3 100644 --- a/app/models/clusters/applications/runner.rb +++ b/app/models/clusters/applications/runner.rb @@ -12,7 +12,7 @@ module Clusters include ::Clusters::Concerns::ApplicationVersion include ::Clusters::Concerns::ApplicationData - belongs_to :runner, class_name: 'Ci::Runner', foreign_key: :runner_id, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent + belongs_to :runner, class_name: 'Ci::Runner', foreign_key: :runner_id delegate :project, :group, to: :cluster default_value_for :version, VERSION @@ -45,6 +45,10 @@ module Clusters runner.update(active: false) end + def post_uninstall + runner.destroy + end + private def ensure_runner diff --git a/app/models/clusters/concerns/application_core.rb b/app/models/clusters/concerns/application_core.rb index bc58755c970..803a65726d3 100644 --- a/app/models/clusters/concerns/application_core.rb +++ b/app/models/clusters/concerns/application_core.rb @@ -51,6 +51,11 @@ module Clusters # Override if your application needs any action before # being uninstalled by Helm end + + def post_uninstall + # Override if your application needs any action after + # being uninstalled by Helm + end end end end diff --git a/app/services/clusters/applications/check_uninstall_progress_service.rb b/app/services/clusters/applications/check_uninstall_progress_service.rb index 8786d295d6a..e51d84ef052 100644 --- a/app/services/clusters/applications/check_uninstall_progress_service.rb +++ b/app/services/clusters/applications/check_uninstall_progress_service.rb @@ -23,6 +23,7 @@ module Clusters private def on_success + app.post_uninstall app.destroy! rescue StandardError => e app.make_errored!(_('Application uninstalled but failed to destroy: %{error_message}') % { error_message: e.message }) diff --git a/spec/models/clusters/applications/runner_spec.rb b/spec/models/clusters/applications/runner_spec.rb index b9851ef3219..f239212bf0f 100644 --- a/spec/models/clusters/applications/runner_spec.rb +++ b/spec/models/clusters/applications/runner_spec.rb @@ -193,11 +193,11 @@ describe Clusters::Applications::Runner do end end - describe '#destroy!' do + describe '#post_uninstall' do it 'destroys its runner' do application_runner = create(:clusters_applications_runner, :scheduled, runner: ci_runner) - expect { application_runner.destroy! }.to change { Ci::Runner.count }.by(-1) + expect { application_runner.post_uninstall }.to change { Ci::Runner.count }.by(-1) end end end diff --git a/spec/services/clusters/applications/check_uninstall_progress_service_spec.rb b/spec/services/clusters/applications/check_uninstall_progress_service_spec.rb index 9ab83d913f5..a948b442441 100644 --- a/spec/services/clusters/applications/check_uninstall_progress_service_spec.rb +++ b/spec/services/clusters/applications/check_uninstall_progress_service_spec.rb @@ -41,7 +41,7 @@ describe Clusters::Applications::CheckUninstallProgressService do end end - context 'when application is installing' do + context 'when application is uninstalling' do RESCHEDULE_PHASES.each { |phase| it_behaves_like 'a not yet terminated installation', phase } context 'when installation POD succeeded' do @@ -56,6 +56,12 @@ describe Clusters::Applications::CheckUninstallProgressService do service.execute end + it 'runs application post_uninstall' do + expect(application).to receive(:post_uninstall).and_call_original + + service.execute + end + it 'destroys the application' do expect(worker_class).not_to receive(:perform_in) |