From 8f39d120b2215cd1b3117d676a30dd94f969bced Mon Sep 17 00:00:00 2001 From: Madhu RAJAGOPAL Date: Thu, 9 Oct 2025 10:02:07 +1300 Subject: [PATCH] fix: Run exec commands only on container that is nginx-ingress --- pkg/jobs/nic_job_list.go | 72 ++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/pkg/jobs/nic_job_list.go b/pkg/jobs/nic_job_list.go index 3ea2a71..4538191 100644 --- a/pkg/jobs/nic_job_list.go +++ b/pkg/jobs/nic_job_list.go @@ -23,12 +23,13 @@ import ( "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" "path/filepath" "strings" "time" + + "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" ) func NICJobList() []Job { @@ -47,14 +48,15 @@ func NICJobList() []Job { for _, pod := range pods.Items { if strings.Contains(pod.Name, "ingress") { 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 + if container.Name == "nginx-ingress" { + 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 + } } } } @@ -78,13 +80,15 @@ func NICJobList() []Job { for _, pod := range pods.Items { if strings.Contains(pod.Name, "ingress") { 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 + if container.Name == "nginx-ingress" { + 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 + } } } } @@ -108,13 +112,15 @@ func NICJobList() []Job { for _, pod := range pods.Items { if strings.Contains(pod.Name, "ingress") { 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-agent.conf", pod.Name, container.Name) - jobResult.Files[filepath.Join(dc.BaseDir, "exec", namespace, fileName)] = res + if container.Name == "nginx-ingress" { + 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-agent.conf", pod.Name, container.Name) + jobResult.Files[filepath.Join(dc.BaseDir, "exec", namespace, fileName)] = res + } } } } @@ -138,13 +144,15 @@ func NICJobList() []Job { for _, pod := range pods.Items { if strings.Contains(pod.Name, "ingress") { 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-agent-version.txt", pod.Name, container.Name) - jobResult.Files[filepath.Join(dc.BaseDir, "exec", namespace, fileName)] = res + if container.Name == "nginx-ingress" { + 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-agent-version.txt", pod.Name, container.Name) + jobResult.Files[filepath.Join(dc.BaseDir, "exec", namespace, fileName)] = res + } } } }