summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Caiazza <acaiazza@gitlab.com>2017-11-03 10:02:30 +0100
committerAlessio Caiazza <acaiazza@gitlab.com>2017-11-03 10:57:09 +0100
commit08752e5d742a144ffb1ec7c8e07e7a558774fbfc (patch)
tree8f7f3e698eafccfefcd0312e1c7abbda07fc3325
parentc46417c5064867d72debb15c4e280db24c6ab73c (diff)
downloadgitlab-ce-08752e5d742a144ffb1ec7c8e07e7a558774fbfc.tar.gz
Remove `Clusters::Applications::FetchInstallationStatusService`
-rw-r--r--app/models/clusters/cluster.rb2
-rw-r--r--app/services/clusters/applications/check_installation_progress_service.rb64
-rw-r--r--app/services/clusters/applications/fetch_installation_status_service.rb15
-rw-r--r--app/services/clusters/applications/install_service.rb2
-rw-r--r--app/workers/cluster_wait_for_app_installation_worker.rb3
-rw-r--r--lib/gitlab/kubernetes/pod.rb12
6 files changed, 60 insertions, 38 deletions
diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb
index 7dae2234998..77b299e46a0 100644
--- a/app/models/clusters/cluster.rb
+++ b/app/models/clusters/cluster.rb
@@ -52,7 +52,7 @@ module Clusters
end
def applications
- [
+ [
application_helm || build_application_helm
]
end
diff --git a/app/services/clusters/applications/check_installation_progress_service.rb b/app/services/clusters/applications/check_installation_progress_service.rb
index 4e8fd9baaf4..7f5a633b749 100644
--- a/app/services/clusters/applications/check_installation_progress_service.rb
+++ b/app/services/clusters/applications/check_installation_progress_service.rb
@@ -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
diff --git a/app/services/clusters/applications/fetch_installation_status_service.rb b/app/services/clusters/applications/fetch_installation_status_service.rb
deleted file mode 100644
index 3d082485532..00000000000
--- a/app/services/clusters/applications/fetch_installation_status_service.rb
+++ /dev/null
@@ -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
diff --git a/app/services/clusters/applications/install_service.rb b/app/services/clusters/applications/install_service.rb
index 7fcccb5e78c..5ed0968a98a 100644
--- a/app/services/clusters/applications/install_service.rb
+++ b/app/services/clusters/applications/install_service.rb
@@ -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
diff --git a/app/workers/cluster_wait_for_app_installation_worker.rb b/app/workers/cluster_wait_for_app_installation_worker.rb
index d5974c467c4..548f34fc6a5 100644
--- a/app/workers/cluster_wait_for_app_installation_worker.rb
+++ b/app/workers/cluster_wait_for_app_installation_worker.rb
@@ -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)
diff --git a/lib/gitlab/kubernetes/pod.rb b/lib/gitlab/kubernetes/pod.rb
new file mode 100644
index 00000000000..12a6bfcf816
--- /dev/null
+++ b/lib/gitlab/kubernetes/pod.rb
@@ -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