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

257 lines
6.7 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2018-03-17 18:26:18 +05:30
describe Gitlab::Kubernetes::Helm::InstallCommand do
2020-05-24 23:13:21 +05:30
subject(:install_command) do
2018-11-18 11:00:15 +05:30
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,
2020-06-23 00:09:42 +05:30
postinstall: postinstall,
local_tiller_enabled: local_tiller_enabled
2018-11-18 11:00:15 +05:30
)
end
2018-03-17 18:26:18 +05:30
2020-05-24 23:13:21 +05:30
let(:files) { { 'ca.pem': 'some file content' } }
let(:repository) { 'https://repository.example.com' }
let(:rbac) { false }
let(:version) { '1.2.3' }
let(:preinstall) { nil }
let(:postinstall) { nil }
2020-06-23 00:09:42 +05:30
let(:local_tiller_enabled) { true }
2018-03-17 18:26:18 +05:30
2020-05-24 23:13:21 +05:30
it_behaves_like 'helm command generator' do
2018-11-18 11:00:15 +05:30
let(:commands) do
<<~EOS
2020-01-01 13:55:28 +05:30
export HELM_HOST="localhost:44134"
tiller -listen ${HELM_HOST} -alsologtostderr &
helm init --client-only
2018-11-18 11:00:15 +05:30
helm repo add app-name https://repository.example.com
2019-02-15 15:39:39 +05:30
helm repo update
2018-11-20 20:47:30 +05:30
#{helm_install_comand}
EOS
end
let(:helm_install_comand) do
<<~EOS.squish
2019-03-02 22:35:43 +05:30
helm upgrade app-name chart-name
--install
2020-04-22 19:07:51 +05:30
--atomic
--cleanup-on-fail
2019-03-02 22:35:43 +05:30
--reset-values
2018-11-20 20:47:30 +05:30
--version 1.2.3
2019-02-15 15:39:39 +05:30
--set rbac.create\\=false,rbac.enabled\\=false
2018-11-20 20:47:30 +05:30
--namespace gitlab-managed-apps
2019-02-15 15:39:39 +05:30
-f /data/helm/app-name/config/values.yaml
2018-11-18 11:00:15 +05:30
EOS
2018-11-08 19:23:39 +05:30
end
end
2020-01-01 13:55:28 +05:30
context 'tillerless feature disabled' do
2020-06-23 00:09:42 +05:30
let(:local_tiller_enabled) { false }
2020-01-01 13:55:28 +05:30
let(:tls_flags) do
<<~EOS.squish
--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
EOS
end
2018-11-20 20:47:30 +05:30
2020-05-24 23:13:21 +05:30
it_behaves_like 'helm command generator' do
2018-11-20 20:47:30 +05:30
let(:commands) do
<<~EOS
2019-02-15 15:39:39 +05:30
helm init --upgrade
2019-12-21 20:55:43 +05:30
for i in $(seq 1 30); do helm version #{tls_flags} && s=0 && break || s=$?; sleep 1s; echo \"Retrying ($i)...\"; done; (exit $s)
2018-11-20 20:47:30 +05:30
helm repo add app-name https://repository.example.com
2019-02-15 15:39:39 +05:30
helm repo update
2020-01-01 13:55:28 +05:30
#{helm_install_comand}
EOS
end
let(:helm_install_comand) do
<<~EOS.squish
helm upgrade app-name chart-name
--install
2020-04-22 19:07:51 +05:30
--atomic
--cleanup-on-fail
2020-01-01 13:55:28 +05:30
--reset-values
#{tls_flags}
--version 1.2.3
--set rbac.create\\=false,rbac.enabled\\=false
--namespace gitlab-managed-apps
-f /data/helm/app-name/config/values.yaml
EOS
end
end
end
context 'when rbac is true' do
let(:rbac) { true }
2020-05-24 23:13:21 +05:30
it_behaves_like 'helm command generator' do
2020-01-01 13:55:28 +05:30
let(:commands) do
<<~EOS
export HELM_HOST="localhost:44134"
tiller -listen ${HELM_HOST} -alsologtostderr &
helm init --client-only
helm repo add app-name https://repository.example.com
helm repo update
2018-11-20 20:47:30 +05:30
#{helm_install_command}
EOS
end
let(:helm_install_command) do
<<~EOS.squish
2019-03-02 22:35:43 +05:30
helm upgrade app-name chart-name
--install
2020-04-22 19:07:51 +05:30
--atomic
--cleanup-on-fail
2019-03-02 22:35:43 +05:30
--reset-values
2018-11-20 20:47:30 +05:30
--version 1.2.3
--set rbac.create\\=true,rbac.enabled\\=true
--namespace gitlab-managed-apps
2019-02-15 15:39:39 +05:30
-f /data/helm/app-name/config/values.yaml
2018-11-20 20:47:30 +05:30
EOS
end
end
end
2018-12-13 13:39:08 +05:30
context 'when there is a pre-install script' do
let(:preinstall) { ['/bin/date', '/bin/true'] }
2020-05-24 23:13:21 +05:30
it_behaves_like 'helm command generator' do
2018-12-13 13:39:08 +05:30
let(:commands) do
<<~EOS
2020-01-01 13:55:28 +05:30
export HELM_HOST="localhost:44134"
tiller -listen ${HELM_HOST} -alsologtostderr &
helm init --client-only
2018-12-13 13:39:08 +05:30
helm repo add app-name https://repository.example.com
2019-02-15 15:39:39 +05:30
helm repo update
2019-03-02 22:35:43 +05:30
/bin/date
/bin/true
2018-12-13 13:39:08 +05:30
#{helm_install_command}
EOS
end
let(:helm_install_command) do
2019-03-02 22:35:43 +05:30
<<~EOS.squish
helm upgrade app-name chart-name
--install
2020-04-22 19:07:51 +05:30
--atomic
--cleanup-on-fail
2019-03-02 22:35:43 +05:30
--reset-values
--version 1.2.3
--set rbac.create\\=false,rbac.enabled\\=false
--namespace gitlab-managed-apps
-f /data/helm/app-name/config/values.yaml
2018-12-13 13:39:08 +05:30
EOS
end
end
end
context 'when there is a post-install script' do
let(:postinstall) { ['/bin/date', "/bin/false\n"] }
2020-05-24 23:13:21 +05:30
it_behaves_like 'helm command generator' do
2018-12-13 13:39:08 +05:30
let(:commands) do
<<~EOS
2020-01-01 13:55:28 +05:30
export HELM_HOST="localhost:44134"
tiller -listen ${HELM_HOST} -alsologtostderr &
helm init --client-only
2018-12-13 13:39:08 +05:30
helm repo add app-name https://repository.example.com
2019-02-15 15:39:39 +05:30
helm repo update
2018-12-13 13:39:08 +05:30
#{helm_install_command}
2019-03-02 22:35:43 +05:30
/bin/date
/bin/false
2018-12-13 13:39:08 +05:30
EOS
end
let(:helm_install_command) do
2019-03-02 22:35:43 +05:30
<<~EOS.squish
helm upgrade app-name chart-name
--install
2020-04-22 19:07:51 +05:30
--atomic
--cleanup-on-fail
2019-03-02 22:35:43 +05:30
--reset-values
--version 1.2.3
--set rbac.create\\=false,rbac.enabled\\=false
--namespace gitlab-managed-apps
-f /data/helm/app-name/config/values.yaml
2018-12-13 13:39:08 +05:30
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
2020-05-24 23:13:21 +05:30
it_behaves_like 'helm command generator' do
2018-11-08 19:23:39 +05:30
let(:commands) do
<<~EOS
2020-01-01 13:55:28 +05:30
export HELM_HOST="localhost:44134"
tiller -listen ${HELM_HOST} -alsologtostderr &
helm init --client-only
2018-11-20 20:47:30 +05:30
helm repo add app-name https://repository.example.com
2019-02-15 15:39:39 +05:30
helm repo update
2018-11-20 20:47:30 +05:30
#{helm_install_command}
EOS
end
let(:helm_install_command) do
<<~EOS.squish
2019-03-02 22:35:43 +05:30
helm upgrade app-name chart-name
--install
2020-04-22 19:07:51 +05:30
--atomic
--cleanup-on-fail
2019-03-02 22:35:43 +05:30
--reset-values
2018-11-20 20:47:30 +05:30
--version 1.2.3
2019-02-15 15:39:39 +05:30
--set rbac.create\\=false,rbac.enabled\\=false
2018-11-20 20:47:30 +05:30
--namespace gitlab-managed-apps
2019-02-15 15:39:39 +05:30
-f /data/helm/app-name/config/values.yaml
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
2020-05-24 23:13:21 +05:30
it_behaves_like 'helm command generator' do
2018-10-15 14:42:47 +05:30
let(:commands) do
<<~EOS
2020-01-01 13:55:28 +05:30
export HELM_HOST="localhost:44134"
tiller -listen ${HELM_HOST} -alsologtostderr &
helm init --client-only
2018-11-20 20:47:30 +05:30
helm repo add app-name https://repository.example.com
2019-02-15 15:39:39 +05:30
helm repo update
2018-11-20 20:47:30 +05:30
#{helm_install_command}
EOS
end
let(:helm_install_command) do
<<~EOS.squish
2019-03-02 22:35:43 +05:30
helm upgrade app-name chart-name
--install
2020-04-22 19:07:51 +05:30
--atomic
--cleanup-on-fail
2019-03-02 22:35:43 +05:30
--reset-values
2019-02-15 15:39:39 +05:30
--set rbac.create\\=false,rbac.enabled\\=false
2018-11-20 20:47:30 +05:30
--namespace gitlab-managed-apps
2019-02-15 15:39:39 +05:30
-f /data/helm/app-name/config/values.yaml
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
2020-05-24 23:13:21 +05:30
it_behaves_like 'helm command' do
let(:command) { install_command }
2018-03-17 18:26:18 +05:30
end
end