summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/clusters/concerns.rb4
-rw-r--r--app/services/clusters/applications/base_helm_service.rb25
-rw-r--r--app/services/clusters/applications/check_installation_progress_service.rb30
-rw-r--r--app/services/clusters/applications/fetch_installation_status_service.rb15
-rw-r--r--app/services/clusters/applications/finalize_installation_service.rb17
-rw-r--r--app/services/clusters/applications/install_service.rb24
-rw-r--r--app/services/clusters/base_helm_service.rb23
-rw-r--r--app/services/clusters/check_app_installation_progress_service.rb28
-rw-r--r--app/services/clusters/fetch_app_installation_status_service.rb13
-rw-r--r--app/services/clusters/finalize_app_installation_service.rb15
-rw-r--r--app/services/clusters/install_app_service.rb22
-rw-r--r--app/workers/cluster_install_app_worker.rb6
-rw-r--r--app/workers/cluster_wait_for_app_installation_worker.rb6
-rw-r--r--app/workers/concerns/cluster_app.rb11
-rw-r--r--app/workers/concerns/cluster_applications.rb9
15 files changed, 126 insertions, 122 deletions
diff --git a/app/models/clusters/concerns.rb b/app/models/clusters/concerns.rb
deleted file mode 100644
index cd09863bcfc..00000000000
--- a/app/models/clusters/concerns.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-module Clusters
- module Concerns
- end
-end
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
diff --git a/app/workers/cluster_install_app_worker.rb b/app/workers/cluster_install_app_worker.rb
index 4993b2b7349..899aed904e4 100644
--- a/app/workers/cluster_install_app_worker.rb
+++ b/app/workers/cluster_install_app_worker.rb
@@ -1,11 +1,11 @@
class ClusterInstallAppWorker
include Sidekiq::Worker
include ClusterQueue
- include ClusterApp
+ include ClusterApplications
def perform(app_name, app_id)
- find_app(app_name, app_id) do |app|
- Clusters::InstallAppService.new(app).execute
+ find_application(app_name, app_id) do |app|
+ Clusters::Applications::InstallService.new(app).execute
end
end
end
diff --git a/app/workers/cluster_wait_for_app_installation_worker.rb b/app/workers/cluster_wait_for_app_installation_worker.rb
index 7e480c42fd4..d5974c467c4 100644
--- a/app/workers/cluster_wait_for_app_installation_worker.rb
+++ b/app/workers/cluster_wait_for_app_installation_worker.rb
@@ -1,15 +1,15 @@
class ClusterWaitForAppInstallationWorker
include Sidekiq::Worker
include ClusterQueue
- include ClusterApp
+ include ClusterApplications
INITIAL_INTERVAL = 30.seconds
EAGER_INTERVAL = 10.seconds
TIMEOUT = 20.minutes
def perform(app_name, app_id)
- find_app(app_name, app_id) do |app|
- Clusters::CheckAppInstallationProgressService.new(app).execute
+ find_application(app_name, app_id) do |app|
+ Clusters::Applications::CheckInstallationProgressService.new(app).execute
end
end
end
diff --git a/app/workers/concerns/cluster_app.rb b/app/workers/concerns/cluster_app.rb
deleted file mode 100644
index 947cdaefcb7..00000000000
--- a/app/workers/concerns/cluster_app.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module ClusterApp
- extend ActiveSupport::Concern
-
- included do
- def find_app(app_name, id)
- Clusters::Cluster::APPLICATIONS[app_name].find(id).try do |app|
- yield(app) if block_given?
- end
- end
- end
-end
diff --git a/app/workers/concerns/cluster_applications.rb b/app/workers/concerns/cluster_applications.rb
new file mode 100644
index 00000000000..24ecaa0b52f
--- /dev/null
+++ b/app/workers/concerns/cluster_applications.rb
@@ -0,0 +1,9 @@
+module ClusterApplications
+ extend ActiveSupport::Concern
+
+ included do
+ def find_application(app_name, id, &blk)
+ Clusters::Cluster::APPLICATIONS[app_name].find(id).try(&blk)
+ end
+ end
+end