summaryrefslogtreecommitdiff
path: root/qa/qa/service/docker_run/k3s.rb
blob: 07211b220f12265d4baa5465c438f3b0e4cd8a54 (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
# frozen_string_literal: true

module QA
  module Service
    module DockerRun
      class K3s < Base
        def initialize
          @image = 'registry.gitlab.com/gitlab-org/cluster-integration/test-utils/k3s-gitlab-ci/releases/v0.6.1'
          @name = 'k3s'
          super
        end

        def register!
          pull
          start_k3s
        end

        def host_name
          return 'localhost' unless Runtime::Env.running_in_ci?

          super
        end

        def kubeconfig
          read_file('/etc/rancher/k3s/k3s.yaml').chomp
        end

        def start_k3s
          command = <<~CMD.tr("\n", ' ')
            docker run -d --rm
            --network #{network}
            --hostname #{host_name}
            --name #{@name}
            --publish 6443:6443
            --privileged
            #{@image} server
            --cluster-secret some-secret
            --no-deploy traefik
          CMD

          command.gsub!("--network #{network} --hostname #{host_name}", '') unless QA::Runtime::Env.running_in_ci?

          shell command
        end
      end
    end
  end
end