2019-02-15 15:39:39 +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
|
2019-02-15 15:39:39 +05:30
|
|
|
include ClientCommand
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
attr_reader :name, :files, :chart, :repository, :preinstall, :postinstall
|
|
|
|
attr_accessor :version
|
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,
|
2019-02-15 15:39:39 +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,
|
2019-10-12 21:52:04 +05:30
|
|
|
preinstall,
|
2018-12-13 13:39:08 +05:30
|
|
|
install_command,
|
2019-10-12 21:52:04 +05:30
|
|
|
postinstall
|
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-03-02 22:35:43 +05:30
|
|
|
# Uses `helm upgrade --install` which means we can use this for both
|
|
|
|
# installation and uprade of applications
|
2018-12-13 13:39:08 +05:30
|
|
|
def install_command
|
2019-03-02 22:35:43 +05:30
|
|
|
command = ['helm', 'upgrade', name, chart] +
|
|
|
|
install_flag +
|
|
|
|
reset_values_flag +
|
2020-01-01 13:55:28 +05:30
|
|
|
tls_flags_if_remote_tiller +
|
2019-03-02 22:35:43 +05:30
|
|
|
optional_version_flag +
|
|
|
|
rbac_create_flag +
|
|
|
|
namespace_flag +
|
|
|
|
value_flag
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
command.shelljoin
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
def install_flag
|
|
|
|
['--install']
|
|
|
|
end
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
def reset_values_flag
|
|
|
|
['--reset-values']
|
|
|
|
end
|
|
|
|
|
|
|
|
def value_flag
|
|
|
|
['-f', "/data/helm/#{name}/config/values.yaml"]
|
|
|
|
end
|
|
|
|
|
|
|
|
def namespace_flag
|
|
|
|
['--namespace', Gitlab::Kubernetes::Helm::NAMESPACE]
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +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-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|