diff options
author | rpereira2 <rpereira@gitlab.com> | 2019-09-06 19:12:08 +0530 |
---|---|---|
committer | rpereira2 <rpereira@gitlab.com> | 2019-09-09 17:30:50 +0530 |
commit | 8f1114ea01aab15a3a94ddea52dcb466b9c7c715 (patch) | |
tree | 910f97bd1dbb77ba637ea90ed326def9c362a42e | |
parent | 7f5eea27991c8892faceae31812d432efbec1925 (diff) | |
download | gitlab-ce-12819-fix-pod-logs-bug.tar.gz |
Include container name in kube pod_logs API call12819-fix-pod-logs-bug
- 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.
-rw-r--r-- | spec/support/helpers/kubernetes_helpers.rb | 27 |
1 files 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 |