2018-07-24 07:02:35 -04:00
|
|
|
require 'openssl'
|
|
|
|
|
2017-11-02 06:14:10 -04:00
|
|
|
module Clusters
|
2017-11-02 10:10:46 -04:00
|
|
|
module Applications
|
|
|
|
class Helm < ActiveRecord::Base
|
|
|
|
self.table_name = 'clusters_applications_helm'
|
|
|
|
|
2018-07-24 07:02:35 -04:00
|
|
|
attr_encrypted :ca_key,
|
|
|
|
mode: :per_attribute_iv,
|
|
|
|
key: Settings.attr_encrypted_db_key_base_truncated,
|
|
|
|
algorithm: 'aes-256-cbc'
|
|
|
|
|
2017-12-22 12:23:43 -05:00
|
|
|
include ::Clusters::Concerns::ApplicationCore
|
2017-11-02 12:57:50 -04:00
|
|
|
include ::Clusters::Concerns::ApplicationStatus
|
2017-11-02 06:14:10 -04:00
|
|
|
|
2017-11-02 11:57:18 -04:00
|
|
|
default_value_for :version, Gitlab::Kubernetes::Helm::HELM_VERSION
|
2017-11-02 06:14:10 -04:00
|
|
|
|
2018-07-24 07:02:35 -04:00
|
|
|
before_create :create_keys_and_certs
|
|
|
|
|
|
|
|
def create_keys_and_certs
|
|
|
|
ca_cert = Gitlab::Kubernetes::Helm::Certificate.generate_root
|
|
|
|
self.ca_key = ca_cert.key_string
|
|
|
|
self.ca_cert = ca_cert.cert_string
|
|
|
|
end
|
|
|
|
|
|
|
|
def ca_cert_obj
|
|
|
|
return unless has_ssl?
|
|
|
|
|
|
|
|
Gitlab::Kubernetes::Helm::Certificate
|
|
|
|
.from_strings(ca_key, ca_cert)
|
|
|
|
end
|
|
|
|
|
|
|
|
def issue_cert
|
2018-07-24 11:34:39 -04:00
|
|
|
ca_cert_obj.issue
|
2018-07-24 07:02:35 -04:00
|
|
|
end
|
|
|
|
|
2017-11-07 08:26:14 -05:00
|
|
|
def set_initial_status
|
2017-11-07 08:52:11 -05:00
|
|
|
return unless not_installable?
|
|
|
|
|
2017-11-07 08:26:14 -05:00
|
|
|
self.status = 'installable' if cluster&.platform_kubernetes_active?
|
2017-11-06 09:48:44 -05:00
|
|
|
end
|
|
|
|
|
2017-11-07 09:26:14 -05:00
|
|
|
def install_command
|
2018-07-24 11:34:39 -04:00
|
|
|
tiller_cert = ca_cert_obj.issue(expires_in: Gitlab::Kubernetes::Helm::Certificate::INFINITE_EXPIRY)
|
|
|
|
|
2018-07-23 10:35:19 -04:00
|
|
|
Gitlab::Kubernetes::Helm::InitCommand.new(
|
|
|
|
name: name,
|
2018-07-24 07:02:35 -04:00
|
|
|
files: {
|
|
|
|
'ca.pem': ca_cert,
|
|
|
|
'cert.pem': tiller_cert.cert_string,
|
|
|
|
'key.pem': tiller_cert.key_string
|
|
|
|
}
|
2018-07-23 10:35:19 -04:00
|
|
|
)
|
2017-11-07 09:26:14 -05:00
|
|
|
end
|
2018-07-24 07:02:35 -04:00
|
|
|
|
|
|
|
def has_ssl?
|
|
|
|
ca_key.present? && ca_cert.present?
|
|
|
|
end
|
2017-11-02 06:14:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|