Commit 8a3d61ba authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix Kubernetes service specs

parent cecd2699
...@@ -116,10 +116,9 @@ class KubernetesService < DeploymentService ...@@ -116,10 +116,9 @@ class KubernetesService < DeploymentService
# short time later # short time later
def terminals(environment) def terminals(environment)
with_reactive_cache do |data| with_reactive_cache do |data|
pods = data.fetch(:pods, nil) pods = filter_by_label(data[:pods], app: environment.slug)
filter_pods(pods, app: environment.slug). terminals = pods.flat_map { |pod| terminals_for_pod(api_url, actual_namespace, pod) }
flat_map { |pod| terminals_for_pod(api_url, actual_namespace, pod) }. terminals.each { |terminal| add_terminal_auth(terminal, terminal_auth) }
each { |terminal| add_terminal_auth(terminal, terminal_auth) }
end end
end end
...@@ -168,7 +167,7 @@ class KubernetesService < DeploymentService ...@@ -168,7 +167,7 @@ class KubernetesService < DeploymentService
def read_pods def read_pods
kubeclient = build_kubeclient! kubeclient = build_kubeclient!
kubeclient.get_pods(namespace: namespace).as_json kubeclient.get_pods(namespace: actual_namespace).as_json
rescue KubeException => err rescue KubeException => err
raise err unless err.error_code == 404 raise err unless err.error_code == 404
[] []
...@@ -177,7 +176,7 @@ class KubernetesService < DeploymentService ...@@ -177,7 +176,7 @@ class KubernetesService < DeploymentService
def read_deployments def read_deployments
kubeclient = build_kubeclient!(api_path: 'apis/extensions', api_version: 'v1beta1') kubeclient = build_kubeclient!(api_path: 'apis/extensions', api_version: 'v1beta1')
kubeclient.get_deployments(namespace: namespace).as_json kubeclient.get_deployments(namespace: actual_namespace).as_json
rescue KubeException => err rescue KubeException => err
raise err unless err.error_code == 404 raise err unless err.error_code == 404
[] []
......
...@@ -7,24 +7,6 @@ describe KubernetesService, models: true, caching: true do ...@@ -7,24 +7,6 @@ describe KubernetesService, models: true, caching: true do
let(:project) { build_stubbed(:kubernetes_project) } let(:project) { build_stubbed(:kubernetes_project) }
let(:service) { project.kubernetes_service } let(:service) { project.kubernetes_service }
# We use Kubeclient to interactive with the Kubernetes API. It will
# GET /api/v1 for a list of resources the API supports. This must be stubbed
# in addition to any other HTTP requests we expect it to perform.
let(:discovery_url) { service.api_url + '/api/v1' }
let(:discovery_response) { { body: kube_discovery_body.to_json } }
let(:pods_url) { service.api_url + "/api/v1/namespaces/#{service.actual_namespace}/pods" }
let(:pods_response) { { body: kube_pods_body(kube_pod).to_json } }
def stub_kubeclient_discover
WebMock.stub_request(:get, discovery_url).to_return(discovery_response)
end
def stub_kubeclient_pods
stub_kubeclient_discover
WebMock.stub_request(:get, pods_url).to_return(pods_response)
end
describe "Associations" do describe "Associations" do
it { is_expected.to belong_to :project } it { is_expected.to belong_to :project }
end end
......
...@@ -20,14 +20,14 @@ module KubernetesHelpers ...@@ -20,14 +20,14 @@ module KubernetesHelpers
def stub_kubeclient_pods(response = nil) def stub_kubeclient_pods(response = nil)
stub_kubeclient_discover stub_kubeclient_discover
pods_url = service.api_url + "/api/v1/namespaces/#{service.namespace}/pods" pods_url = service.api_url + "/api/v1/namespaces/#{service.actual_namespace}/pods"
WebMock.stub_request(:get, pods_url).to_return(response || kube_pods_response) WebMock.stub_request(:get, pods_url).to_return(response || kube_pods_response)
end end
def stub_kubeclient_deployments(response = nil) def stub_kubeclient_deployments(response = nil)
stub_kubeclient_discover stub_kubeclient_discover
deployments_url = service.api_url + "/apis/extensions/v1beta1/namespaces/#{service.namespace}/deployments" deployments_url = service.api_url + "/apis/extensions/v1beta1/namespaces/#{service.actual_namespace}/deployments"
WebMock.stub_request(:get, deployments_url).to_return(response || kube_deployments_response) WebMock.stub_request(:get, deployments_url).to_return(response || kube_deployments_response)
end end
......
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