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