2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
module Clusters
|
|
|
|
module Concerns
|
|
|
|
module ApplicationCore
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
belongs_to :cluster, class_name: 'Clusters::Cluster', foreign_key: :cluster_id
|
|
|
|
|
|
|
|
validates :cluster, presence: true
|
|
|
|
|
|
|
|
after_initialize :set_initial_status
|
|
|
|
|
|
|
|
def set_initial_status
|
|
|
|
return unless not_installable?
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
self.status = status_states[:installable] if cluster&.application_helm_available? || ::Gitlab::Kubernetes::Helm.local_tiller_enabled?
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
def can_uninstall?
|
|
|
|
allowed_to_uninstall?
|
|
|
|
end
|
|
|
|
|
|
|
|
# All new applications should uninstall by default
|
|
|
|
# Override if there's dependencies that needs to be uninstalled first
|
|
|
|
def allowed_to_uninstall?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def self.application_name
|
|
|
|
self.to_s.demodulize.underscore
|
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
def self.association_name
|
|
|
|
:"application_#{application_name}"
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def name
|
|
|
|
self.class.application_name
|
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
def schedule_status_update
|
|
|
|
# Override if you need extra data synchronized
|
|
|
|
# from K8s after installation
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
def update_command
|
|
|
|
install_command.tap do |command|
|
|
|
|
command.version = version
|
|
|
|
end
|
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
def prepare_uninstall
|
|
|
|
# Override if your application needs any action before
|
|
|
|
# being uninstalled by Helm
|
|
|
|
end
|
|
|
|
|
|
|
|
def post_uninstall
|
|
|
|
# Override if your application needs any action after
|
|
|
|
# being uninstalled by Helm
|
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
def logger
|
|
|
|
@logger ||= Gitlab::Kubernetes::Logger.build
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_exception(error, event)
|
|
|
|
logger.error({
|
|
|
|
exception: error.class.name,
|
|
|
|
status_code: error.error_code,
|
|
|
|
cluster_id: cluster&.id,
|
|
|
|
application_id: id,
|
|
|
|
class_name: self.class.name,
|
|
|
|
event: event,
|
|
|
|
message: error.message
|
|
|
|
})
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
Gitlab::ErrorTracking.track_exception(error, cluster_id: cluster&.id, application_id: id)
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
Clusters::Concerns::ApplicationCore.prepend_if_ee('EE::Clusters::Concerns::ApplicationCore')
|