Commit 86d85317 authored by Alessio Caiazza's avatar Alessio Caiazza

Remove Clusters::Applications::FinalizeInstallationService

parent a46d3241
...@@ -6,7 +6,7 @@ module Clusters ...@@ -6,7 +6,7 @@ module Clusters
case installation_phase case installation_phase
when Gitlab::Kubernetes::Pod::SUCCEEDED when Gitlab::Kubernetes::Pod::SUCCEEDED
finalize_installation on_success
when Gitlab::Kubernetes::Pod::FAILED when Gitlab::Kubernetes::Pod::FAILED
on_failed on_failed
else else
...@@ -18,23 +18,39 @@ module Clusters ...@@ -18,23 +18,39 @@ module Clusters
private private
def on_success
app.make_installed!
ensure
remove_installation_pod
end
def on_failed def on_failed
app.make_errored!(installation_errors || 'Installation silently failed') app.make_errored!(installation_errors || 'Installation silently failed')
finalize_installation ensure
remove_installation_pod
end end
def check_timeout def check_timeout
if Time.now.utc - app.updated_at.to_time.utc > ClusterWaitForAppInstallationWorker::TIMEOUT if timeouted?
begin
app.make_errored!('Installation timeouted') app.make_errored!('Installation timeouted')
finalize_installation ensure
remove_installation_pod
end
else else
ClusterWaitForAppInstallationWorker.perform_in( ClusterWaitForAppInstallationWorker.perform_in(
ClusterWaitForAppInstallationWorker::INTERVAL, app.name, app.id) ClusterWaitForAppInstallationWorker::INTERVAL, app.name, app.id)
end end
end end
def finalize_installation def timeouted?
FinalizeInstallationService.new(app).execute Time.now.utc - app.updated_at.to_time.utc > ClusterWaitForAppInstallationWorker::TIMEOUT
end
def remove_installation_pod
helm_api.delete_installation_pod!(app)
rescue
# no-op
end end
def installation_phase def installation_phase
......
module Clusters
module Applications
class FinalizeInstallationService < BaseHelmService
def execute
helm_api.delete_installation_pod!(app)
app.make_installed! if app.installing?
end
end
end
end
...@@ -9,8 +9,8 @@ describe Clusters::Applications::CheckInstallationProgressService do ...@@ -9,8 +9,8 @@ describe Clusters::Applications::CheckInstallationProgressService do
let(:errors) { nil } let(:errors) { nil }
shared_examples 'a terminated installation' do shared_examples 'a terminated installation' do
it 'finalize the installation' do it 'removes the installation POD' do
expect(service).to receive(:finalize_installation).once expect(service).to receive(:remove_installation_pod).once
service.execute service.execute
end end
...@@ -23,7 +23,7 @@ describe Clusters::Applications::CheckInstallationProgressService do ...@@ -23,7 +23,7 @@ describe Clusters::Applications::CheckInstallationProgressService do
context 'when not timeouted' do context 'when not timeouted' do
it 'reschedule a new check' do it 'reschedule a new check' do
expect(ClusterWaitForAppInstallationWorker).to receive(:perform_in).once expect(ClusterWaitForAppInstallationWorker).to receive(:perform_in).once
expect(service).not_to receive(:finalize_installation) expect(service).not_to receive(:remove_installation_pod)
service.execute service.execute
...@@ -53,7 +53,7 @@ describe Clusters::Applications::CheckInstallationProgressService do ...@@ -53,7 +53,7 @@ describe Clusters::Applications::CheckInstallationProgressService do
expect(service).to receive(:installation_phase).once.and_return(phase) expect(service).to receive(:installation_phase).once.and_return(phase)
allow(service).to receive(:installation_errors).and_return(errors) allow(service).to receive(:installation_errors).and_return(errors)
allow(service).to receive(:finalize_installation).and_return(nil) allow(service).to receive(:remove_installation_pod).and_return(nil)
end end
describe '#execute' do describe '#execute' do
...@@ -61,6 +61,15 @@ describe Clusters::Applications::CheckInstallationProgressService do ...@@ -61,6 +61,15 @@ describe Clusters::Applications::CheckInstallationProgressService do
let(:phase) { Gitlab::Kubernetes::Pod::SUCCEEDED } let(:phase) { Gitlab::Kubernetes::Pod::SUCCEEDED }
it_behaves_like 'a terminated installation' it_behaves_like 'a terminated installation'
it 'make the application installed' do
expect(ClusterWaitForAppInstallationWorker).not_to receive(:perform_in)
service.execute
expect(application).to be_installed
expect(application.status_reason).to be_nil
end
end end
context 'when installation POD failed' do context 'when installation POD failed' do
......
require 'spec_helper'
describe Clusters::Applications::FinalizeInstallationService do
describe '#execute' do
let(:application) { create(:applications_helm, :installing) }
let(:service) { described_class.new(application) }
before do
expect_any_instance_of(Gitlab::Kubernetes::Helm).to receive(:delete_installation_pod!).with(application)
end
context 'when installation POD succeeded' do
it 'make the application installed' do
service.execute
expect(application).to be_installed
expect(application.status_reason).to be_nil
end
end
context 'when installation POD failed' do
let(:application) { create(:applications_helm, :errored) }
it 'make the application errored' do
service.execute
expect(application).to be_errored
expect(application.status_reason).not_to be_nil
end
end
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