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

278 lines
7.4 KiB
Ruby
Raw Normal View History

2018-03-17 18:26:18 +05:30
require 'rails_helper'
describe Gitlab::Kubernetes::Helm::InstallCommand do
2018-11-18 11:00:15 +05:30
let(:files) { { 'ca.pem': 'some file content' } }
let(:repository) { 'https://repository.example.com' }
2018-11-20 20:47:30 +05:30
let(:rbac) { false }
2018-11-18 11:00:15 +05:30
let(:version) { '1.2.3' }
2018-12-13 13:39:08 +05:30
let(:preinstall) { nil }
let(:postinstall) { nil }
2018-11-18 11:00:15 +05:30
let(:install_command) do
described_class.new(
name: 'app-name',
chart: 'chart-name',
2018-11-20 20:47:30 +05:30
rbac: rbac,
2018-11-18 11:00:15 +05:30
files: files,
2018-11-20 20:47:30 +05:30
version: version,
2018-12-13 13:39:08 +05:30
repository: repository,
preinstall: preinstall,
postinstall: postinstall
2018-11-18 11:00:15 +05:30
)
end
2018-03-17 18:26:18 +05:30
2018-10-15 14:42:47 +05:30
subject { install_command }
2018-03-17 18:26:18 +05:30
2018-11-18 11:00:15 +05:30
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
helm init --client-only >/dev/null
helm repo add app-name https://repository.example.com
2018-12-13 13:39:08 +05:30
helm repo update >/dev/null
2018-11-20 20:47:30 +05:30
#{helm_install_comand}
EOS
end
let(:helm_install_comand) do
<<~EOS.squish
helm install chart-name
--name app-name
--tls
--tls-ca-cert /data/helm/app-name/config/ca.pem
--tls-cert /data/helm/app-name/config/cert.pem
--tls-key /data/helm/app-name/config/key.pem
--version 1.2.3
--namespace gitlab-managed-apps
-f /data/helm/app-name/config/values.yaml >/dev/null
2018-11-18 11:00:15 +05:30
EOS
2018-11-08 19:23:39 +05:30
end
end
2018-11-20 20:47:30 +05:30
context 'when rbac is true' do
let(:rbac) { true }
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
helm init --client-only >/dev/null
helm repo add app-name https://repository.example.com
2018-12-13 13:39:08 +05:30
helm repo update >/dev/null
2018-11-20 20:47:30 +05:30
#{helm_install_command}
EOS
end
let(:helm_install_command) do
<<~EOS.squish
helm install chart-name
--name app-name
--tls
--tls-ca-cert /data/helm/app-name/config/ca.pem
--tls-cert /data/helm/app-name/config/cert.pem
--tls-key /data/helm/app-name/config/key.pem
--version 1.2.3
--set rbac.create\\=true,rbac.enabled\\=true
--namespace gitlab-managed-apps
-f /data/helm/app-name/config/values.yaml >/dev/null
EOS
end
end
end
2018-11-18 11:00:15 +05:30
context 'when there is no repository' do
let(:repository) { nil }
2018-11-08 19:23:39 +05:30
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
2018-11-20 20:47:30 +05:30
helm init --client-only >/dev/null
#{helm_install_command}
EOS
end
let(:helm_install_command) do
<<~EOS.squish
helm install chart-name
--name app-name
--tls
--tls-ca-cert /data/helm/app-name/config/ca.pem
--tls-cert /data/helm/app-name/config/cert.pem
--tls-key /data/helm/app-name/config/key.pem
--version 1.2.3
--namespace gitlab-managed-apps
-f /data/helm/app-name/config/values.yaml >/dev/null
2018-11-08 19:23:39 +05:30
EOS
end
2018-03-17 18:26:18 +05:30
end
2018-10-15 14:42:47 +05:30
end
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
context 'when there is a pre-install script' do
let(:preinstall) { ['/bin/date', '/bin/true'] }
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
helm init --client-only >/dev/null
helm repo add app-name https://repository.example.com
helm repo update >/dev/null
#{helm_install_command}
EOS
end
let(:helm_install_command) do
<<~EOS.strip
/bin/date
/bin/true
helm install chart-name --name app-name --tls --tls-ca-cert /data/helm/app-name/config/ca.pem --tls-cert /data/helm/app-name/config/cert.pem --tls-key /data/helm/app-name/config/key.pem --version 1.2.3 --namespace gitlab-managed-apps -f /data/helm/app-name/config/values.yaml >/dev/null
EOS
end
end
end
context 'when there is a post-install script' do
let(:postinstall) { ['/bin/date', "/bin/false\n"] }
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
helm init --client-only >/dev/null
helm repo add app-name https://repository.example.com
helm repo update >/dev/null
#{helm_install_command}
EOS
end
let(:helm_install_command) do
<<~EOS.strip
helm install chart-name --name app-name --tls --tls-ca-cert /data/helm/app-name/config/ca.pem --tls-cert /data/helm/app-name/config/cert.pem --tls-key /data/helm/app-name/config/key.pem --version 1.2.3 --namespace gitlab-managed-apps -f /data/helm/app-name/config/values.yaml >/dev/null
/bin/date
/bin/false
EOS
end
end
end
2018-11-18 11:00:15 +05:30
context 'when there is no ca.pem file' do
let(:files) { { 'file.txt': 'some content' } }
2018-11-08 19:23:39 +05:30
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
2018-11-20 20:47:30 +05:30
helm init --client-only >/dev/null
helm repo add app-name https://repository.example.com
2018-12-13 13:39:08 +05:30
helm repo update >/dev/null
2018-11-20 20:47:30 +05:30
#{helm_install_command}
EOS
end
let(:helm_install_command) do
<<~EOS.squish
helm install chart-name
--name app-name
--version 1.2.3
--namespace gitlab-managed-apps
-f /data/helm/app-name/config/values.yaml >/dev/null
2018-11-08 19:23:39 +05:30
EOS
end
2018-10-15 14:42:47 +05:30
end
2018-11-08 19:23:39 +05:30
end
2018-11-18 11:00:15 +05:30
context 'when there is no version' do
let(:version) { nil }
2018-03-17 18:26:18 +05:30
2018-10-15 14:42:47 +05:30
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
2018-11-20 20:47:30 +05:30
helm init --client-only >/dev/null
helm repo add app-name https://repository.example.com
2018-12-13 13:39:08 +05:30
helm repo update >/dev/null
2018-11-20 20:47:30 +05:30
#{helm_install_command}
EOS
end
let(:helm_install_command) do
<<~EOS.squish
helm install chart-name
--name app-name
--tls
--tls-ca-cert /data/helm/app-name/config/ca.pem
--tls-cert /data/helm/app-name/config/cert.pem
--tls-key /data/helm/app-name/config/key.pem
--namespace gitlab-managed-apps
-f /data/helm/app-name/config/values.yaml >/dev/null
2018-10-15 14:42:47 +05:30
EOS
2018-03-17 18:26:18 +05:30
end
end
2018-03-27 19:54:05 +05:30
end
2018-03-17 18:26:18 +05:30
2018-11-20 20:47:30 +05:30
describe '#rbac?' do
subject { install_command.rbac? }
context 'rbac is enabled' do
let(:rbac) { true }
it { is_expected.to be_truthy }
end
context 'rbac is not enabled' do
let(:rbac) { false }
it { is_expected.to be_falsey }
end
end
describe '#pod_resource' do
subject { install_command.pod_resource }
context 'rbac is enabled' do
let(:rbac) { true }
it 'generates a pod that uses the tiller serviceAccountName' do
expect(subject.spec.serviceAccountName).to eq('tiller')
end
end
context 'rbac is not enabled' do
let(:rbac) { false }
it 'generates a pod that uses the default serviceAccountName' do
expect(subject.spec.serviceAcccountName).to be_nil
end
end
end
2018-03-27 19:54:05 +05:30
describe '#config_map_resource' do
let(:metadata) do
{
2018-11-18 11:00:15 +05:30
name: "values-content-configuration-app-name",
namespace: 'gitlab-managed-apps',
labels: { name: "values-content-configuration-app-name" }
2018-03-27 19:54:05 +05:30
}
2018-03-17 18:26:18 +05:30
end
2018-11-18 11:00:15 +05:30
let(:resource) { ::Kubeclient::Resource.new(metadata: metadata, data: files) }
2018-03-17 18:26:18 +05:30
2018-03-27 19:54:05 +05:30
subject { install_command.config_map_resource }
2018-03-17 18:26:18 +05:30
2018-03-27 19:54:05 +05:30
it 'returns a KubeClient resource with config map content for the application' do
is_expected.to eq(resource)
2018-03-17 18:26:18 +05:30
end
end
2018-11-20 20:47:30 +05:30
describe '#service_account_resource' do
subject { install_command.service_account_resource }
it 'returns nothing' do
is_expected.to be_nil
end
end
describe '#cluster_role_binding_resource' do
subject { install_command.cluster_role_binding_resource }
it 'returns nothing' do
is_expected.to be_nil
end
end
2018-03-17 18:26:18 +05:30
end