Commit a236468a authored by Stan Hu's avatar Stan Hu

Merge branch 'tillerless-gitlab-managed-apps' into 'master'

Implement Tillerless install and uninstall

See merge request gitlab-org/gitlab!20894
parents 97f2dcbd 521e270d
......@@ -5,14 +5,24 @@ module Gitlab
module Helm
module ClientCommand
def init_command
if local_tiller_enabled?
<<~HEREDOC.chomp
export HELM_HOST="localhost:44134"
tiller -listen ${HELM_HOST} -alsologtostderr &
helm init --client-only
HEREDOC
else
# Here we are always upgrading to the latest version of Tiller when
# installing an app. We ensure the helm version stored in the
# database is correct by also updating this after transition to
# :installed,:updated in Clusters::Concerns::ApplicationStatus
'helm init --upgrade'
end
end
def wait_for_tiller_command
return if local_tiller_enabled?
helm_check = ['helm', 'version', *optional_tls_flags].shelljoin
# This is necessary to give Tiller time to restart after upgrade.
# Ideally we'd be able to use --wait but cannot because of
......@@ -25,6 +35,14 @@ module Gitlab
['helm', 'repo', 'add', name, repository].shelljoin if repository
end
private
def tls_flags_if_remote_tiller
return [] if local_tiller_enabled?
optional_tls_flags
end
def optional_tls_flags
return [] unless files.key?(:'ca.pem')
......@@ -35,6 +53,10 @@ module Gitlab
'--tls-key', "#{files_dir}/key.pem"
]
end
def local_tiller_enabled?
Feature.enabled?(:managed_apps_local_tiller)
end
end
end
end
......
......@@ -39,7 +39,7 @@ module Gitlab
private
def delete_command
command = ['helm', 'delete', '--purge', name] + optional_tls_flags
command = ['helm', 'delete', '--purge', name] + tls_flags_if_remote_tiller
command.shelljoin
end
......
......@@ -49,7 +49,7 @@ module Gitlab
command = ['helm', 'upgrade', name, chart] +
install_flag +
reset_values_flag +
optional_tls_flags +
tls_flags_if_remote_tiller +
optional_version_flag +
rbac_create_flag +
namespace_flag +
......
......@@ -10,6 +10,22 @@ describe Gitlab::Kubernetes::Helm::DeleteCommand do
subject { delete_command }
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
export HELM_HOST="localhost:44134"
tiller -listen ${HELM_HOST} -alsologtostderr &
helm init --client-only
helm delete --purge app-name
EOS
end
end
context 'tillerless feature disabled' do
before do
stub_feature_flags(managed_apps_local_tiller: false)
end
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
......@@ -20,6 +36,9 @@ describe Gitlab::Kubernetes::Helm::DeleteCommand do
end
end
context 'when there is a ca.pem file' do
let(:files) { { 'ca.pem': 'some file content' } }
let(:tls_flags) do
<<~EOS.squish
--tls
......@@ -29,9 +48,6 @@ describe Gitlab::Kubernetes::Helm::DeleteCommand do
EOS
end
context 'when there is a ca.pem file' do
let(:files) { { 'ca.pem': 'some file content' } }
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
......@@ -49,6 +65,7 @@ describe Gitlab::Kubernetes::Helm::DeleteCommand do
end
end
end
end
describe '#pod_resource' do
subject { delete_command.pod_resource }
......
......@@ -23,6 +23,38 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
)
end
subject { install_command }
it_behaves_like 'helm commands' do
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
#{helm_install_comand}
EOS
end
let(:helm_install_comand) do
<<~EOS.squish
helm upgrade app-name chart-name
--install
--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
EOS
end
end
context 'tillerless feature disabled' do
before do
stub_feature_flags(managed_apps_local_tiller: false)
end
let(:tls_flags) do
<<~EOS.squish
--tls
......@@ -32,8 +64,6 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
EOS
end
subject { install_command }
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
......@@ -58,6 +88,7 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
EOS
end
end
end
context 'when rbac is true' do
let(:rbac) { true }
......@@ -65,8 +96,9 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
helm init --upgrade
for i in $(seq 1 30); do helm version #{tls_flags} && s=0 && break || s=$?; sleep 1s; echo \"Retrying ($i)...\"; done; (exit $s)
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
#{helm_install_command}
......@@ -78,7 +110,6 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
helm upgrade app-name chart-name
--install
--reset-values
#{tls_flags}
--version 1.2.3
--set rbac.create\\=true,rbac.enabled\\=true
--namespace gitlab-managed-apps
......@@ -94,8 +125,9 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
helm init --upgrade
for i in $(seq 1 30); do helm version #{tls_flags} && s=0 && break || s=$?; sleep 1s; echo \"Retrying ($i)...\"; done; (exit $s)
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
/bin/date
......@@ -109,7 +141,6 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
helm upgrade app-name chart-name
--install
--reset-values
#{tls_flags}
--version 1.2.3
--set rbac.create\\=false,rbac.enabled\\=false
--namespace gitlab-managed-apps
......@@ -125,8 +156,9 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
helm init --upgrade
for i in $(seq 1 30); do helm version #{tls_flags} && s=0 && break || s=$?; sleep 1s; echo \"Retrying ($i)...\"; done; (exit $s)
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
#{helm_install_command}
......@@ -140,7 +172,6 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
helm upgrade app-name chart-name
--install
--reset-values
#{tls_flags}
--version 1.2.3
--set rbac.create\\=false,rbac.enabled\\=false
--namespace gitlab-managed-apps
......@@ -156,8 +187,9 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
helm init --upgrade
for i in $(seq 1 30); do helm version && s=0 && break || s=$?; sleep 1s; echo \"Retrying ($i)...\"; done; (exit $s)
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
#{helm_install_command}
......@@ -184,8 +216,9 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
helm init --upgrade
for i in $(seq 1 30); do helm version #{tls_flags} && s=0 && break || s=$?; sleep 1s; echo \"Retrying ($i)...\"; done; (exit $s)
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
#{helm_install_command}
......@@ -197,7 +230,6 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
helm upgrade app-name chart-name
--install
--reset-values
#{tls_flags}
--set rbac.create\\=false,rbac.enabled\\=false
--namespace gitlab-managed-apps
-f /data/helm/app-name/config/values.yaml
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment