36a01a88ce
Kubernetes deployments on new clusters will now have a separate namespace per project environment, instead of sharing a single namespace for the project. Behaviour of existing clusters is unchanged. All new functionality is controlled by the :kubernetes_namespace_per_environment feature flag, which is safe to enable/disable at any time.
35 lines
864 B
Ruby
35 lines
864 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Clusters
|
|
class BuildKubernetesNamespaceService
|
|
attr_reader :cluster, :environment
|
|
|
|
def initialize(cluster, environment:)
|
|
@cluster = cluster
|
|
@environment = environment
|
|
end
|
|
|
|
def execute
|
|
cluster.kubernetes_namespaces.build(attributes)
|
|
end
|
|
|
|
private
|
|
|
|
def attributes
|
|
attributes = {
|
|
project: environment.project,
|
|
namespace: namespace,
|
|
service_account_name: "#{namespace}-service-account"
|
|
}
|
|
|
|
attributes[:cluster_project] = cluster.cluster_project if cluster.project_type?
|
|
attributes[:environment] = environment if cluster.namespace_per_environment?
|
|
|
|
attributes
|
|
end
|
|
|
|
def namespace
|
|
Gitlab::Kubernetes::DefaultNamespace.new(cluster, project: environment.project).from_environment_slug(environment.slug)
|
|
end
|
|
end
|
|
end
|