debian-mirror-gitlab/lib/gitlab/kubernetes/helm/install_command.rb

104 lines
2.6 KiB
Ruby
Raw Normal View History

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-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,
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
2019-01-03 12:48:30 +05:30
def init_command
'helm init --client-only >/dev/null'
end
def repository_command
['helm', 'repo', 'add', name, repository].shelljoin if repository
end
2018-12-13 13:39:08 +05:30
def repository_update_command
2019-01-03 12:48:30 +05:30
'helm repo update >/dev/null' 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
2019-01-03 12:48:30 +05:30
command.shelljoin + " >/dev/null\n"
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 +
2019-01-03 12:48:30 +05:30
optional_rbac_create_flag +
2018-11-20 20:47:30 +05:30
namespace_flag +
value_flag
end
2019-01-03 12:48:30 +05:30
def optional_rbac_create_flag
return [] unless rbac?
# jupyterhub helm chart is using rbac.enabled
# https://github.com/jupyterhub/zero-to-jupyterhub-k8s/tree/master/jupyterhub
%w[--set rbac.create=true,rbac.enabled=true]
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