debian-mirror-gitlab/spec/lib/gitlab/kubernetes/helm/pod_spec.rb

79 lines
3.1 KiB
Ruby
Raw Normal View History

2018-03-17 18:26:18 +05:30
require 'rails_helper'
describe Gitlab::Kubernetes::Helm::Pod do
describe '#generate' do
2019-03-02 22:35:43 +05:30
let(:app) { create(:clusters_applications_prometheus) }
let(:command) { app.install_command }
2018-03-27 19:54:05 +05:30
let(:namespace) { Gitlab::Kubernetes::Helm::NAMESPACE }
2018-11-20 20:47:30 +05:30
let(:service_account_name) { nil }
2018-03-17 18:26:18 +05:30
2018-11-20 20:47:30 +05:30
subject { described_class.new(command, namespace, service_account_name: service_account_name) }
2018-03-17 18:26:18 +05:30
2018-11-18 11:00:15 +05:30
context 'with a command' do
2018-03-17 18:26:18 +05:30
it 'should generate a Kubeclient::Resource' do
expect(subject.generate).to be_a_kind_of(Kubeclient::Resource)
end
it 'should generate the appropriate metadata' do
metadata = subject.generate.metadata
expect(metadata.name).to eq("install-#{app.name}")
expect(metadata.namespace).to eq('gitlab-managed-apps')
expect(metadata.labels['gitlab.org/action']).to eq('install')
expect(metadata.labels['gitlab.org/application']).to eq(app.name)
end
it 'should generate a container spec' do
spec = subject.generate.spec
expect(spec.containers.count).to eq(1)
end
it 'should generate the appropriate specifications for the container' do
container = subject.generate.spec.containers.first
expect(container.name).to eq('helm')
2019-03-02 22:35:43 +05:30
expect(container.image).to eq('registry.gitlab.com/gitlab-org/cluster-integration/helm-install-image/releases/2.12.2-kube-1.11.0')
2018-03-17 18:26:18 +05:30
expect(container.env.count).to eq(3)
expect(container.env.map(&:name)).to match_array([:HELM_VERSION, :TILLER_NAMESPACE, :COMMAND_SCRIPT])
expect(container.command).to match_array(["/bin/sh"])
expect(container.args).to match_array(["-c", "$(COMMAND_SCRIPT)"])
end
it 'should include a never restart policy' do
spec = subject.generate.spec
expect(spec.restartPolicy).to eq('Never')
end
it 'should include volumes for the container' do
container = subject.generate.spec.containers.first
expect(container.volumeMounts.first['name']).to eq('configuration-volume')
expect(container.volumeMounts.first['mountPath']).to eq("/data/helm/#{app.name}/config")
end
it 'should include a volume inside the specification' do
spec = subject.generate.spec
expect(spec.volumes.first['name']).to eq('configuration-volume')
end
it 'should mount configMap specification in the volume' do
2018-03-27 19:54:05 +05:30
volume = subject.generate.spec.volumes.first
expect(volume.configMap['name']).to eq("values-content-configuration-#{app.name}")
2018-11-18 11:00:15 +05:30
expect(volume.configMap['items'].first['key']).to eq(:'values.yaml')
expect(volume.configMap['items'].first['path']).to eq(:'values.yaml')
2018-03-17 18:26:18 +05:30
end
2018-11-20 20:47:30 +05:30
it 'should have no serviceAccountName' do
spec = subject.generate.spec
expect(spec.serviceAccountName).to be_nil
end
context 'with a service_account_name' do
let(:service_account_name) { 'sa' }
it 'should use the serviceAccountName provided' do
spec = subject.generate.spec
expect(spec.serviceAccountName).to eq(service_account_name)
end
end
2018-03-17 18:26:18 +05:30
end
end
end