Skip to content

Commit

Permalink
feat: scan K8s Resources Kind with --all-namespaces (#5043)
Browse files Browse the repository at this point in the history
  • Loading branch information
thapabishwa authored Aug 27, 2023
1 parent 0e17d0b commit 1be9da7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/k8s/commands/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 1be9da7

Please sign in to comment.