summaryrefslogtreecommitdiff
path: root/lib/gitlab/kubernetes/helm/install_command.rb
blob: bf6981035f45990178b0ad5d362a5bffb2b3d975 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module Gitlab
  module Kubernetes
    module Helm
      class InstallCommand
        attr_reader :name, :install_helm, :chart, :chart_values_file

        def initialize(name, install_helm: false, chart: false, chart_values_file: false)
          @name = name
          @install_helm = install_helm
          @chart = chart
          @chart_values_file = chart_values_file
        end

        def pod_name
          "install-#{name}"
        end

        def generate_script(namespace_name)
          [
            install_dps_command,
            init_command,
            complete_command(namespace_name)
          ].join("\n")
        end

        private

        def init_command
          if install_helm
            'helm init >/dev/null'
          else
            'helm init --client-only >/dev/null'
          end
        end

        def complete_command(namespace_name)
          return unless chart

          if chart_values_file
            "helm install #{chart} --name #{name} --namespace #{namespace_name} -f /data/helm/#{name}/config/values.yaml >/dev/null"
          else
            "helm install #{chart} --name #{name} --namespace #{namespace_name} >/dev/null"
          end
        end

        def install_dps_command
          <<~HEREDOC
            set -eo pipefail
            apk add -U ca-certificates openssl >/dev/null
            wget -q -O - https://kubernetes-helm.storage.googleapis.com/helm-v#{Gitlab::Kubernetes::Helm::HELM_VERSION}-linux-amd64.tar.gz | tar zxC /tmp >/dev/null
            mv /tmp/linux-amd64/helm /usr/bin/
          HEREDOC
        end
      end
    end
  end
end