Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cluster_helpers.rb « migrations_helpers « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 03104e22bcf4da2e8e11558754590833d3f315cf (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
67
68
69
70
71
# frozen_string_literal: true

module MigrationHelpers
  module ClusterHelpers
    # Creates a list of cluster projects.
    def create_cluster_project_list(quantity)
      group = namespaces_table.create!(name: 'gitlab-org', path: 'gitlab-org')

      quantity.times do |id|
        create_cluster_project(group, id)
      end
    end

    # Creates dependencies for a cluster project:
    # - Group
    # - Project
    # - Cluster
    # - Project - cluster relationship
    # - GCP provider
    # - Platform Kubernetes
    def create_cluster_project(group, id)
      project = projects_table.create!(
        name: "project-#{id}",
        path: "project-#{id}",
        namespace_id: group.id
      )

      cluster = clusters_table.create!(
        name: 'test-cluster',
        cluster_type: 3,
        provider_type: :gcp,
        platform_type: :kubernetes
      )

      cluster_projects_table.create!(project_id: project.id, cluster_id: cluster.id)

      provider_gcp_table.create!(
        gcp_project_id: "test-gcp-project-#{id}",
        endpoint: '111.111.111.111',
        cluster_id: cluster.id,
        status: 3,
        num_nodes: 1,
        zone: 'us-central1-a'
      )

      platform_kubernetes_table.create!(
        cluster_id: cluster.id,
        api_url: 'https://kubernetes.example.com',
        encrypted_token: 'a' * 40,
        encrypted_token_iv: 'a' * 40
      )
    end

    # Creates a Kubernetes namespace for a list of clusters
    def create_kubernetes_namespace(clusters)
      clusters.each do |cluster|
        cluster_project = cluster_projects_table.find_by(cluster_id: cluster.id)
        project = projects_table.find(cluster_project.project_id)
        namespace = "#{project.path}-#{project.id}"

        cluster_kubernetes_namespaces_table.create!(
          cluster_project_id: cluster_project.id,
          cluster_id: cluster.id,
          project_id: cluster_project.project_id,
          namespace: namespace,
          service_account_name: "#{namespace}-service-account"
        )
      end
    end
  end
end