summaryrefslogtreecommitdiff
path: root/lib/gitlab/kubernetes/helm
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-20 09:07:57 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-20 09:07:57 +0000
commit7881eb30eaa8b01dbcfe87faa09927c75c7d6e45 (patch)
tree298bc8d2c62b2f2c29cb8ecbcf3de3eaaa6466d9 /lib/gitlab/kubernetes/helm
parent64b66e0cb6d1bfd27abf24e06653f00bddb60597 (diff)
downloadgitlab-ce-7881eb30eaa8b01dbcfe87faa09927c75c7d6e45.tar.gz
Add latest changes from gitlab-org/gitlab@12-6-stable-ee
Diffstat (limited to 'lib/gitlab/kubernetes/helm')
-rw-r--r--lib/gitlab/kubernetes/helm/client_command.rb36
-rw-r--r--lib/gitlab/kubernetes/helm/delete_command.rb2
-rw-r--r--lib/gitlab/kubernetes/helm/install_command.rb6
-rw-r--r--lib/gitlab/kubernetes/helm/patch_command.rb73
4 files changed, 106 insertions, 11 deletions
diff --git a/lib/gitlab/kubernetes/helm/client_command.rb b/lib/gitlab/kubernetes/helm/client_command.rb
index a3f732e1283..b953ce24c4a 100644
--- a/lib/gitlab/kubernetes/helm/client_command.rb
+++ b/lib/gitlab/kubernetes/helm/client_command.rb
@@ -5,14 +5,24 @@ module Gitlab
module Helm
module ClientCommand
def init_command
- # 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'
+ 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,18 @@ 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 repository_update_command
+ 'helm repo update'
+ end
+
def optional_tls_flags
return [] unless files.key?(:'ca.pem')
@@ -35,6 +57,10 @@ module Gitlab
'--tls-key', "#{files_dir}/key.pem"
]
end
+
+ def local_tiller_enabled?
+ Feature.enabled?(:managed_apps_local_tiller)
+ end
end
end
end
diff --git a/lib/gitlab/kubernetes/helm/delete_command.rb b/lib/gitlab/kubernetes/helm/delete_command.rb
index dcf22e7abb6..9d0fd30ba8f 100644
--- a/lib/gitlab/kubernetes/helm/delete_command.rb
+++ b/lib/gitlab/kubernetes/helm/delete_command.rb
@@ -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
diff --git a/lib/gitlab/kubernetes/helm/install_command.rb b/lib/gitlab/kubernetes/helm/install_command.rb
index ccb053f507d..8e24cb4c24f 100644
--- a/lib/gitlab/kubernetes/helm/install_command.rb
+++ b/lib/gitlab/kubernetes/helm/install_command.rb
@@ -39,17 +39,13 @@ module Gitlab
private
- def repository_update_command
- 'helm repo update'
- end
-
# Uses `helm upgrade --install` which means we can use this for both
# installation and uprade of applications
def install_command
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 +
diff --git a/lib/gitlab/kubernetes/helm/patch_command.rb b/lib/gitlab/kubernetes/helm/patch_command.rb
new file mode 100644
index 00000000000..ed7a5c2b2d6
--- /dev/null
+++ b/lib/gitlab/kubernetes/helm/patch_command.rb
@@ -0,0 +1,73 @@
+# frozen_string_literal: true
+
+# PatchCommand is for updating values in installed charts without overwriting
+# existing values.
+module Gitlab
+ module Kubernetes
+ module Helm
+ class PatchCommand
+ include BaseCommand
+ include ClientCommand
+
+ attr_reader :name, :files, :chart, :repository
+ attr_accessor :version
+
+ def initialize(name:, chart:, files:, rbac:, version:, repository: nil)
+ # version is mandatory to prevent chart mismatches
+ # we do not want our values interpreted in the context of the wrong version
+ raise ArgumentError, 'version is required' if version.blank?
+
+ @name = name
+ @chart = chart
+ @version = version
+ @rbac = rbac
+ @files = files
+ @repository = repository
+ end
+
+ def generate_script
+ super + [
+ init_command,
+ wait_for_tiller_command,
+ repository_command,
+ repository_update_command,
+ upgrade_command
+ ].compact.join("\n")
+ end
+
+ def rbac?
+ @rbac
+ end
+
+ private
+
+ def upgrade_command
+ command = ['helm', 'upgrade', name, chart] +
+ reuse_values_flag +
+ tls_flags_if_remote_tiller +
+ version_flag +
+ namespace_flag +
+ value_flag
+
+ command.shelljoin
+ end
+
+ def reuse_values_flag
+ ['--reuse-values']
+ end
+
+ def value_flag
+ ['-f', "/data/helm/#{name}/config/values.yaml"]
+ end
+
+ def namespace_flag
+ ['--namespace', Gitlab::Kubernetes::Helm::NAMESPACE]
+ end
+
+ def version_flag
+ ['--version', version]
+ end
+ end
+ end
+ end
+end