2018-08-03 03:15:25 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-02 06:14:10 -04:00
|
|
|
module Clusters
|
|
|
|
module Concerns
|
2017-11-02 12:57:50 -04:00
|
|
|
module ApplicationStatus
|
2017-11-02 06:14:10 -04:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2019-02-15 06:16:45 -05:00
|
|
|
scope :available, -> do
|
|
|
|
where(
|
|
|
|
status: [
|
|
|
|
self.state_machines[:status].states[:installed].value,
|
|
|
|
self.state_machines[:status].states[:updated].value
|
|
|
|
]
|
|
|
|
)
|
|
|
|
end
|
2018-03-29 16:08:13 -04:00
|
|
|
|
2017-11-07 08:26:14 -05:00
|
|
|
state_machine :status, initial: :not_installable do
|
2017-11-06 09:48:44 -05:00
|
|
|
state :not_installable, value: -2
|
2017-11-02 06:14:10 -04:00
|
|
|
state :errored, value: -1
|
2017-11-02 12:57:50 -04:00
|
|
|
state :installable, value: 0
|
|
|
|
state :scheduled, value: 1
|
|
|
|
state :installing, value: 2
|
|
|
|
state :installed, value: 3
|
2018-09-26 23:52:30 -04:00
|
|
|
state :updating, value: 4
|
|
|
|
state :updated, value: 5
|
|
|
|
state :update_errored, value: 6
|
2017-11-02 06:14:10 -04:00
|
|
|
|
2017-11-07 04:07:22 -05:00
|
|
|
event :make_scheduled do
|
2019-02-07 16:40:55 -05:00
|
|
|
transition [:installable, :errored, :installed, :updated, :update_errored] => :scheduled
|
2017-11-07 04:07:22 -05:00
|
|
|
end
|
|
|
|
|
2017-11-02 06:14:10 -04:00
|
|
|
event :make_installing do
|
2017-11-07 07:58:36 -05:00
|
|
|
transition [:scheduled] => :installing
|
2017-11-02 06:14:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
event :make_installed do
|
2017-11-07 07:58:36 -05:00
|
|
|
transition [:installing] => :installed
|
2019-02-07 16:40:55 -05:00
|
|
|
transition [:updating] => :updated
|
2017-11-02 06:14:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
event :make_errored do
|
2019-02-07 16:40:55 -05:00
|
|
|
transition any - [:updating] => :errored
|
|
|
|
transition [:updating] => :update_errored
|
2017-11-03 06:10:50 -04:00
|
|
|
end
|
|
|
|
|
2018-09-26 23:52:30 -04:00
|
|
|
event :make_updating do
|
2019-02-07 16:40:55 -05:00
|
|
|
transition [:installed, :updated, :update_errored, :scheduled] => :updating
|
2018-09-26 23:52:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
event :make_update_errored do
|
|
|
|
transition any => :update_errored
|
|
|
|
end
|
|
|
|
|
2017-11-03 06:10:50 -04:00
|
|
|
before_transition any => [:scheduled] do |app_status, _|
|
|
|
|
app_status.status_reason = nil
|
|
|
|
end
|
|
|
|
|
2017-11-02 06:14:10 -04:00
|
|
|
before_transition any => [:errored] do |app_status, transition|
|
|
|
|
status_reason = transition.args.first
|
|
|
|
app_status.status_reason = status_reason if status_reason
|
|
|
|
end
|
2018-09-26 23:52:30 -04:00
|
|
|
|
|
|
|
before_transition any => [:updating] do |app_status, _|
|
|
|
|
app_status.status_reason = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
before_transition any => [:update_errored] do |app_status, transition|
|
|
|
|
status_reason = transition.args.first
|
|
|
|
app_status.status_reason = status_reason if status_reason
|
|
|
|
end
|
2018-11-14 07:38:08 -05:00
|
|
|
|
|
|
|
before_transition any => [:installed, :updated] do |app_status, _|
|
2018-11-15 09:13:32 -05:00
|
|
|
# When installing any application we are also performing an update
|
|
|
|
# of tiller (see Gitlab::Kubernetes::Helm::ClientCommand) so
|
|
|
|
# therefore we need to reflect that in the database.
|
2018-11-14 07:38:08 -05:00
|
|
|
app_status.cluster.application_helm.update!(version: Gitlab::Kubernetes::Helm::HELM_VERSION)
|
|
|
|
end
|
2017-11-02 06:14:10 -04:00
|
|
|
end
|
|
|
|
end
|
2018-10-15 05:03:15 -04:00
|
|
|
|
2019-02-07 16:40:55 -05:00
|
|
|
def updateable?
|
|
|
|
installed? || updated? || update_errored?
|
|
|
|
end
|
|
|
|
|
2018-10-15 05:03:15 -04:00
|
|
|
def available?
|
|
|
|
installed? || updated?
|
|
|
|
end
|
2019-01-17 23:38:28 -05:00
|
|
|
|
|
|
|
def update_in_progress?
|
|
|
|
updating?
|
|
|
|
end
|
2017-11-02 06:14:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|