Skip to content

Commit

Permalink
feat: change flag name to disable-node-collector
Browse files Browse the repository at this point in the history
Signed-off-by: chenk <[email protected]>
  • Loading branch information
chen-keinan committed Apr 15, 2024
1 parent 7e8c80d commit 660c113
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
16 changes: 8 additions & 8 deletions pkg/flag/kubernetes_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ var (
Shorthand: "A",
Usage: "fetch resources from all cluster namespaces",
}
NonIntrusive = Flag[bool]{
Name: "non-intrusive",
ConfigName: "kubernetes.non.intrusive",
DisableNodeCollector = Flag[bool]{
Name: "disable-node-collector",
ConfigName: "kubernetes.disable.node.collector",
Usage: "When the flag is activated, the node-collector job will not be executed, thus skipping misconfiguration findings on the node.",
}
NodeCollectorNamespace = Flag[string]{
Expand Down Expand Up @@ -92,7 +92,7 @@ type K8sFlagGroup struct {
KubeConfig *Flag[string]
K8sVersion *Flag[string]
Tolerations *Flag[[]string]
NonIntrusive *Flag[bool]
DisableNodeCollector *Flag[bool]
NodeCollectorImageRef *Flag[string]
AllNamespaces *Flag[bool]
NodeCollectorNamespace *Flag[string]
Expand All @@ -112,7 +112,7 @@ type K8sOptions struct {
AllNamespaces bool
NodeCollectorNamespace string
ExcludeOwned bool
NonIntrusive bool
DisableNodeCollector bool
ExcludeNodes map[string]string
QPS float32
Burst int
Expand All @@ -125,7 +125,7 @@ func NewK8sFlagGroup() *K8sFlagGroup {
KubeConfig: KubeConfigFlag.Clone(),
K8sVersion: K8sVersionFlag.Clone(),
Tolerations: TolerationsFlag.Clone(),
NonIntrusive: NonIntrusive.Clone(),
DisableNodeCollector: DisableNodeCollector.Clone(),
AllNamespaces: AllNamespaces.Clone(),
NodeCollectorNamespace: NodeCollectorNamespace.Clone(),
ExcludeOwned: ExcludeOwned.Clone(),
Expand All @@ -146,7 +146,7 @@ func (f *K8sFlagGroup) Flags() []Flagger {
f.Namespace,
f.KubeConfig,
f.K8sVersion,
f.NonIntrusive,
f.DisableNodeCollector,
f.Tolerations,
f.AllNamespaces,
f.NodeCollectorNamespace,
Expand Down Expand Up @@ -184,7 +184,7 @@ func (f *K8sFlagGroup) ToOptions() (K8sOptions, error) {
KubeConfig: f.KubeConfig.Value(),
K8sVersion: f.K8sVersion.Value(),
Tolerations: tolerations,
NonIntrusive: f.NonIntrusive.Value(),
DisableNodeCollector: f.DisableNodeCollector.Value(),
AllNamespaces: f.AllNamespaces.Value(),
NodeCollectorNamespace: f.NodeCollectorNamespace.Value(),
ExcludeOwned: f.ExcludeOwned.Value(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/flag/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (o *Options) Align() {

// Vulnerability scanning is disabled by default for CycloneDX.
if o.Format == types.FormatCycloneDX && !viper.IsSet(ScannersFlag.ConfigName) {
log.Logger.Info(`"--format cyclonedx" disables security scanning. Specify "--scanners vuln" explicitly if you want to include vulnerabilities in the CycloneDX report.`)
log.Info(`"--format cyclonedx" disables security scanning. Specify "--scanners vuln" explicitly if you want to include vulnerabilities in the CycloneDX report.`)
o.Scanners = nil
}
}
Expand Down
16 changes: 5 additions & 11 deletions pkg/k8s/commands/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

"go.uber.org/zap"
"golang.org/x/exp/slices"
"golang.org/x/xerrors"

k8sArtifacts "github.com/aquasecurity/trivy-kubernetes/pkg/artifacts"
Expand All @@ -18,7 +17,6 @@ import (
func clusterRun(ctx context.Context, opts flag.Options, cluster k8s.Cluster) error {
// TODO: replace with log.Logger
logger, _ := zap.NewProduction()

if err := validateReportArguments(opts); err != nil {
return err
}
Expand All @@ -31,13 +29,9 @@ func clusterRun(ctx context.Context, opts flag.Options, cluster k8s.Cluster) err
return xerrors.Errorf("get k8s artifacts with node info error: %w", err)
}
case types.FormatJSON, types.FormatTable:
<<<<<<< HEAD
if opts.Scanners.AnyEnabled(types.MisconfigScanner) && !opts.SkipIntrusive {

if opts.Scanners.AnyEnabled(types.MisconfigScanner) && !opts.DisableNodeCollector {
artifacts, err = trivyk8s.New(cluster, logger.Sugar(), trivyk8s.WithExcludeOwned(opts.ExcludeOwned)).ListArtifactAndNodeInfo(ctx,
=======
if opts.Scanners.AnyEnabled(types.MisconfigScanner) && !opts.NonIntrusive {
artifacts, err = trivyk8s.New(cluster, log.Logger, trivyk8s.WithExcludeOwned(opts.ExcludeOwned)).ListArtifactAndNodeInfo(ctx,
>>>>>>> 1d05c3394 (feat: change flag name from skip-intrusive to non-intrusive)
trivyk8s.WithScanJobNamespace(opts.NodeCollectorNamespace),
trivyk8s.WithIgnoreLabels(opts.ExcludeNodes),
trivyk8s.WithScanJobImageRef(opts.NodeCollectorImageRef),
Expand All @@ -55,9 +49,9 @@ func clusterRun(ctx context.Context, opts flag.Options, cluster k8s.Cluster) err
return xerrors.Errorf(`unknown format %q. Use "json" or "table" or "cyclonedx"`, opts.Format)
}

if !opts.NonIntrusive && !opts.Quiet {
log.Logger.Info("Node scanning is enabled")
log.Logger.Info("If you want to disable Node scanning via an in-cluster Job, please try '--non-intrusive' to disable the Node-Collector job.")
if !opts.DisableNodeCollector && !opts.Quiet {
logger.Sugar().Info("Node scanning is enabled")
logger.Sugar().Info("If you want to disable Node scanning via an in-cluster Job, please try '--disable-node-collector' to disable the Node-Collector job.")
}
runner := newRunner(opts, cluster.GetCurrentContext())
return runner.run(ctx, artifacts)
Expand Down

0 comments on commit 660c113

Please sign in to comment.