summaryrefslogtreecommitdiff
path: root/lib/gitlab/kubernetes/helm/v2/init_command.rb
blob: f8b52feb5b6d76678f40bddb62c88b4345f78f80 (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
# frozen_string_literal: true

module Gitlab
  module Kubernetes
    module Helm
      module V2
        class InitCommand < BaseCommand
          def generate_script
            super + [
              init_helm_command
            ].join("\n")
          end

          private

          def init_helm_command
            command = %w[helm init] + init_command_flags

            command.shelljoin
          end

          def init_command_flags
            tls_flags + optional_service_account_flag
          end

          def tls_flags
            [
              '--tiller-tls',
              '--tiller-tls-verify',
              '--tls-ca-cert', "#{files_dir}/ca.pem",
              '--tiller-tls-cert', "#{files_dir}/cert.pem",
              '--tiller-tls-key', "#{files_dir}/key.pem"
            ]
          end

          def optional_service_account_flag
            return [] unless rbac?

            ['--service-account', service_account_name]
          end
        end
      end
    end
  end
end