fix: k8s all-namespaces support (#4096)

This commit is contained in:
chenk
2023-04-23 20:08:37 +03:00
committed by GitHub
parent bd0c60364a
commit 107752df65
5 changed files with 23 additions and 6 deletions

View File

@@ -16,10 +16,14 @@ func namespaceRun(ctx context.Context, opts flag.Options, cluster k8s.Cluster) e
if err := validateReportArguments(opts); err != nil {
return err
}
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()))
}
trivyk8s := trivyk8s.New(cluster, log.Logger).Namespace(getNamespace(opts, cluster.GetCurrentNamespace()))
artifacts, err := trivyk8s.ListArtifacts(ctx)
artifacts, err := trivyk.ListArtifacts(ctx)
if err != nil {
return xerrors.Errorf("get k8s artifacts error: %w", err)
}