From 8b5b731df1493b02a103629cb295928be104a742 Mon Sep 17 00:00:00 2001 From: Daniel Areste Hernandez Date: Mon, 14 Oct 2024 10:18:50 +0200 Subject: [PATCH] fix hardcoded container name for nic jobs --- pkg/jobs/nic_job_list.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/pkg/jobs/nic_job_list.go b/pkg/jobs/nic_job_list.go index 91b4437..4fd5c02 100644 --- a/pkg/jobs/nic_job_list.go +++ b/pkg/jobs/nic_job_list.go @@ -22,6 +22,7 @@ import ( "bytes" "context" "encoding/json" + "fmt" "github.com/nginxinc/nginx-k8s-supportpkg/pkg/crds" "github.com/nginxinc/nginx-k8s-supportpkg/pkg/data_collector" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -45,12 +46,16 @@ func NICJobList() []Job { } else { for _, pod := range pods.Items { if strings.Contains(pod.Name, "ingress") { - res, err := dc.PodExecutor(namespace, pod.Name, "nginx-ingress", command, ctx) - if err != nil { - jobResult.Error = err - dc.Logger.Printf("\tCommand execution %s failed for pod %s in namespace %s: %v\n", command, pod.Name, namespace, err) - } else { - jobResult.Files[filepath.Join(dc.BaseDir, "exec", namespace, pod.Name+"__nginx-ingress-version.txt")] = res + for _, container := range pod.Spec.Containers { + + res, err := dc.PodExecutor(namespace, pod.Name, container.Name, command, ctx) + if err != nil { + jobResult.Error = err + dc.Logger.Printf("\tCommand execution %s failed for pod %s in namespace %s: %v\n", command, pod.Name, namespace, err) + } else { + fileName := fmt.Sprintf("%s__%s__nginx-ingress-version.txt", pod.Name, container.Name) + jobResult.Files[filepath.Join(dc.BaseDir, "exec", namespace, fileName)] = res + } } } } @@ -72,12 +77,15 @@ func NICJobList() []Job { } else { for _, pod := range pods.Items { if strings.Contains(pod.Name, "ingress") { - res, err := dc.PodExecutor(namespace, pod.Name, "nginx-ingress", command, ctx) - if err != nil { - jobResult.Error = err - dc.Logger.Printf("\tCommand execution %s failed for pod %s in namespace %s: %v\n", command, pod.Name, namespace, err) - } else { - jobResult.Files[filepath.Join(dc.BaseDir, "exec", namespace, pod.Name+"__nginx-t.txt")] = res + for _, container := range pod.Spec.Containers { + res, err := dc.PodExecutor(namespace, pod.Name, container.Name, command, ctx) + if err != nil { + jobResult.Error = err + dc.Logger.Printf("\tCommand execution %s failed for pod %s in namespace %s: %v\n", command, pod.Name, namespace, err) + } else { + fileName := fmt.Sprintf("%s__%s__nginx-t.txt", pod.Name, container.Name) + jobResult.Files[filepath.Join(dc.BaseDir, "exec", namespace, fileName)] = res + } } } }