diff options
author | Tiger <twatson@gitlab.com> | 2019-05-17 01:49:12 +0300 |
---|---|---|
committer | Tiger <twatson@gitlab.com> | 2019-05-21 19:38:11 +0300 |
commit | 101c4480b32044682e453753c6bb18c2a296b044 (patch) | |
tree | 46b6ac3df55c748a6854bdb5c02a696228a7e9fc /spec/support | |
parent | 0702d4b6899648ba12a747824f3db86c2f4aa42e (diff) |
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).
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/helpers/kubernetes_helpers.rb | 24 | ||||
-rw-r--r-- | spec/support/prometheus/additional_metrics_shared_examples.rb | 2 |
2 files changed, 16 insertions, 10 deletions
diff --git a/spec/support/helpers/kubernetes_helpers.rb b/spec/support/helpers/kubernetes_helpers.rb index ac52acb6570..78b7ae9c00c 100644 --- a/spec/support/helpers/kubernetes_helpers.rb +++ b/spec/support/helpers/kubernetes_helpers.rb @@ -24,30 +24,34 @@ module KubernetesHelpers WebMock.stub_request(:get, api_url + '/apis/serving.knative.dev/v1alpha1').to_return(kube_response(kube_v1alpha1_serving_knative_discovery_body)) end - def stub_kubeclient_service_pods(response = nil) + def stub_kubeclient_service_pods(status: nil) stub_kubeclient_discover(service.api_url) pods_url = service.api_url + "/api/v1/pods" + response = { status: status } if status WebMock.stub_request(:get, pods_url).to_return(response || kube_pods_response) end - def stub_kubeclient_pods(response = nil) + def stub_kubeclient_pods(namespace, status: nil) stub_kubeclient_discover(service.api_url) - pods_url = service.api_url + "/api/v1/namespaces/#{service.actual_namespace}/pods" + pods_url = service.api_url + "/api/v1/namespaces/#{namespace}/pods" + response = { status: status } if status WebMock.stub_request(:get, pods_url).to_return(response || kube_pods_response) end - def stub_kubeclient_logs(pod_name, response = nil) + def stub_kubeclient_logs(pod_name, namespace, status: nil) stub_kubeclient_discover(service.api_url) - logs_url = service.api_url + "/api/v1/namespaces/#{service.actual_namespace}/pods/#{pod_name}/log?tailLines=#{Clusters::Platforms::Kubernetes::LOGS_LIMIT}" + logs_url = service.api_url + "/api/v1/namespaces/#{namespace}/pods/#{pod_name}/log?tailLines=#{Clusters::Platforms::Kubernetes::LOGS_LIMIT}" + response = { status: status } if status WebMock.stub_request(:get, logs_url).to_return(response || kube_logs_response) end - def stub_kubeclient_deployments(response = nil) + def stub_kubeclient_deployments(namespace, status: nil) stub_kubeclient_discover(service.api_url) - deployments_url = service.api_url + "/apis/extensions/v1beta1/namespaces/#{service.actual_namespace}/deployments" + deployments_url = service.api_url + "/apis/extensions/v1beta1/namespaces/#{namespace}/deployments" + response = { status: status } if status WebMock.stub_request(:get, deployments_url).to_return(response || kube_deployments_response) end @@ -250,10 +254,11 @@ module KubernetesHelpers # This is a partial response, it will have many more elements in reality but # these are the ones we care about at the moment - def kube_pod(name: "kube-pod", environment_slug: "production", project_slug: "project-path-slug", status: "Running", track: nil) + def kube_pod(name: "kube-pod", environment_slug: "production", namespace: "project-namespace", project_slug: "project-path-slug", status: "Running", track: nil) { "metadata" => { "name" => name, + "namespace" => namespace, "generate_name" => "generated-name-with-suffix", "creationTimestamp" => "2016-11-25T19:55:19Z", "annotations" => { @@ -369,12 +374,13 @@ module KubernetesHelpers def kube_terminals(service, pod) pod_name = pod['metadata']['name'] + pod_namespace = pod['metadata']['namespace'] containers = pod['spec']['containers'] containers.map do |container| terminal = { selectors: { pod: pod_name, container: container['name'] }, - url: container_exec_url(service.api_url, service.actual_namespace, pod_name, container['name']), + url: container_exec_url(service.api_url, pod_namespace, pod_name, container['name']), subprotocols: ['channel.k8s.io'], headers: { 'Authorization' => ["Bearer #{service.token}"] }, created_at: DateTime.parse(pod['metadata']['creationTimestamp']), diff --git a/spec/support/prometheus/additional_metrics_shared_examples.rb b/spec/support/prometheus/additional_metrics_shared_examples.rb index 0fd67531c3b..8044b061ca5 100644 --- a/spec/support/prometheus/additional_metrics_shared_examples.rb +++ b/spec/support/prometheus/additional_metrics_shared_examples.rb @@ -46,7 +46,7 @@ RSpec.shared_examples 'additional metrics query' do describe 'project has Kubernetes service' do shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do let(:environment) { create(:environment, slug: 'environment-slug', project: project) } - let(:kube_namespace) { project.deployment_platform.actual_namespace } + let(:kube_namespace) { project.deployment_platform.kubernetes_namespace_for(project) } it_behaves_like 'query context containing environment slug and filter' |