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

module Gitlab
  module Kubernetes
    module Helm
      class DeleteCommand
        include BaseCommand
        include ClientCommand

        attr_accessor :name, :files

        def initialize(name:, rbac:, files:)
          @name = name
          @files = files
          @rbac = rbac
        end

        def generate_script
          super + [
            init_command,
            wait_for_tiller_command,
            delete_command
          ].compact.join("\n")
        end

        def pod_name
          "uninstall-#{name}"
        end

        def rbac?
          @rbac
        end

        private

        def delete_command
          command = ['helm', 'delete', '--purge', name] + optional_tls_flags

          command.shelljoin
        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