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

86 lines
1.9 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2018-03-27 19:54:05 +05:30
module Gitlab
module Kubernetes
module Helm
2020-06-23 00:09:42 +05:30
class BaseCommand
attr_reader :name, :files
2020-10-24 23:57:45 +05:30
def initialize(rbac:, name:, files:)
2020-06-23 00:09:42 +05:30
@rbac = rbac
@name = name
@files = files
end
def rbac?
@rbac
end
2018-03-27 19:54:05 +05:30
def pod_resource
2018-11-20 20:47:30 +05:30
pod_service_account_name = rbac? ? service_account_name : nil
Gitlab::Kubernetes::Helm::Pod.new(self, namespace, service_account_name: pod_service_account_name).generate
2018-03-27 19:54:05 +05:30
end
def generate_script
<<~HEREDOC
2019-02-15 15:39:39 +05:30
set -xeo pipefail
2018-03-27 19:54:05 +05:30
HEREDOC
end
def pod_name
"install-#{name}"
end
2018-11-18 11:00:15 +05:30
def config_map_resource
Gitlab::Kubernetes::ConfigMap.new(name, files).generate
end
2018-11-20 20:47:30 +05:30
def service_account_resource
2020-04-22 19:07:51 +05:30
return unless rbac?
Gitlab::Kubernetes::ServiceAccount.new(service_account_name, namespace).generate
2018-11-20 20:47:30 +05:30
end
def cluster_role_binding_resource
2020-04-22 19:07:51 +05:30
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
2018-11-20 20:47:30 +05:30
end
2018-11-18 11:00:15 +05:30
def file_names
files.keys
end
2018-03-27 19:54:05 +05:30
private
2018-11-18 11:00:15 +05:30
def files_dir
"/data/helm/#{name}/config"
end
2018-03-27 19:54:05 +05:30
def namespace
Gitlab::Kubernetes::Helm::NAMESPACE
end
2018-11-20 20:47:30 +05:30
def service_account_name
Gitlab::Kubernetes::Helm::SERVICE_ACCOUNT
end
2020-04-22 19:07:51 +05:30
def cluster_role_binding_name
Gitlab::Kubernetes::Helm::CLUSTER_ROLE_BINDING
end
def cluster_role_name
Gitlab::Kubernetes::Helm::CLUSTER_ROLE
end
2018-03-27 19:54:05 +05:30
end
end
end
end