2019-02-13 22:33:31 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
module Gitlab
|
|
|
|
module Kubernetes
|
|
|
|
module Helm
|
|
|
|
class Pod
|
2018-11-20 20:47:30 +05:30
|
|
|
def initialize(command, namespace_name, service_account_name: nil)
|
2018-03-17 18:26:18 +05:30
|
|
|
@command = command
|
|
|
|
@namespace_name = namespace_name
|
2018-11-20 20:47:30 +05:30
|
|
|
@service_account_name = service_account_name
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def generate
|
|
|
|
spec = { containers: [container_specification], restartPolicy: 'Never' }
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
spec[:volumes] = volumes_specification
|
|
|
|
spec[:containers][0][:volumeMounts] = volume_mounts_specification
|
2018-11-20 20:47:30 +05:30
|
|
|
spec[:serviceAccountName] = service_account_name if service_account_name
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
::Kubeclient::Resource.new(metadata: metadata, spec: spec)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
attr_reader :command, :namespace_name, :service_account_name
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def container_specification
|
2018-03-27 19:54:05 +05:30
|
|
|
{
|
2018-03-17 18:26:18 +05:30
|
|
|
name: 'helm',
|
2018-12-13 13:39:08 +05:30
|
|
|
image: "registry.gitlab.com/gitlab-org/cluster-integration/helm-install-image/releases/#{Gitlab::Kubernetes::Helm::HELM_VERSION}-kube-#{Gitlab::Kubernetes::Helm::KUBECTL_VERSION}",
|
2018-03-17 18:26:18 +05:30
|
|
|
env: generate_pod_env(command),
|
|
|
|
command: %w(/bin/sh),
|
|
|
|
args: %w(-c $(COMMAND_SCRIPT))
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def labels
|
|
|
|
{
|
|
|
|
'gitlab.org/action': 'install',
|
|
|
|
'gitlab.org/application': command.name
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def metadata
|
|
|
|
{
|
|
|
|
name: command.pod_name,
|
|
|
|
namespace: namespace_name,
|
|
|
|
labels: labels
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
def generate_pod_env(command)
|
|
|
|
{
|
|
|
|
HELM_VERSION: Gitlab::Kubernetes::Helm::HELM_VERSION,
|
|
|
|
TILLER_NAMESPACE: namespace_name,
|
|
|
|
COMMAND_SCRIPT: command.generate_script
|
|
|
|
}.map { |key, value| { name: key, value: value } }
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def volumes_specification
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: 'configuration-volume',
|
|
|
|
configMap: {
|
|
|
|
name: "values-content-configuration-#{command.name}",
|
2018-11-18 11:00:15 +05:30
|
|
|
items: command.file_names.map { |name| { key: name, path: name } }
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
def volume_mounts_specification
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: 'configuration-volume',
|
|
|
|
mountPath: "/data/helm/#{command.name}/config"
|
|
|
|
}
|
|
|
|
]
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|