summaryrefslogtreecommitdiff
path: root/lib/gitlab/kubernetes/helm/install_command.rb
blob: 846a1948434db069da8806ef8ecaedec389430ab (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
module Gitlab
  module Kubernetes
    class Helm::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

        "helm install #{chart} --name #{name} --namespace #{namespace_name} >/dev/null"
      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