diff options
author | Alessio Caiazza <acaiazza@gitlab.com> | 2017-11-02 11:14:10 +0100 |
---|---|---|
committer | Alessio Caiazza <acaiazza@gitlab.com> | 2017-11-02 11:14:39 +0100 |
commit | 6950f38f830079199c382c974b51ad73048a6939 (patch) | |
tree | 80f4275ba2bfa0a4a8124362003be85d79debe1f /app/workers | |
parent | 84f5aaa729d6286252602800a1f9e1bf1e5b47d3 (diff) | |
download | gitlab-ce-6950f38f830079199c382c974b51ad73048a6939.tar.gz |
Install k8s application with helm running inside the cluster
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/cluster_install_app_worker.rb | 11 | ||||
-rw-r--r-- | app/workers/cluster_wait_for_app_installation_worker.rb | 33 | ||||
-rw-r--r-- | app/workers/concerns/cluster_app.rb | 10 |
3 files changed, 54 insertions, 0 deletions
diff --git a/app/workers/cluster_install_app_worker.rb b/app/workers/cluster_install_app_worker.rb new file mode 100644 index 00000000000..4993b2b7349 --- /dev/null +++ b/app/workers/cluster_install_app_worker.rb @@ -0,0 +1,11 @@ +class ClusterInstallAppWorker + include Sidekiq::Worker + include ClusterQueue + include ClusterApp + + def perform(app_name, app_id) + find_app(app_name, app_id) do |app| + Clusters::InstallAppService.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 new file mode 100644 index 00000000000..21149cf2d19 --- /dev/null +++ b/app/workers/cluster_wait_for_app_installation_worker.rb @@ -0,0 +1,33 @@ +class ClusterWaitForAppInstallationWorker + include Sidekiq::Worker + include ClusterQueue + include ClusterApp + + 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::FetchAppInstallationStatusService.new(app).execute do |phase, log| + case phase + when 'Succeeded' + if app.make_installed + Clusters::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') + Clusters::FinalizeAppInstallationService.new(app).execute + else + if Time.now.utc - app.updated_at.to_time.utc > TIMEOUT + app.make_errored!('App installation timeouted') + else + ClusterWaitForAppInstallationWorker.perform_in(EAGER_INTERVAL, app.name, app.id) + end + end + end + end + end +end diff --git a/app/workers/concerns/cluster_app.rb b/app/workers/concerns/cluster_app.rb new file mode 100644 index 00000000000..2170f8be6f6 --- /dev/null +++ b/app/workers/concerns/cluster_app.rb @@ -0,0 +1,10 @@ +module ClusterApp + extend ActiveSupport::Concern + + included do + def find_app(app_name, id) + app = Clusters::Kubernetes.app(app_name).find(id) + yield(app) if block_given? + end + end +end |