diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-10-02 17:06:29 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-10-02 17:06:29 +0000 |
commit | 607f263c4869d78b113c3610f11cfc3f909ec3b4 (patch) | |
tree | 8badae69eef5ac4770d462dc4be9d9d1b5c82ef1 /lib | |
parent | cfc72c126e22df2485f08f11be500a183727c306 (diff) | |
parent | f6ff32d9bd7a9817bb74379a1f28954aa378559c (diff) | |
download | gitlab-ce-607f263c4869d78b113c3610f11cfc3f909ec3b4.tar.gz |
Merge branch '49952-port-upgrade-command-to-ce' into 'master'
Port UpgradeCommand to CE
See merge request gitlab-org/gitlab-ce!21949
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/kubernetes/helm/api.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/kubernetes/helm/upgrade_command.rb | 71 |
2 files changed, 89 insertions, 0 deletions
diff --git a/lib/gitlab/kubernetes/helm/api.rb b/lib/gitlab/kubernetes/helm/api.rb index 2dd74c68075..e21bc531444 100644 --- a/lib/gitlab/kubernetes/helm/api.rb +++ b/lib/gitlab/kubernetes/helm/api.rb @@ -17,6 +17,12 @@ module Gitlab kubeclient.create_pod(command.pod_resource) end + def update(command) + namespace.ensure_exists! + update_config_map(command) + kubeclient.create_pod(command.pod_resource) + end + ## # Returns Pod phase # @@ -36,6 +42,12 @@ module Gitlab kubeclient.delete_pod(pod_name, namespace.name) end + def get_config_map(config_map_name) + namespace.ensure_exists! + + kubeclient.get_config_map(config_map_name, namespace.name) + end + private attr_reader :kubeclient, :namespace @@ -46,6 +58,12 @@ module Gitlab end end + def update_config_map(command) + command.config_map_resource.tap do |config_map_resource| + kubeclient.update_config_map(config_map_resource) + end + end + def create_service_account(command) command.service_account_resource.tap do |service_account_resource| break unless service_account_resource diff --git a/lib/gitlab/kubernetes/helm/upgrade_command.rb b/lib/gitlab/kubernetes/helm/upgrade_command.rb new file mode 100644 index 00000000000..74188046739 --- /dev/null +++ b/lib/gitlab/kubernetes/helm/upgrade_command.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +module Gitlab + module Kubernetes + module Helm + class UpgradeCommand + include BaseCommand + + attr_reader :name, :chart, :version, :repository, :files + + def initialize(name, chart:, files:, rbac:, version: nil, repository: nil) + @name = name + @chart = chart + @rbac = rbac + @version = version + @files = files + @repository = repository + end + + def generate_script + super + [ + init_command, + repository_command, + script_command + ].compact.join("\n") + end + + def rbac? + @rbac + end + + def pod_name + "upgrade-#{name}" + end + + private + + def init_command + 'helm init --client-only >/dev/null' + end + + def repository_command + "helm repo add #{name} #{repository}" if repository + end + + def script_command + upgrade_flags = "#{optional_version_flag}#{optional_tls_flags}" \ + " --reset-values" \ + " --install" \ + " --namespace #{::Gitlab::Kubernetes::Helm::NAMESPACE}" \ + " -f /data/helm/#{name}/config/values.yaml" + + "helm upgrade #{name} #{chart}#{upgrade_flags} >/dev/null\n" + end + + def optional_version_flag + " --version #{version}" if version + end + + def optional_tls_flags + return unless files.key?(:'ca.pem') + + " --tls" \ + " --tls-ca-cert #{files_dir}/ca.pem" \ + " --tls-cert #{files_dir}/cert.pem" \ + " --tls-key #{files_dir}/key.pem" + end + end + end + end +end |