debian-mirror-gitlab/app/models/clusters/applications/helm.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

84 lines
2.2 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
require 'openssl'
2018-03-17 18:26:18 +05:30
module Clusters
module Applications
2021-02-22 17:27:13 +05:30
# DEPRECATED: This model represents the Helm 2 Tiller server.
# It is being kept around to enable the cleanup of the unused Tiller server.
2019-07-07 11:18:12 +05:30
class Helm < ApplicationRecord
2018-03-17 18:26:18 +05:30
self.table_name = 'clusters_applications_helm'
2018-11-18 11:00:15 +05:30
attr_encrypted :ca_key,
mode: :per_attribute_iv,
key: Settings.attr_encrypted_db_key_base_truncated,
algorithm: 'aes-256-cbc'
2018-03-17 18:26:18 +05:30
include ::Clusters::Concerns::ApplicationCore
include ::Clusters::Concerns::ApplicationStatus
2019-10-12 21:52:04 +05:30
include ::Gitlab::Utils::StrongMemoize
2018-03-17 18:26:18 +05:30
2023-01-13 00:05:48 +05:30
attribute :version, default: Gitlab::Kubernetes::Helm::V2::BaseCommand::HELM_VERSION
2018-03-17 18:26:18 +05:30
2018-11-18 11:00:15 +05:30
before_create :create_keys_and_certs
def issue_client_cert
ca_cert_obj.issue
end
2018-03-17 18:26:18 +05:30
def set_initial_status
2021-02-22 17:27:13 +05:30
# The legacy Tiller server is not installable, which is the initial status of every app
2019-07-31 22:56:46 +05:30
end
2021-02-22 17:27:13 +05:30
# DEPRECATED: This command is only for development and testing purposes, to simulate
# a Helm 2 cluster with an existing Tiller server.
2018-03-17 18:26:18 +05:30
def install_command
2021-01-29 00:20:46 +05:30
Gitlab::Kubernetes::Helm::V2::InitCommand.new(
2018-11-18 11:00:15 +05:30
name: name,
2018-11-20 20:47:30 +05:30
files: files,
2020-10-24 23:57:45 +05:30
rbac: cluster.platform_kubernetes_rbac?
2018-11-18 11:00:15 +05:30
)
end
2019-10-12 21:52:04 +05:30
def uninstall_command
2021-01-29 00:20:46 +05:30
Gitlab::Kubernetes::Helm::V2::ResetCommand.new(
2019-10-12 21:52:04 +05:30
name: name,
files: files,
2020-10-24 23:57:45 +05:30
rbac: cluster.platform_kubernetes_rbac?
2019-10-12 21:52:04 +05:30
)
end
2018-11-18 11:00:15 +05:30
def has_ssl?
ca_key.present? && ca_cert.present?
end
private
def files
{
'ca.pem': ca_cert,
'cert.pem': tiller_cert.cert_string,
'key.pem': tiller_cert.key_string
}
end
def create_keys_and_certs
2021-01-29 00:20:46 +05:30
ca_cert = Gitlab::Kubernetes::Helm::V2::Certificate.generate_root
2018-11-18 11:00:15 +05:30
self.ca_key = ca_cert.key_string
self.ca_cert = ca_cert.cert_string
end
def tiller_cert
2021-01-29 00:20:46 +05:30
@tiller_cert ||= ca_cert_obj.issue(expires_in: Gitlab::Kubernetes::Helm::V2::Certificate::INFINITE_EXPIRY)
2018-11-18 11:00:15 +05:30
end
def ca_cert_obj
return unless has_ssl?
2021-01-29 00:20:46 +05:30
Gitlab::Kubernetes::Helm::V2::Certificate
2018-11-18 11:00:15 +05:30
.from_strings(ca_key, ca_cert)
2018-03-17 18:26:18 +05:30
end
end
end
end