diff options
author | Alessio Caiazza <acaiazza@gitlab.com> | 2017-11-02 18:55:02 +0100 |
---|---|---|
committer | Alessio Caiazza <acaiazza@gitlab.com> | 2017-11-03 10:57:09 +0100 |
commit | c46417c5064867d72debb15c4e280db24c6ab73c (patch) | |
tree | 5ab6d049cbeb94b4dc866a8dda5f589eb9dfb7fc /app/services/clusters | |
parent | 880cf60ba2a617ce31800b92e2ac6bb40cffe23a (diff) | |
download | gitlab-ce-c46417c5064867d72debb15c4e280db24c6ab73c.tar.gz |
Rename App to Applications
Diffstat (limited to 'app/services/clusters')
10 files changed, 111 insertions, 101 deletions
diff --git a/app/services/clusters/applications/base_helm_service.rb b/app/services/clusters/applications/base_helm_service.rb new file mode 100644 index 00000000000..68320a3b267 --- /dev/null +++ b/app/services/clusters/applications/base_helm_service.rb @@ -0,0 +1,25 @@ +module Clusters + module Applications + class BaseHelmService + attr_accessor :app + + def initialize(app) + @app = app + end + + protected + + def cluster + app.cluster + end + + def kubeclient + cluster.kubeclient + end + + def helm_api + @helm_api ||= Gitlab::Kubernetes::Helm.new(kubeclient) + end + end + end +end diff --git a/app/services/clusters/applications/check_installation_progress_service.rb b/app/services/clusters/applications/check_installation_progress_service.rb new file mode 100644 index 00000000000..4e8fd9baaf4 --- /dev/null +++ b/app/services/clusters/applications/check_installation_progress_service.rb @@ -0,0 +1,30 @@ +module Clusters + module Applications + class CheckInstallationProgressService < BaseHelmService + 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 + end + end + end + end +end diff --git a/app/services/clusters/applications/fetch_installation_status_service.rb b/app/services/clusters/applications/fetch_installation_status_service.rb new file mode 100644 index 00000000000..3d082485532 --- /dev/null +++ b/app/services/clusters/applications/fetch_installation_status_service.rb @@ -0,0 +1,15 @@ +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 diff --git a/app/services/clusters/applications/finalize_installation_service.rb b/app/services/clusters/applications/finalize_installation_service.rb new file mode 100644 index 00000000000..339d671c091 --- /dev/null +++ b/app/services/clusters/applications/finalize_installation_service.rb @@ -0,0 +1,17 @@ +module Clusters + module Applications + class FinalizeInstallationService < BaseHelmService + def execute + helm_api.delete_installation_pod!(app) + + app.make_errored!('Installation aborted') if aborted? + end + + private + + def aborted? + app.installing? || app.scheduled? + end + end + end +end diff --git a/app/services/clusters/applications/install_service.rb b/app/services/clusters/applications/install_service.rb new file mode 100644 index 00000000000..7fcccb5e78c --- /dev/null +++ b/app/services/clusters/applications/install_service.rb @@ -0,0 +1,24 @@ +module Clusters + module Applications + class InstallService < BaseHelmService + def execute + return unless app.scheduled? + + begin + helm_api.install(app) + + if app.make_installing + ClusterWaitForAppInstallationWorker.perform_in( + ClusterWaitForAppInstallationWorker::INITIAL_INTERVAL, app.name, app.id) + else + app.make_errored!("Failed to update app record; #{app.errors}") + end + rescue KubeException => ke + app.make_errored!("Kubernetes error: #{ke.message}") + rescue StandardError + app.make_errored!("Can't start installation process") + end + end + end + end +end diff --git a/app/services/clusters/base_helm_service.rb b/app/services/clusters/base_helm_service.rb deleted file mode 100644 index 0a95955a204..00000000000 --- a/app/services/clusters/base_helm_service.rb +++ /dev/null @@ -1,23 +0,0 @@ -module Clusters - class BaseHelmService - attr_accessor :app - - def initialize(app) - @app = app - end - - protected - - def cluster - app.cluster - end - - def kubeclient - cluster.kubeclient - end - - def helm_api - @helm_api ||= Gitlab::Kubernetes::Helm.new(kubeclient) - end - end -end diff --git a/app/services/clusters/check_app_installation_progress_service.rb b/app/services/clusters/check_app_installation_progress_service.rb deleted file mode 100644 index ff3398bbd63..00000000000 --- a/app/services/clusters/check_app_installation_progress_service.rb +++ /dev/null @@ -1,28 +0,0 @@ -module Clusters - class CheckAppInstallationProgressService < BaseHelmService - def execute - return unless app.installing? - - FetchAppInstallationStatusService.new(app).execute do |phase, log| - case phase - when 'Succeeded' - if app.make_installed - FinalizeAppInstallationService.new(app).execute - else - app.make_errored!("Failed to update app record; #{app.errors}") - end - when 'Failed' - app.make_errored!(log || 'Installation silently failed') - FinalizeAppInstallationService.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 - end - end - end -end diff --git a/app/services/clusters/fetch_app_installation_status_service.rb b/app/services/clusters/fetch_app_installation_status_service.rb deleted file mode 100644 index 9b281c77c49..00000000000 --- a/app/services/clusters/fetch_app_installation_status_service.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Clusters - class FetchAppInstallationStatusService < 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 diff --git a/app/services/clusters/finalize_app_installation_service.rb b/app/services/clusters/finalize_app_installation_service.rb deleted file mode 100644 index b9d5da063eb..00000000000 --- a/app/services/clusters/finalize_app_installation_service.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Clusters - class FinalizeAppInstallationService < BaseHelmService - def execute - helm_api.delete_installation_pod!(app) - - app.make_errored!('Installation aborted') if aborted? - end - - private - - def aborted? - app.installing? || app.scheduled? - end - end -end diff --git a/app/services/clusters/install_app_service.rb b/app/services/clusters/install_app_service.rb deleted file mode 100644 index 63f15abaa6d..00000000000 --- a/app/services/clusters/install_app_service.rb +++ /dev/null @@ -1,22 +0,0 @@ -module Clusters - class InstallAppService < BaseHelmService - def execute - return unless app.scheduled? - - begin - helm_api.install(app) - - if app.make_installing - ClusterWaitForAppInstallationWorker.perform_in( - ClusterWaitForAppInstallationWorker::INITIAL_INTERVAL, app.name, app.id) - else - app.make_errored!("Failed to update app record; #{app.errors}") - end - rescue KubeException => ke - app.make_errored!("Kubernetes error: #{ke.message}") - rescue StandardError - app.make_errored!("Can't start installation process") - end - end - end -end |