Class: Clusters::Applications::Helm

Inherits:
ApplicationRecord show all
Includes:
Concerns::ApplicationCore, Concerns::ApplicationStatus, Gitlab::Utils::StrongMemoize
Defined in:
app/models/clusters/applications/helm.rb

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods included from Concerns::ApplicationStatus

#available?, #status_states, #update_in_progress?, #updateable?

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Instance Method Details

#allowed_to_uninstall?Boolean

It can only be uninstalled if there are no other applications installed or with intermitent installation statuses in the database.

Returns:

  • (Boolean)

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/clusters/applications/helm.rb', line 35

def allowed_to_uninstall?
  strong_memoize(:allowed_to_uninstall) do
    applications = nil

    Clusters::Cluster::APPLICATIONS.each do |application_name, klass|
      next if application_name == 'helm'

      extra_apps = Clusters::Applications::Helm.where('EXISTS (?)', klass.select(1).where(cluster_id: cluster_id))

      applications = applications ? applications.or(extra_apps) : extra_apps
    end

    !applications.exists?
  end
end

#has_ssl?Boolean

Returns:

  • (Boolean)

67
68
69
# File 'app/models/clusters/applications/helm.rb', line 67

def has_ssl?
  ca_key.present? && ca_cert.present?
end

#install_commandObject


51
52
53
54
55
56
57
# File 'app/models/clusters/applications/helm.rb', line 51

def install_command
  Gitlab::Kubernetes::Helm::InitCommand.new(
    name: name,
    files: files,
    rbac: cluster.platform_kubernetes_rbac?
  )
end

#issue_client_certObject


23
24
25
# File 'app/models/clusters/applications/helm.rb', line 23

def issue_client_cert
  ca_cert_obj.issue
end

#post_uninstallObject


71
72
73
74
75
76
# File 'app/models/clusters/applications/helm.rb', line 71

def post_uninstall
  cluster.kubeclient.delete_namespace(Gitlab::Kubernetes::Helm::NAMESPACE)
rescue Kubeclient::ResourceNotFoundError
  # we actually don't care if the namespace is not present
  # since we want to delete it anyway.
end

#set_initial_statusObject


27
28
29
30
31
# File 'app/models/clusters/applications/helm.rb', line 27

def set_initial_status
  return unless not_installable?

  self.status = status_states[:installable] if cluster&.platform_kubernetes_active?
end

#uninstall_commandObject


59
60
61
62
63
64
65
# File 'app/models/clusters/applications/helm.rb', line 59

def uninstall_command
  Gitlab::Kubernetes::Helm::ResetCommand.new(
    name: name,
    files: files,
    rbac: cluster.platform_kubernetes_rbac?
  )
end