2019-08-07 00:40:29 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Clusters
|
|
|
|
class KubernetesNamespaceFinder
|
2019-09-23 11:06:32 -04:00
|
|
|
attr_reader :cluster, :project, :environment_name
|
2019-08-07 00:40:29 -04:00
|
|
|
|
2019-09-23 11:06:32 -04:00
|
|
|
def initialize(cluster, project:, environment_name:, allow_blank_token: false)
|
2019-08-07 00:40:29 -04:00
|
|
|
@cluster = cluster
|
|
|
|
@project = project
|
2019-09-23 11:06:32 -04:00
|
|
|
@environment_name = environment_name
|
2019-08-07 00:40:29 -04:00
|
|
|
@allow_blank_token = allow_blank_token
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
find_namespace(with_environment: cluster.namespace_per_environment?)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :allow_blank_token
|
|
|
|
|
|
|
|
def find_namespace(with_environment:)
|
2019-09-23 11:06:32 -04:00
|
|
|
relation = if with_environment
|
|
|
|
namespaces.with_environment_name(environment_name)
|
|
|
|
else
|
|
|
|
namespaces
|
|
|
|
end
|
2019-08-07 00:40:29 -04:00
|
|
|
|
|
|
|
relation.find_by_project_id(project.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def namespaces
|
|
|
|
if allow_blank_token
|
|
|
|
cluster.kubernetes_namespaces
|
|
|
|
else
|
|
|
|
cluster.kubernetes_namespaces.has_service_account_token
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|