Remove `Clusters::Applications::FetchInstallationStatusService`
This commit is contained in:
parent
c46417c506
commit
08752e5d74
|
@ -52,7 +52,7 @@ module Clusters
|
|||
end
|
||||
|
||||
def applications
|
||||
[
|
||||
[
|
||||
application_helm || build_application_helm
|
||||
]
|
||||
end
|
||||
|
|
|
@ -4,26 +4,52 @@ module Clusters
|
|||
def execute
|
||||
return unless app.installing?
|
||||
|
||||
FetchInstallationStatusService.new(app).execute do |phase, log|
|
||||
case phase
|
||||
when 'Succeeded'
|
||||
if app.make_installed
|
||||
FinalizeInstallationService.new(app).execute
|
||||
else
|
||||
app.make_errored!("Failed to update app record; #{app.errors}")
|
||||
end
|
||||
when 'Failed'
|
||||
app.make_errored!(log || 'Installation silently failed')
|
||||
FinalizeInstallationService.new(app).execute
|
||||
else
|
||||
if Time.now.utc - app.updated_at.to_time.utc > ClusterWaitForAppInstallationWorker::TIMEOUT
|
||||
app.make_errored!('App installation timeouted')
|
||||
else
|
||||
ClusterWaitForAppInstallationWorker.perform_in(
|
||||
ClusterWaitForAppInstallationWorker::EAGER_INTERVAL, app.name, app.id)
|
||||
end
|
||||
end
|
||||
case installation_phase
|
||||
when Gitlab::Kubernetes::Pod::SUCCEEDED
|
||||
on_succeeded
|
||||
when Gitlab::Kubernetes::Pod::FAILED
|
||||
on_failed
|
||||
else
|
||||
check_timeout
|
||||
end
|
||||
rescue KubeException => ke
|
||||
app.make_errored!("Kubernetes error: #{ke.message}") unless app.errored?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def on_succeeded
|
||||
if app.make_installed
|
||||
finalize_installation
|
||||
else
|
||||
app.make_errored!("Failed to update app record; #{app.errors}")
|
||||
end
|
||||
end
|
||||
|
||||
def on_failed
|
||||
app.make_errored!(log || 'Installation silently failed')
|
||||
finalize_installation
|
||||
end
|
||||
|
||||
def check_timeout
|
||||
if Time.now.utc - app.updated_at.to_time.utc > ClusterWaitForAppInstallationWorker::TIMEOUT
|
||||
app.make_errored!('App installation timeouted')
|
||||
else
|
||||
ClusterWaitForAppInstallationWorker.perform_in(
|
||||
ClusterWaitForAppInstallationWorker::INTERVAL, app.name, app.id)
|
||||
end
|
||||
end
|
||||
|
||||
def finilize_installation
|
||||
FinalizeInstallationService.new(app).execute
|
||||
end
|
||||
|
||||
def installation_phase
|
||||
helm_api.installation_status(app)
|
||||
end
|
||||
|
||||
def installation_errors
|
||||
helm_api.installation_log(app)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
module Clusters
|
||||
module Applications
|
||||
class FetchInstallationStatusService < BaseHelmService
|
||||
def execute
|
||||
return unless app.installing?
|
||||
|
||||
phase = helm_api.installation_status(app)
|
||||
log = helm_api.installation_log(app) if phase == 'Failed'
|
||||
yield(phase, log) if block_given?
|
||||
rescue KubeException => ke
|
||||
app.make_errored!("Kubernetes error: #{ke.message}") unless app.errored?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,7 +9,7 @@ module Clusters
|
|||
|
||||
if app.make_installing
|
||||
ClusterWaitForAppInstallationWorker.perform_in(
|
||||
ClusterWaitForAppInstallationWorker::INITIAL_INTERVAL, app.name, app.id)
|
||||
ClusterWaitForAppInstallationWorker::INTERVAL, app.name, app.id)
|
||||
else
|
||||
app.make_errored!("Failed to update app record; #{app.errors}")
|
||||
end
|
||||
|
|
|
@ -3,8 +3,7 @@ class ClusterWaitForAppInstallationWorker
|
|||
include ClusterQueue
|
||||
include ClusterApplications
|
||||
|
||||
INITIAL_INTERVAL = 30.seconds
|
||||
EAGER_INTERVAL = 10.seconds
|
||||
INTERVAL = 30.seconds
|
||||
TIMEOUT = 20.minutes
|
||||
|
||||
def perform(app_name, app_id)
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
module Gitlab
|
||||
module Kubernetes
|
||||
module Pod
|
||||
PENDING = 'Pending'.freeze
|
||||
RUNNING = 'Running'.freeze
|
||||
SUCCEEDED = 'Succeeded'.freeze
|
||||
FAILED = 'Failed'.freeze
|
||||
UNKNOWN = 'Unknown'.freeze
|
||||
PHASES = [PENDING, RUNNING, SUCCEEDED, FAILED, UNKNONW].freeze
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue