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

82 lines
1.8 KiB
Ruby
Raw Normal View History

2018-03-27 19:54:05 +05:30
module Gitlab
module Kubernetes
module Helm
2018-11-18 11:00:15 +05:30
class InitCommand
include BaseCommand
attr_reader :name, :files
2018-11-20 20:47:30 +05:30
def initialize(name:, files:, rbac:)
2018-11-18 11:00:15 +05:30
@name = name
@files = files
2018-11-20 20:47:30 +05:30
@rbac = rbac
2018-11-18 11:00:15 +05:30
end
2018-03-27 19:54:05 +05:30
def generate_script
super + [
init_helm_command
].join("\n")
end
2018-11-20 20:47:30 +05:30
def rbac?
@rbac
end
def service_account_resource
return unless rbac?
Gitlab::Kubernetes::ServiceAccount.new(service_account_name, namespace).generate
end
def cluster_role_binding_resource
return unless rbac?
subjects = [{ kind: 'ServiceAccount', name: service_account_name, namespace: namespace }]
Gitlab::Kubernetes::ClusterRoleBinding.new(
cluster_role_binding_name,
cluster_role_name,
subjects
).generate
end
2018-03-27 19:54:05 +05:30
private
def init_helm_command
2018-11-20 20:47:30 +05:30
command = %w[helm init] + init_command_flags
2019-01-03 12:48:30 +05:30
command.shelljoin + " >/dev/null\n"
2018-11-20 20:47:30 +05:30
end
def init_command_flags
tls_flags + optional_service_account_flag
end
def tls_flags
[
'--tiller-tls',
'--tiller-tls-verify',
'--tls-ca-cert', "#{files_dir}/ca.pem",
'--tiller-tls-cert', "#{files_dir}/cert.pem",
'--tiller-tls-key', "#{files_dir}/key.pem"
]
end
def optional_service_account_flag
return [] unless rbac?
['--service-account', service_account_name]
end
def cluster_role_binding_name
Gitlab::Kubernetes::Helm::CLUSTER_ROLE_BINDING
end
2018-11-18 11:00:15 +05:30
2018-11-20 20:47:30 +05:30
def cluster_role_name
Gitlab::Kubernetes::Helm::CLUSTER_ROLE
2018-03-27 19:54:05 +05:30
end
end
end
end
end