Skip to content
Snippets Groups Projects
Commit a134b2ce authored by Dylan Griffith's avatar Dylan Griffith
Browse files

Merge branch 'hustewart-wait-app-update' into 'master'

Noop job and delete unused service

See merge request !102913



Merged-by: default avatarDylan Griffith <dyl.griffith@gmail.com>
Approved-by: Jessie Young's avatarJessie Young <jessieyoung@gitlab.com>
Approved-by: default avatarDylan Griffith <dyl.griffith@gmail.com>
Co-authored-by: default avatarhustewart <hustewart@gitlab.com>
parents 74e912fb 9fe4dd52
No related branches found
No related tags found
1 merge request!102913Noop job and delete unused service
Pipeline #687019226 passed
# frozen_string_literal: true
module Clusters
module Applications
class CheckUpgradeProgressService < BaseHelmService
def execute
return unless app.updating?
case phase
when ::Gitlab::Kubernetes::Pod::SUCCEEDED
on_success
when ::Gitlab::Kubernetes::Pod::FAILED
on_failed
else
check_timeout
end
rescue ::Kubeclient::HttpError => e
app.make_update_errored!("Kubernetes error: #{e.message}") unless app.update_errored?
end
private
def on_success
app.make_installed!
ensure
remove_pod
end
def on_failed
app.make_update_errored!(errors || 'Update silently failed')
ensure
remove_pod
end
def check_timeout
if timed_out?
begin
app.make_update_errored!('Update timed out')
ensure
remove_pod
end
else
::ClusterWaitForAppUpdateWorker.perform_in(
::ClusterWaitForAppUpdateWorker::INTERVAL, app.name, app.id)
end
end
def timed_out?
Time.current.utc - app.updated_at.to_time.utc > ::ClusterWaitForAppUpdateWorker::TIMEOUT
end
def remove_pod
helm_api.delete_pod!(pod_name)
rescue StandardError
# no-op
end
def phase
helm_api.status(pod_name)
end
def errors
helm_api.log(pod_name)
end
def pod_name
@pod_name ||= patch_command.pod_name
end
end
end
end
# frozen_string_literal: true
# DEPRECATED
#
# To be removed by https://gitlab.com/gitlab-org/gitlab/-/issues/366573
class ClusterWaitForAppUpdateWorker # rubocop:disable Scalability/IdempotentWorker
include ApplicationWorker
......@@ -14,9 +17,5 @@ class ClusterWaitForAppUpdateWorker # rubocop:disable Scalability/IdempotentWork
loggable_arguments 0
def perform(app_name, app_id)
find_application(app_name, app_id) do |app|
::Clusters::Applications::CheckUpgradeProgressService.new(app).execute
end
end
def perform(app_name, app_id); end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Applications::CheckUpgradeProgressService do
reschedule_phashes = ::Gitlab::Kubernetes::Pod::PHASES -
[::Gitlab::Kubernetes::Pod::SUCCEEDED, ::Gitlab::Kubernetes::Pod::FAILED, ::Gitlab].freeze
let(:application) { create(:clusters_applications_prometheus, :updating) }
let(:service) { described_class.new(application) }
let(:phase) { ::Gitlab::Kubernetes::Pod::UNKNOWN }
let(:errors) { nil }
shared_examples 'a terminated upgrade' do
it 'removes the POD' do
expect(service).to receive(:remove_pod).once
service.execute
end
end
shared_examples 'a not yet terminated upgrade' do |a_phase|
let(:phase) { a_phase }
context "when phase is #{a_phase}" do
context 'when not timed out' do
it 'reschedule a new check' do
expect(::ClusterWaitForAppUpdateWorker).to receive(:perform_in).once
expect(service).not_to receive(:remove_pod)
service.execute
expect(application).to be_updating
expect(application.status_reason).to be_nil
end
end
context 'when timed out' do
let(:application) { create(:clusters_applications_prometheus, :timed_out, :updating) }
it_behaves_like 'a terminated upgrade'
it 'make the application update errored' do
expect(::ClusterWaitForAppUpdateWorker).not_to receive(:perform_in)
service.execute
expect(application).to be_update_errored
expect(application.status_reason).to eq("Update timed out")
end
end
end
end
before do
allow(service).to receive(:phase).once.and_return(phase)
allow(service).to receive(:errors).and_return(errors)
allow(service).to receive(:remove_pod).and_return(nil)
end
describe '#execute' do
context 'when upgrade pod succeeded' do
let(:phase) { ::Gitlab::Kubernetes::Pod::SUCCEEDED }
it_behaves_like 'a terminated upgrade'
it 'make the application upgraded' do
expect(::ClusterWaitForAppUpdateWorker).not_to receive(:perform_in)
service.execute
expect(application).to be_updated
expect(application.status_reason).to be_nil
end
end
context 'when upgrade pod failed' do
let(:phase) { ::Gitlab::Kubernetes::Pod::FAILED }
let(:errors) { 'test installation failed' }
it_behaves_like 'a terminated upgrade'
it 'make the application update errored' do
service.execute
expect(application).to be_update_errored
expect(application.status_reason).to eq(errors)
end
end
reschedule_phashes.each { |phase| it_behaves_like 'a not yet terminated upgrade', phase }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ClusterWaitForAppUpdateWorker do
let(:check_upgrade_progress_service) { spy }
before do
allow(::Clusters::Applications::CheckUpgradeProgressService).to receive(:new).and_return(check_upgrade_progress_service)
end
it 'runs CheckUpgradeProgressService when application is found' do
application = create(:clusters_applications_prometheus)
expect(check_upgrade_progress_service).to receive(:execute)
subject.perform(application.name, application.id)
end
it 'does not run CheckUpgradeProgressService when application is not found' do
expect(check_upgrade_progress_service).not_to receive(:execute)
expect do
subject.perform("prometheus", -1)
end.to raise_error(ActiveRecord::RecordNotFound)
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment