Schedule k8s application installation with a service
This commit is contained in:
parent
1ca9aaf860
commit
49210dfff1
|
@ -5,12 +5,12 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll
|
||||||
before_action :authorize_create_cluster!, only: [:create]
|
before_action :authorize_create_cluster!, only: [:create]
|
||||||
|
|
||||||
def create
|
def create
|
||||||
return render_404 if application
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
# TODO: Do that via Service
|
scheduled = Clusters::Applications::ScheduleInstallationService.new(project, current_user,
|
||||||
if application_class.create(cluster: cluster).persisted?
|
application_class: @application_class,
|
||||||
|
cluster: @cluster).execute
|
||||||
|
if scheduled
|
||||||
head :no_data
|
head :no_data
|
||||||
else
|
else
|
||||||
head :bad_request
|
head :bad_request
|
||||||
|
@ -26,10 +26,6 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll
|
||||||
end
|
end
|
||||||
|
|
||||||
def application_class
|
def application_class
|
||||||
Clusters::Cluster::APPLICATIONS[params[:application]] || render_404
|
@application_class ||= Clusters::Cluster::APPLICATIONS[params[:application]] || render_404
|
||||||
end
|
|
||||||
|
|
||||||
def application
|
|
||||||
application_class.find_by(cluster: cluster)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,6 +11,8 @@ module Clusters
|
||||||
|
|
||||||
default_value_for :version, Gitlab::Kubernetes::Helm::HELM_VERSION
|
default_value_for :version, Gitlab::Kubernetes::Helm::HELM_VERSION
|
||||||
|
|
||||||
|
validates :cluster, presence: true
|
||||||
|
|
||||||
def name
|
def name
|
||||||
NAME
|
NAME
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,6 +23,14 @@ module Clusters
|
||||||
transition any - [:errored] => :errored
|
transition any - [:errored] => :errored
|
||||||
end
|
end
|
||||||
|
|
||||||
|
event :make_scheduled do
|
||||||
|
transition %i(installable errored) => :scheduled
|
||||||
|
end
|
||||||
|
|
||||||
|
before_transition any => [:scheduled] do |app_status, _|
|
||||||
|
app_status.status_reason = nil
|
||||||
|
end
|
||||||
|
|
||||||
before_transition any => [:errored] do |app_status, transition|
|
before_transition any => [:errored] do |app_status, transition|
|
||||||
status_reason = transition.args.first
|
status_reason = transition.args.first
|
||||||
app_status.status_reason = status_reason if status_reason
|
app_status.status_reason = status_reason if status_reason
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
module Clusters
|
||||||
|
module Applications
|
||||||
|
class ScheduleInstallationService < ::BaseService
|
||||||
|
def execute
|
||||||
|
application = application_class.find_or_create_by!(cluster: cluster)
|
||||||
|
|
||||||
|
application.make_scheduled!
|
||||||
|
ClusterInstallAppWorker.perform_async(application.name, application.id)
|
||||||
|
true
|
||||||
|
rescue ActiveRecord::RecordInvalid
|
||||||
|
false
|
||||||
|
rescue StateMachines::InvalidTransition
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def application_class
|
||||||
|
params[:application_class]
|
||||||
|
end
|
||||||
|
|
||||||
|
def cluster
|
||||||
|
params[:cluster]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue