gitlab-org--gitlab-foss/spec/lib/gitlab/prometheus/query_variables_spec.rb
Tiger 101c4480b3 Remove legacy Kubernetes #actual_namespace
When Kubernetes clusters were originally built they could only
exist at the project level, and so there was logic included
that assumed there would only ever be a single Kubernetes
namespace per cluster. We now support clusters at the group
and instance level, which allows multiple namespaces.

This change consolidates various project-specific fallbacks to
generate namespaces, and hands all responsibility to the
Clusters::KubernetesNamespace model. There is now no concept of
a single namespace for a Clusters::Platforms::Kubernetes; to
retrieve a namespace a project must now be supplied in all cases.

This simplifies upcoming work to use a separate Kubernetes
namespace per project environment (instead of a namespace
per project).
2019-05-21 11:38:11 -05:00

53 lines
1.6 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Prometheus::QueryVariables do
describe '.call' do
let(:project) { environment.project }
let(:environment) { create(:environment) }
let(:slug) { environment.slug }
subject { described_class.call(environment) }
it { is_expected.to include(ci_environment_slug: slug) }
it do
is_expected.to include(environment_filter:
%{container_name!="POD",environment="#{slug}"})
end
context 'without deployment platform' do
it { is_expected.to include(kube_namespace: '') }
end
context 'with deployment platform' do
context 'with project cluster' do
let(:kube_namespace) { environment.deployment_platform.cluster.kubernetes_namespace_for(project) }
before do
create(:cluster, :project, :provided_by_user, projects: [project])
end
it { is_expected.to include(kube_namespace: kube_namespace) }
end
context 'with group cluster' do
let(:cluster) { create(:cluster, :group, :provided_by_user, groups: [group]) }
let(:group) { create(:group) }
let(:project2) { create(:project) }
let(:kube_namespace) { k8s_ns.namespace }
let!(:k8s_ns) { create(:cluster_kubernetes_namespace, cluster: cluster, project: project) }
let!(:k8s_ns2) { create(:cluster_kubernetes_namespace, cluster: cluster, project: project2) }
before do
group.projects << project
group.projects << project2
end
it { is_expected.to include(kube_namespace: kube_namespace) }
end
end
end
end