From 8f1114ea01aab15a3a94ddea52dcb466b9c7c715 Mon Sep 17 00:00:00 2001 From: rpereira2 Date: Fri, 6 Sep 2019 19:12:08 +0530 Subject: Include container name in kube pod_logs API call - When a pod contains more than one container, the container name has to be included in the pod_logs API call otherwise the Kubernetes API returns 400. - Also allow our logs API to take a container_name param which can be used to choose which container's logs should be returned. --- spec/support/helpers/kubernetes_helpers.rb | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/spec/support/helpers/kubernetes_helpers.rb b/spec/support/helpers/kubernetes_helpers.rb index 538a5b8ef3c..36391543768 100644 --- a/spec/support/helpers/kubernetes_helpers.rb +++ b/spec/support/helpers/kubernetes_helpers.rb @@ -11,6 +11,10 @@ module KubernetesHelpers kube_response(kube_pods_body) end + def kube_pod_response + kube_response(kube_pod) + end + def kube_logs_response kube_response(kube_logs_body) end @@ -63,11 +67,30 @@ module KubernetesHelpers WebMock.stub_request(:get, pods_url).to_return(response || kube_pods_response) end - def stub_kubeclient_logs(pod_name, namespace, status: nil) + def stub_kubeclient_pod_details(pod, namespace, status: nil) stub_kubeclient_discover(service.api_url) - logs_url = service.api_url + "/api/v1/namespaces/#{namespace}/pods/#{pod_name}/log?tailLines=#{Clusters::Platforms::Kubernetes::LOGS_LIMIT}" + + pod_url = service.api_url + "/api/v1/namespaces/#{namespace}/pods/#{pod}" response = { status: status } if status + WebMock.stub_request(:get, pod_url).to_return(response || kube_pod_response) + end + + def stub_kubeclient_logs(pod_name, namespace, container: nil, status: nil, message: nil) + stub_kubeclient_discover(service.api_url) + + if container + container_query_param = "container=#{container}&" + end + + logs_url = service.api_url + "/api/v1/namespaces/#{namespace}/pods/#{pod_name}" \ + "/log?#{container_query_param}tailLines=#{Clusters::Platforms::Kubernetes::LOGS_LIMIT}" + + if status + response = { status: status } + response[:body] = { message: message }.to_json if message + end + WebMock.stub_request(:get, logs_url).to_return(response || kube_logs_response) end -- cgit v1.2.1