From f06bb5980423e25767cf2c3b6c65047f8ae9bbb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Maty=C3=A1=C5=A1?= Date: Fri, 7 Jun 2024 01:00:11 +0200 Subject: [PATCH] Add namespace when calling pods_by_resource (#2040) The namespace is needed to be passed as a parameter when calling pods_by_resource of kubectl client. Impacted tests: single_process_type, prometheus_traffic Also adding non-default namespace to respective spec tests. Refs: #2030 Signed-off-by: Martin Matyas --- sample-cnfs/k8s-multiple-processes/cnf-testsuite.yml | 1 + sample-cnfs/sample-multiple-processes/cnf-testsuite.yml | 1 + sample-cnfs/sample-prom-pod-discovery/cnf-testsuite.yml | 1 + sample-cnfs/sample_coredns/cnf-testsuite.yml | 1 + sample-cnfs/sample_coredns_default_namespace/chart | 1 + .../sample_coredns_default_namespace/cnf-testsuite.yml | 8 ++++++++ spec/workload/configuration_spec.cr | 4 ++-- src/tasks/workload/microservice.cr | 2 +- src/tasks/workload/observability.cr | 2 +- 9 files changed, 17 insertions(+), 4 deletions(-) create mode 120000 sample-cnfs/sample_coredns_default_namespace/chart create mode 100644 sample-cnfs/sample_coredns_default_namespace/cnf-testsuite.yml diff --git a/sample-cnfs/k8s-multiple-processes/cnf-testsuite.yml b/sample-cnfs/k8s-multiple-processes/cnf-testsuite.yml index f1e4cb23b..a5025e86e 100644 --- a/sample-cnfs/k8s-multiple-processes/cnf-testsuite.yml +++ b/sample-cnfs/k8s-multiple-processes/cnf-testsuite.yml @@ -6,4 +6,5 @@ helm_repository: name: stable repo_url: https://cncf.gitlab.io/stable rolling_update_test_tag: 1.6.7 +helm_install_namespace: cnfspace allowlist_helm_chart_container_names: [node-cache, nginx, coredns, calico-node, kube-proxy, nginx-proxy] diff --git a/sample-cnfs/sample-multiple-processes/cnf-testsuite.yml b/sample-cnfs/sample-multiple-processes/cnf-testsuite.yml index 107f96e0f..e2a2df722 100644 --- a/sample-cnfs/sample-multiple-processes/cnf-testsuite.yml +++ b/sample-cnfs/sample-multiple-processes/cnf-testsuite.yml @@ -4,4 +4,5 @@ release_name: multi-proc helm_repository: name: repo_url: +helm_install_namespace: cnfspace allowlist_helm_chart_container_names: [node-cache, nginx, coredns, calico-node, kube-proxy, nginx-proxy] diff --git a/sample-cnfs/sample-prom-pod-discovery/cnf-testsuite.yml b/sample-cnfs/sample-prom-pod-discovery/cnf-testsuite.yml index e9b59cbfc..1092b4985 100644 --- a/sample-cnfs/sample-prom-pod-discovery/cnf-testsuite.yml +++ b/sample-cnfs/sample-prom-pod-discovery/cnf-testsuite.yml @@ -4,4 +4,5 @@ release_name: coredns helm_repository: name: stable repo_url: https://cncf.gitlab.io/stable +helm_install_namespace: cnfspace allowlist_helm_chart_container_names: [] diff --git a/sample-cnfs/sample_coredns/cnf-testsuite.yml b/sample-cnfs/sample_coredns/cnf-testsuite.yml index e9b59cbfc..1092b4985 100644 --- a/sample-cnfs/sample_coredns/cnf-testsuite.yml +++ b/sample-cnfs/sample_coredns/cnf-testsuite.yml @@ -4,4 +4,5 @@ release_name: coredns helm_repository: name: stable repo_url: https://cncf.gitlab.io/stable +helm_install_namespace: cnfspace allowlist_helm_chart_container_names: [] diff --git a/sample-cnfs/sample_coredns_default_namespace/chart b/sample-cnfs/sample_coredns_default_namespace/chart new file mode 120000 index 000000000..e8121a68a --- /dev/null +++ b/sample-cnfs/sample_coredns_default_namespace/chart @@ -0,0 +1 @@ +../sample_coredns/chart \ No newline at end of file diff --git a/sample-cnfs/sample_coredns_default_namespace/cnf-testsuite.yml b/sample-cnfs/sample_coredns_default_namespace/cnf-testsuite.yml new file mode 100644 index 000000000..ca8310c3f --- /dev/null +++ b/sample-cnfs/sample_coredns_default_namespace/cnf-testsuite.yml @@ -0,0 +1,8 @@ +--- +helm_directory: chart +release_name: coredns +helm_repository: + name: stable + repo_url: https://cncf.gitlab.io/stable +helm_install_namespace: default +allowlist_helm_chart_container_names: [] diff --git a/spec/workload/configuration_spec.cr b/spec/workload/configuration_spec.cr index 933be8258..3e9d4ad5c 100644 --- a/spec/workload/configuration_spec.cr +++ b/spec/workload/configuration_spec.cr @@ -353,13 +353,13 @@ describe CnfTestSuite do it "'default_namespace' should fail if a cnf creates resources in the default namespace", tags: ["default_namespace"] do begin - result = ShellCmd.run_testsuite("cnf_setup cnf-config=./sample-cnfs/sample_coredns") + result = ShellCmd.run_testsuite("cnf_setup cnf-config=./sample-cnfs/sample_coredns_default_namespace") result[:status].success?.should be_true result = ShellCmd.run_testsuite("default_namespace verbose") result[:status].success?.should be_true (/(FAILED).*(Resources are created in the default namespace)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_coredns") + result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_coredns_default_namespace") KubectlClient::Utils.wait_for_terminations() end end diff --git a/src/tasks/workload/microservice.cr b/src/tasks/workload/microservice.cr index 64745c702..1b039df51 100644 --- a/src/tasks/workload/microservice.cr +++ b/src/tasks/workload/microservice.cr @@ -312,7 +312,7 @@ task "single_process_type" do |t, args| case kind when "deployment","statefulset","pod","replicaset", "daemonset" resource_yaml = KubectlClient::Get.resource(resource[:kind], resource[:name], resource[:namespace]) - pods = KubectlClient::Get.pods_by_resource(resource_yaml) + pods = KubectlClient::Get.pods_by_resource(resource_yaml, resource[:namespace]) containers = KubectlClient::Get.resource_containers(kind, resource[:name], resource[:namespace]) pods.map do |pod| pod_name = pod.dig("metadata", "name") diff --git a/src/tasks/workload/observability.cr b/src/tasks/workload/observability.cr index a63602a70..f12c1c395 100644 --- a/src/tasks/workload/observability.cr +++ b/src/tasks/workload/observability.cr @@ -96,7 +96,7 @@ task "prometheus_traffic" do |t, args| prom_cnf_match = CNFManager.workload_resource_test(args, config) do |resource_name, container, initialized| ip_match = false resource = KubectlClient::Get.resource(resource_name[:kind], resource_name[:name], resource_name[:namespace]) - pods = KubectlClient::Get.pods_by_resource(resource) + pods = KubectlClient::Get.pods_by_resource(resource, resource_name[:namespace]) pods.each do |pod| pod_ips = pod.dig("status", "podIPs") Log.info { "pod_ips: #{pod_ips}"}