Commit 3c8df0c9 authored by Thong Kuah's avatar Thong Kuah Committed by Stan Hu

Destroy app on successful uninstallation

Rescue and put into :uninstall_errored if something goes wrong while
destroying, which can happen. I think it is safe to expose the full
error message from the destroy error.

Remove the :uninstalled state as no longer used.
parent 938e90f4
...@@ -27,7 +27,6 @@ module Clusters ...@@ -27,7 +27,6 @@ module Clusters
state :update_errored, value: 6 state :update_errored, value: 6
state :uninstalling, value: 7 state :uninstalling, value: 7
state :uninstall_errored, value: 8 state :uninstall_errored, value: 8
state :uninstalled, value: 9
event :make_scheduled do event :make_scheduled do
transition [:installable, :errored, :installed, :updated, :update_errored, :uninstall_errored] => :scheduled transition [:installable, :errored, :installed, :updated, :update_errored, :uninstall_errored] => :scheduled
...@@ -60,10 +59,6 @@ module Clusters ...@@ -60,10 +59,6 @@ module Clusters
transition [:scheduled] => :uninstalling transition [:scheduled] => :uninstalling
end end
event :make_uninstalled do
transition [:uninstalling] => :uninstalled
end
before_transition any => [:scheduled] do |app_status, _| before_transition any => [:scheduled] do |app_status, _|
app_status.status_reason = nil app_status.status_reason = nil
end end
......
...@@ -23,7 +23,9 @@ module Clusters ...@@ -23,7 +23,9 @@ module Clusters
private private
def on_success def on_success
app.make_uninstalled! app.destroy!
rescue StandardError => e
app.make_errored!("Application uninstalled but failed to destroy: #{e.message}")
ensure ensure
remove_installation_pod remove_installation_pod
end end
......
...@@ -49,10 +49,6 @@ FactoryBot.define do ...@@ -49,10 +49,6 @@ FactoryBot.define do
status_reason 'something went wrong' status_reason 'something went wrong'
end end
trait :uninstalled do
status 9
end
trait :timeouted do trait :timeouted do
installing installing
updated_at { ClusterWaitForAppInstallationWorker::TIMEOUT.ago } updated_at { ClusterWaitForAppInstallationWorker::TIMEOUT.ago }
......
...@@ -56,13 +56,30 @@ describe Clusters::Applications::CheckUninstallProgressService do ...@@ -56,13 +56,30 @@ describe Clusters::Applications::CheckUninstallProgressService do
service.execute service.execute
end end
it 'make the application installed' do it 'destroys the application' do
expect(worker_class).not_to receive(:perform_in) expect(worker_class).not_to receive(:perform_in)
service.execute service.execute
expect(application).to be_destroyed
end
expect(application).to be_uninstalled context 'an error occurs while destroying' do
expect(application.status_reason).to be_nil before do
expect(application).to receive(:destroy!).once.and_raise("destroy failed")
end
it 'still removes the installation POD' do
expect(service).to receive(:remove_installation_pod).once
service.execute
end
it 'makes the application uninstall_errored' do
service.execute
expect(application).to be_uninstall_errored
expect(application.status_reason).to eq('Application uninstalled but failed to destroy: destroy failed')
end
end end
end end
......
...@@ -192,16 +192,6 @@ shared_examples 'cluster application status specs' do |application_name| ...@@ -192,16 +192,6 @@ shared_examples 'cluster application status specs' do |application_name|
expect(subject).to be_uninstalling expect(subject).to be_uninstalling
end end
end end
describe '#make_uninstalled' do
subject { create(application_name, :uninstalling) }
it 'is uninstalled' do
subject.make_uninstalled!
expect(subject).to be_uninstalled
end
end
end end
describe '#available?' do describe '#available?' do
...@@ -219,7 +209,6 @@ shared_examples 'cluster application status specs' do |application_name| ...@@ -219,7 +209,6 @@ shared_examples 'cluster application status specs' do |application_name|
:update_errored | false :update_errored | false
:uninstalling | false :uninstalling | false
:uninstall_errored | false :uninstall_errored | false
:uninstalled | false
:timeouted | false :timeouted | false
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment