Commit 2653b9b2 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '27630-use-ci-specified-namespace-for-deploy-boards' into 'master'

Allow CI specified k8s namespace for deploy boards, terminals & pod logs

See merge request gitlab-org/gitlab!21460
parents 3eb67d94 fea10b45
......@@ -249,14 +249,9 @@ module Clusters
end
def kubernetes_namespace_for(environment)
project = environment.project
persisted_namespace = Clusters::KubernetesNamespaceFinder.new(
self,
project: project,
environment_name: environment.name
).execute
persisted_namespace&.namespace || Gitlab::Kubernetes::DefaultNamespace.new(self, project: project).from_environment_slug(environment.slug)
managed_namespace(environment) ||
ci_configured_namespace(environment) ||
default_namespace(environment)
end
def allow_user_defined_namespace?
......@@ -308,6 +303,25 @@ module Clusters
end
end
def managed_namespace(environment)
Clusters::KubernetesNamespaceFinder.new(
self,
project: environment.project,
environment_name: environment.name
).execute&.namespace
end
def ci_configured_namespace(environment)
environment.last_deployable&.expanded_kubernetes_namespace
end
def default_namespace(environment)
Gitlab::Kubernetes::DefaultNamespace.new(
self,
project: environment.project
).from_environment_slug(environment.slug)
end
def instance_domain
@instance_domain ||= Gitlab::CurrentSettings.auto_devops_domain
end
......
---
title: Allow Kubernetes namespaces specified via CI template to be used for terminals,
pod logs and deploy boards
merge_request: 21460
author:
type: added
......@@ -674,7 +674,8 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
describe '#kubernetes_namespace_for' do
let(:cluster) { create(:cluster, :group) }
let(:environment) { create(:environment) }
let(:environment) { create(:environment, last_deployable: build) }
let(:build) { create(:ci_build) }
subject { cluster.kubernetes_namespace_for(environment) }
......@@ -682,16 +683,15 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
expect(Clusters::KubernetesNamespaceFinder).to receive(:new)
.with(cluster, project: environment.project, environment_name: environment.name)
.and_return(double(execute: persisted_namespace))
end
context 'a persisted namespace exists' do
let(:persisted_namespace) { create(:cluster_kubernetes_namespace) }
it { is_expected.to eq persisted_namespace.namespace }
allow(build).to receive(:expanded_kubernetes_namespace)
.and_return(ci_configured_namespace)
end
context 'no persisted namespace exists' do
context 'no persisted namespace exists and namespace is not specified in CI template' do
let(:persisted_namespace) { nil }
let(:ci_configured_namespace) { nil }
let(:namespace_generator) { double }
let(:default_namespace) { 'a-default-namespace' }
......@@ -706,6 +706,27 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
it { is_expected.to eq default_namespace }
end
context 'persisted namespace exists' do
let(:persisted_namespace) { create(:cluster_kubernetes_namespace) }
let(:ci_configured_namespace) { nil }
it { is_expected.to eq persisted_namespace.namespace }
end
context 'namespace is specified in CI template' do
let(:persisted_namespace) { nil }
let(:ci_configured_namespace) { 'ci-configured-namespace' }
it { is_expected.to eq ci_configured_namespace }
end
context 'persisted namespace exists and namespace is also specifed in CI template' do
let(:persisted_namespace) { create(:cluster_kubernetes_namespace) }
let(:ci_configured_namespace) { 'ci-configured-namespace' }
it { is_expected.to eq persisted_namespace.namespace }
end
end
describe '#predefined_variables' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment