debian-mirror-gitlab/app/services/clusters/applications/check_installation_progress_service.rb

72 lines
1.6 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Clusters
module Applications
class CheckInstallationProgressService < BaseHelmService
def execute
2019-03-02 22:35:43 +05:30
return unless operation_in_progress?
2018-03-17 18:26:18 +05:30
case installation_phase
when Gitlab::Kubernetes::Pod::SUCCEEDED
on_success
when Gitlab::Kubernetes::Pod::FAILED
on_failed
else
check_timeout
end
2018-12-13 13:39:08 +05:30
rescue Kubeclient::HttpError => e
2019-02-15 15:39:39 +05:30
log_error(e)
2019-03-02 22:35:43 +05:30
app.make_errored!("Kubernetes error: #{e.error_code}")
2018-03-17 18:26:18 +05:30
end
private
2019-03-02 22:35:43 +05:30
def operation_in_progress?
app.installing? || app.updating?
end
2018-03-17 18:26:18 +05:30
def on_success
app.make_installed!
ensure
remove_installation_pod
end
def on_failed
2019-03-02 22:35:43 +05:30
app.make_errored!("Operation failed. Check pod logs for #{pod_name} for more details.")
2018-03-17 18:26:18 +05:30
end
def check_timeout
2019-07-31 22:56:46 +05:30
if timed_out?
2018-03-17 18:26:18 +05:30
begin
2019-03-02 22:35:43 +05:30
app.make_errored!("Operation timed out. Check pod logs for #{pod_name} for more details.")
2018-03-17 18:26:18 +05:30
end
else
ClusterWaitForAppInstallationWorker.perform_in(
ClusterWaitForAppInstallationWorker::INTERVAL, app.name, app.id)
end
end
2019-03-02 22:35:43 +05:30
def pod_name
install_command.pod_name
end
2019-07-31 22:56:46 +05:30
def timed_out?
Time.now.utc - app.updated_at.utc > ClusterWaitForAppInstallationWorker::TIMEOUT
2018-03-17 18:26:18 +05:30
end
def remove_installation_pod
2019-03-02 22:35:43 +05:30
helm_api.delete_pod!(pod_name)
2018-03-17 18:26:18 +05:30
end
def installation_phase
2019-03-02 22:35:43 +05:30
helm_api.status(pod_name)
2018-03-17 18:26:18 +05:30
end
def installation_errors
2019-03-02 22:35:43 +05:30
helm_api.log(pod_name)
2018-03-17 18:26:18 +05:30
end
end
end
end