debian-mirror-gitlab/spec/support/helpers/migrations_helpers/cluster_helpers.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
2 KiB
Ruby
Raw Permalink Normal View History

2019-03-02 22:35:43 +05:30
# frozen_string_literal: true
module MigrationHelpers
module ClusterHelpers
# Creates a list of cluster projects.
def create_cluster_project_list(quantity)
2021-01-03 14:25:43 +05:30
group = namespaces_table.create!(name: 'gitlab-org', path: 'gitlab-org')
2019-03-02 22:35:43 +05:30
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
)
2021-01-03 14:25:43 +05:30
cluster = clusters_table.create!(
2019-03-02 22:35:43 +05:30
name: 'test-cluster',
cluster_type: 3,
provider_type: :gcp,
platform_type: :kubernetes
)
2021-01-03 14:25:43 +05:30
cluster_projects_table.create!(project_id: project.id, cluster_id: cluster.id)
2019-03-02 22:35:43 +05:30
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'
)
2021-01-03 14:25:43 +05:30
platform_kubernetes_table.create!(
2019-03-02 22:35:43 +05:30
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}"
2021-01-03 14:25:43 +05:30
cluster_kubernetes_namespaces_table.create!(
2019-03-02 22:35:43 +05:30
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