From 1be9da7aaeb4765773b6e686e60f1bcf825f534b Mon Sep 17 00:00:00 2001 From: Bishwa Thapa <15176360+thapabishwa@users.noreply.github.com> Date: Sun, 27 Aug 2023 13:23:45 +0545 Subject: [PATCH] feat: scan K8s Resources Kind with --all-namespaces (#5043) --- pkg/k8s/commands/resource.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/k8s/commands/resource.go b/pkg/k8s/commands/resource.go index c6568a1480..cc6f36397f 100644 --- a/pkg/k8s/commands/resource.go +++ b/pkg/k8s/commands/resource.go @@ -21,15 +21,20 @@ func resourceRun(ctx context.Context, args []string, opts flag.Options, cluster return err } - trivyk8s := trivyk8s.New(cluster, log.Logger).Namespace(getNamespace(opts, cluster.GetCurrentNamespace())) runner := newRunner(opts, cluster.GetCurrentContext()) + var trivyk trivyk8s.TrivyK8S + if opts.AllNamespaces { + trivyk = trivyk8s.New(cluster, log.Logger).AllNamespaces() + } else { + trivyk = trivyk8s.New(cluster, log.Logger).Namespace(getNamespace(opts, cluster.GetCurrentNamespace())) + } if len(name) == 0 { // pods or configmaps etc if err = validateReportArguments(opts); err != nil { return err } - targets, err := trivyk8s.Resources(kind).ListArtifacts(ctx) + targets, err := trivyk.Resources(kind).ListArtifacts(ctx) if err != nil { return err } @@ -38,7 +43,7 @@ func resourceRun(ctx context.Context, args []string, opts flag.Options, cluster } // pod/NAME or pod NAME etc - artifact, err := trivyk8s.GetArtifact(ctx, kind, name) + artifact, err := trivyk.GetArtifact(ctx, kind, name) if err != nil { return err }