summaryrefslogtreecommitdiff
path: root/qa/qa/resource/kubernetes_cluster/project_cluster.rb
blob: b66a75d978b9c41a074a7b65ab079fb6af7c0b97 (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
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true

module QA
  module Resource
    module KubernetesCluster
      class ProjectCluster < Base
        attr_writer :cluster,
                    :install_ingress, :install_prometheus, :install_runner, :domain

        attribute :project do
          Resource::Project.fabricate!
        end

        attribute :ingress_ip do
          Page::Project::Infrastructure::Kubernetes::Show.perform(&:ingress_ip)
        end

        def fabricate!
          project.visit!

          Page::Project::Menu.perform(
            &:go_to_infrastructure_kubernetes)

          Page::Project::Infrastructure::Kubernetes::Index.perform(
            &:add_kubernetes_cluster)

          Page::Project::Infrastructure::Kubernetes::Add.perform(
            &:add_existing_cluster)

          Page::Project::Infrastructure::Kubernetes::AddExisting.perform do |cluster_page|
            cluster_page.set_cluster_name(@cluster.cluster_name)
            cluster_page.set_api_url(@cluster.api_url)
            cluster_page.set_ca_certificate(@cluster.ca_certificate)
            cluster_page.set_token(@cluster.token)
            cluster_page.uncheck_rbac! unless @cluster.rbac
            cluster_page.add_cluster!
          end

          Page::Project::Infrastructure::Kubernetes::Show.perform do |show|
            # We must wait a few seconds for permissions to be set up correctly for new cluster
            sleep 25

            # Open applications tab
            show.open_applications

            show.install!(:ingress) if @install_ingress
            show.install!(:prometheus) if @install_prometheus
            show.install!(:runner) if @install_runner

            show.await_installed(:ingress) if @install_ingress
            show.await_installed(:prometheus) if @install_prometheus
            show.await_installed(:runner) if @install_runner

            if @install_ingress
              populate(:ingress_ip)

              show.open_details
              show.set_domain("#{ingress_ip}.nip.io")
              show.save_domain
            end
          end
        end
      end
    end
  end
end