Commit 004e8627 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'refactor_cluster_application_services' into 'master'

Refactor cluster application services

See merge request gitlab-org/gitlab-ce!27191
parents d30ac325 8dfec0ce
...@@ -7,6 +7,13 @@ module Clusters ...@@ -7,6 +7,13 @@ module Clusters
return unless app.scheduled? return unless app.scheduled?
app.make_installing! app.make_installing!
install
end
private
def install
log_event(:begin_install) log_event(:begin_install)
helm_api.install(install_command) helm_api.install(install_command)
...@@ -18,7 +25,7 @@ module Clusters ...@@ -18,7 +25,7 @@ module Clusters
app.make_errored!("Kubernetes error: #{e.error_code}") app.make_errored!("Kubernetes error: #{e.error_code}")
rescue StandardError => e rescue StandardError => e
log_error(e) log_error(e)
app.make_errored!("Can't start installation process.") app.make_errored!('Failed to install.')
end end
end end
end end
......
...@@ -8,6 +8,12 @@ module Clusters ...@@ -8,6 +8,12 @@ module Clusters
app.make_updating! app.make_updating!
patch
end
private
def patch
log_event(:begin_patch) log_event(:begin_patch)
helm_api.update(update_command) helm_api.update(update_command)
...@@ -16,10 +22,10 @@ module Clusters ...@@ -16,10 +22,10 @@ module Clusters
ClusterWaitForAppInstallationWorker::INTERVAL, app.name, app.id) ClusterWaitForAppInstallationWorker::INTERVAL, app.name, app.id)
rescue Kubeclient::HttpError => e rescue Kubeclient::HttpError => e
log_error(e) log_error(e)
app.make_update_errored!("Kubernetes error: #{e.error_code}") app.make_errored!("Kubernetes error: #{e.error_code}")
rescue StandardError => e rescue StandardError => e
log_error(e) log_error(e)
app.make_update_errored!("Can't start update process.") app.make_errored!('Failed to update.')
end end
end end
end end
......
...@@ -6,24 +6,28 @@ module Clusters ...@@ -6,24 +6,28 @@ module Clusters
def execute def execute
return unless app.scheduled? return unless app.scheduled?
begin app.make_updating!
app.make_updating!
log_event(:begin_upgrade) upgrade
# install_command works with upgrades too end
# as it basically does `helm upgrade --install`
helm_api.update(install_command) private
def upgrade
# install_command works with upgrades too
# as it basically does `helm upgrade --install`
log_event(:begin_upgrade)
helm_api.update(install_command)
log_event(:schedule_wait_for_upgrade) log_event(:schedule_wait_for_upgrade)
ClusterWaitForAppInstallationWorker.perform_in( ClusterWaitForAppInstallationWorker.perform_in(
ClusterWaitForAppInstallationWorker::INTERVAL, app.name, app.id) ClusterWaitForAppInstallationWorker::INTERVAL, app.name, app.id)
rescue Kubeclient::HttpError => e rescue Kubeclient::HttpError => e
log_error(e) log_error(e)
app.make_update_errored!("Kubernetes error: #{e.error_code}") app.make_errored!("Kubernetes error: #{e.error_code}")
rescue StandardError => e rescue StandardError => e
log_error(e) log_error(e)
app.make_update_errored!("Can't start upgrade process.") app.make_errored!('Failed to upgrade.')
end
end end
end end
end end
......
...@@ -58,7 +58,7 @@ describe Clusters::Applications::InstallService do ...@@ -58,7 +58,7 @@ describe Clusters::Applications::InstallService do
let(:error) { StandardError.new('something bad happened') } let(:error) { StandardError.new('something bad happened') }
before do before do
expect(application).to receive(:make_installing!).once.and_raise(error) expect(helm_client).to receive(:install).with(install_command).and_raise(error)
end end
include_examples 'logs kubernetes errors' do include_examples 'logs kubernetes errors' do
...@@ -68,12 +68,10 @@ describe Clusters::Applications::InstallService do ...@@ -68,12 +68,10 @@ describe Clusters::Applications::InstallService do
end end
it 'make the application errored' do it 'make the application errored' do
expect(helm_client).not_to receive(:install)
service.execute service.execute
expect(application).to be_errored expect(application).to be_errored
expect(application.status_reason).to eq("Can't start installation process.") expect(application.status_reason).to eq('Failed to install.')
end end
end end
end end
......
...@@ -66,16 +66,14 @@ describe Clusters::Applications::PatchService do ...@@ -66,16 +66,14 @@ describe Clusters::Applications::PatchService do
end end
before do before do
expect(application).to receive(:make_updating!).once.and_raise(error) expect(helm_client).to receive(:update).with(update_command).and_raise(error)
end end
it 'make the application errored' do it 'make the application errored' do
expect(helm_client).not_to receive(:update)
service.execute service.execute
expect(application).to be_update_errored expect(application).to be_update_errored
expect(application.status_reason).to eq("Can't start update process.") expect(application.status_reason).to eq('Failed to update.')
end end
end end
end end
......
...@@ -60,7 +60,7 @@ describe Clusters::Applications::UpgradeService do ...@@ -60,7 +60,7 @@ describe Clusters::Applications::UpgradeService do
let(:error) { StandardError.new('something bad happened') } let(:error) { StandardError.new('something bad happened') }
before do before do
expect(application).to receive(:make_updating!).once.and_raise(error) expect(helm_client).to receive(:update).with(install_command).and_raise(error)
end end
include_examples 'logs kubernetes errors' do include_examples 'logs kubernetes errors' do
...@@ -70,12 +70,10 @@ describe Clusters::Applications::UpgradeService do ...@@ -70,12 +70,10 @@ describe Clusters::Applications::UpgradeService do
end end
it 'make the application errored' do it 'make the application errored' do
expect(helm_client).not_to receive(:update)
service.execute service.execute
expect(application).to be_update_errored expect(application).to be_update_errored
expect(application.status_reason).to eq("Can't start upgrade process.") expect(application.status_reason).to eq('Failed to upgrade.')
end end
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