Rename App to Applications
This commit is contained in:
parent
880cf60ba2
commit
c46417c506
15 changed files with 126 additions and 122 deletions
|
@ -1,4 +0,0 @@
|
||||||
module Clusters
|
|
||||||
module Concerns
|
|
||||||
end
|
|
||||||
end
|
|
25
app/services/clusters/applications/base_helm_service.rb
Normal file
25
app/services/clusters/applications/base_helm_service.rb
Normal file
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
24
app/services/clusters/applications/install_service.rb
Normal file
24
app/services/clusters/applications/install_service.rb
Normal file
|
@ -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
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -1,11 +1,11 @@
|
||||||
class ClusterInstallAppWorker
|
class ClusterInstallAppWorker
|
||||||
include Sidekiq::Worker
|
include Sidekiq::Worker
|
||||||
include ClusterQueue
|
include ClusterQueue
|
||||||
include ClusterApp
|
include ClusterApplications
|
||||||
|
|
||||||
def perform(app_name, app_id)
|
def perform(app_name, app_id)
|
||||||
find_app(app_name, app_id) do |app|
|
find_application(app_name, app_id) do |app|
|
||||||
Clusters::InstallAppService.new(app).execute
|
Clusters::Applications::InstallService.new(app).execute
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
class ClusterWaitForAppInstallationWorker
|
class ClusterWaitForAppInstallationWorker
|
||||||
include Sidekiq::Worker
|
include Sidekiq::Worker
|
||||||
include ClusterQueue
|
include ClusterQueue
|
||||||
include ClusterApp
|
include ClusterApplications
|
||||||
|
|
||||||
INITIAL_INTERVAL = 30.seconds
|
INITIAL_INTERVAL = 30.seconds
|
||||||
EAGER_INTERVAL = 10.seconds
|
EAGER_INTERVAL = 10.seconds
|
||||||
TIMEOUT = 20.minutes
|
TIMEOUT = 20.minutes
|
||||||
|
|
||||||
def perform(app_name, app_id)
|
def perform(app_name, app_id)
|
||||||
find_app(app_name, app_id) do |app|
|
find_application(app_name, app_id) do |app|
|
||||||
Clusters::CheckAppInstallationProgressService.new(app).execute
|
Clusters::Applications::CheckInstallationProgressService.new(app).execute
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
9
app/workers/concerns/cluster_applications.rb
Normal file
9
app/workers/concerns/cluster_applications.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue