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