2018-12-23 12:14:25 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
module Gitlab
|
|
|
|
module Kubernetes
|
|
|
|
module Helm
|
2018-11-18 11:00:15 +05:30
|
|
|
class InstallCommand
|
|
|
|
include BaseCommand
|
2018-12-23 12:14:25 +05:30
|
|
|
include ClientCommand
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
attr_reader :name, :files, :chart, :version, :repository, :preinstall, :postinstall
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
def initialize(name:, chart:, files:, rbac:, version: nil, repository: nil, preinstall: nil, postinstall: nil)
|
2018-03-17 18:26:18 +05:30
|
|
|
@name = name
|
|
|
|
@chart = chart
|
2018-11-08 19:23:39 +05:30
|
|
|
@version = version
|
2018-11-20 20:47:30 +05:30
|
|
|
@rbac = rbac
|
2018-11-18 11:00:15 +05:30
|
|
|
@files = files
|
2018-03-27 19:54:05 +05:30
|
|
|
@repository = repository
|
2018-12-13 13:39:08 +05:30
|
|
|
@preinstall = preinstall
|
|
|
|
@postinstall = postinstall
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
def generate_script
|
|
|
|
super + [
|
|
|
|
init_command,
|
2018-12-23 12:14:25 +05:30
|
|
|
wait_for_tiller_command,
|
2018-03-27 19:54:05 +05:30
|
|
|
repository_command,
|
2018-12-13 13:39:08 +05:30
|
|
|
repository_update_command,
|
|
|
|
preinstall_command,
|
|
|
|
install_command,
|
|
|
|
postinstall_command
|
2018-03-27 19:54:05 +05:30
|
|
|
].compact.join("\n")
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
def rbac?
|
|
|
|
@rbac
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
private
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
def repository_update_command
|
2018-12-23 12:14:25 +05:30
|
|
|
'helm repo update' if repository
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def install_command
|
2018-11-20 20:47:30 +05:30
|
|
|
command = ['helm', 'install', chart] + install_command_flags
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
command.shelljoin
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
def preinstall_command
|
|
|
|
preinstall.join("\n") if preinstall
|
|
|
|
end
|
|
|
|
|
|
|
|
def postinstall_command
|
|
|
|
postinstall.join("\n") if postinstall
|
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
def install_command_flags
|
|
|
|
name_flag = ['--name', name]
|
|
|
|
namespace_flag = ['--namespace', Gitlab::Kubernetes::Helm::NAMESPACE]
|
|
|
|
value_flag = ['-f', "/data/helm/#{name}/config/values.yaml"]
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
name_flag +
|
|
|
|
optional_tls_flags +
|
|
|
|
optional_version_flag +
|
2018-12-23 12:14:25 +05:30
|
|
|
rbac_create_flag +
|
2018-11-20 20:47:30 +05:30
|
|
|
namespace_flag +
|
|
|
|
value_flag
|
|
|
|
end
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
def rbac_create_flag
|
|
|
|
if rbac?
|
|
|
|
%w[--set rbac.create=true,rbac.enabled=true]
|
|
|
|
else
|
|
|
|
%w[--set rbac.create=false,rbac.enabled=false]
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
def optional_version_flag
|
2018-11-20 20:47:30 +05:30
|
|
|
return [] unless version
|
|
|
|
|
|
|
|
['--version', version]
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
def optional_tls_flags
|
2018-11-20 20:47:30 +05:30
|
|
|
return [] unless files.key?(:'ca.pem')
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
[
|
|
|
|
'--tls',
|
|
|
|
'--tls-ca-cert', "#{files_dir}/ca.pem",
|
|
|
|
'--tls-cert', "#{files_dir}/cert.pem",
|
|
|
|
'--tls-key', "#{files_dir}/key.pem"
|
|
|
|
]
|
2018-11-18 11:00:15 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|