2018-10-16 16:03:59 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
FactoryBot.define do
|
2020-01-09 13:07:52 -05:00
|
|
|
factory :cluster_kubernetes_namespace, class: 'Clusters::KubernetesNamespace' do
|
2018-11-02 11:46:15 -04:00
|
|
|
association :cluster, :project, :provided_by_gcp
|
|
|
|
|
|
|
|
after(:build) do |kubernetes_namespace|
|
2019-08-07 00:40:29 -04:00
|
|
|
cluster = kubernetes_namespace.cluster
|
|
|
|
|
|
|
|
if cluster.project_type?
|
|
|
|
cluster_project = cluster.cluster_project
|
2018-11-02 11:46:15 -04:00
|
|
|
|
2020-09-03 17:08:18 -04:00
|
|
|
kubernetes_namespace.project = cluster_project&.project
|
2018-11-26 23:30:09 -05:00
|
|
|
kubernetes_namespace.cluster_project = cluster_project
|
|
|
|
end
|
2019-08-07 00:40:29 -04:00
|
|
|
|
2020-09-03 17:08:18 -04:00
|
|
|
if kubernetes_namespace.project
|
|
|
|
kubernetes_namespace.namespace ||=
|
|
|
|
Gitlab::Kubernetes::DefaultNamespace.new(
|
|
|
|
cluster,
|
|
|
|
project: kubernetes_namespace.project
|
|
|
|
).from_environment_slug(kubernetes_namespace.environment&.slug)
|
|
|
|
end
|
|
|
|
|
2019-08-07 00:40:29 -04:00
|
|
|
kubernetes_namespace.service_account_name ||= "#{kubernetes_namespace.namespace}-service-account"
|
2018-11-02 11:46:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_token do
|
2018-11-13 05:27:21 -05:00
|
|
|
service_account_token { FFaker::Lorem.characters(10) }
|
2018-11-02 11:46:15 -04:00
|
|
|
end
|
2019-06-14 01:57:48 -04:00
|
|
|
|
|
|
|
trait :without_token do
|
2019-10-01 20:06:26 -04:00
|
|
|
service_account_token { nil }
|
2019-06-14 01:57:48 -04:00
|
|
|
end
|
2018-10-16 16:03:59 -04:00
|
|
|
end
|
|
|
|
end
|