Skip to content

Commit

Permalink
Add namespace when calling pods_by_resource (#2040)
Browse files Browse the repository at this point in the history
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 <martin.matyas@tietoevry.com>
  • Loading branch information
martin-mat authored Jun 6, 2024
1 parent 5e226f4 commit f06bb59
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions sample-cnfs/k8s-multiple-processes/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
1 change: 1 addition & 0 deletions sample-cnfs/sample-multiple-processes/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
1 change: 1 addition & 0 deletions sample-cnfs/sample-prom-pod-discovery/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
1 change: 1 addition & 0 deletions sample-cnfs/sample_coredns/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
1 change: 1 addition & 0 deletions sample-cnfs/sample_coredns_default_namespace/chart
Original file line number Diff line number Diff line change
@@ -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: []
4 changes: 2 additions & 2 deletions spec/workload/configuration_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/workload/microservice.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/workload/observability.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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}"}
Expand Down

0 comments on commit f06bb59

Please sign in to comment.