From 717b743cd8305b9a1069415a58e91e21c17dd506 Mon Sep 17 00:00:00 2001 From: Matheus Moraes Date: Tue, 25 Jun 2024 09:32:45 -0300 Subject: [PATCH] fix(k8s): skip empty image pull secrets (#362) --- pkg/k8s/k8s.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/k8s/k8s.go b/pkg/k8s/k8s.go index 340d11f..6938b85 100644 --- a/pkg/k8s/k8s.go +++ b/pkg/k8s/k8s.go @@ -3,6 +3,8 @@ package k8s import ( "context" "fmt" + "log/slog" + "strings" "github.com/aquasecurity/trivy-kubernetes/pkg/bom" "github.com/aquasecurity/trivy-kubernetes/pkg/k8s/docker" @@ -23,8 +25,6 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" "k8s.io/utils/strings/slices" - "log/slog" - "strings" ) var ( @@ -712,6 +712,9 @@ func (r *cluster) ListByLocalObjectReferences(ctx context.Context, refs []corev1 secrets := make([]*corev1.Secret, 0) for _, secretRef := range refs { + if secretRef.Name == "" { + continue + } secret, err := r.clientset.CoreV1().Secrets(ns).Get(ctx, secretRef.Name, metav1.GetOptions{}) if err != nil { if k8sapierror.IsNotFound(err) || k8sapierror.IsForbidden(err) {