From 22e51a6d46643e0aee5a8c070df8c6a7d06ad1f2 Mon Sep 17 00:00:00 2001 From: chenk Date: Sat, 27 Apr 2024 18:35:22 +0300 Subject: [PATCH] feat: k8s disable node-0collector flag support Signed-off-by: chenk --- pkg/flag/kubernetes_flags.go | 19 ------------------- pkg/k8s/commands/cluster.go | 13 ------------- 2 files changed, 32 deletions(-) diff --git a/pkg/flag/kubernetes_flags.go b/pkg/flag/kubernetes_flags.go index 9a285524d57b..996317e0be4f 100644 --- a/pkg/flag/kubernetes_flags.go +++ b/pkg/flag/kubernetes_flags.go @@ -25,17 +25,6 @@ var ( ConfigName: "kubernetes.tolerations", Usage: "specify node-collector job tolerations (example: key1=value1:NoExecute,key2=value2:NoSchedule)", } -<<<<<<< HEAD - DisableNodeCollector = Flag[bool]{ - Name: "disable-node-collector", - ConfigName: "kubernetes.disableNodeCollector", -======= - AllNamespaces = Flag[bool]{ - Name: "all-namespaces", - ConfigName: "kubernetes.all.namespaces", - Shorthand: "A", - Usage: "fetch resources from all cluster namespaces", - } DisableNodeCollector = Flag[bool]{ Name: "disable-node-collector", ConfigName: "kubernetes.disableNodeCollector", @@ -138,10 +127,6 @@ func NewK8sFlagGroup() *K8sFlagGroup { K8sVersion: K8sVersionFlag.Clone(), Tolerations: TolerationsFlag.Clone(), DisableNodeCollector: DisableNodeCollector.Clone(), -<<<<<<< HEAD -======= - AllNamespaces: AllNamespaces.Clone(), ->>>>>>> 660c113f6 (feat: change flag name to disable-node-collector) NodeCollectorNamespace: NodeCollectorNamespace.Clone(), ExcludeOwned: ExcludeOwned.Clone(), ExcludeNodes: ExcludeNodes.Clone(), @@ -209,10 +194,6 @@ func (f *K8sFlagGroup) ToOptions() (K8sOptions, error) { K8sVersion: f.K8sVersion.Value(), Tolerations: tolerations, DisableNodeCollector: f.DisableNodeCollector.Value(), -<<<<<<< HEAD -======= - AllNamespaces: f.AllNamespaces.Value(), ->>>>>>> 660c113f6 (feat: change flag name to disable-node-collector) NodeCollectorNamespace: f.NodeCollectorNamespace.Value(), ExcludeOwned: f.ExcludeOwned.Value(), ExcludeNodes: exludeNodeLabels, diff --git a/pkg/k8s/commands/cluster.go b/pkg/k8s/commands/cluster.go index 7e8fdb05ca91..68b2aa9da507 100644 --- a/pkg/k8s/commands/cluster.go +++ b/pkg/k8s/commands/cluster.go @@ -3,11 +3,7 @@ package commands import ( "context" -<<<<<<< HEAD - "golang.org/x/exp/slices" -======= "go.uber.org/zap" ->>>>>>> 660c113f6 (feat: change flag name to disable-node-collector) "golang.org/x/xerrors" k8sArtifacts "github.com/aquasecurity/trivy-kubernetes/pkg/artifacts" @@ -19,11 +15,8 @@ import ( // clusterRun runs scan on kubernetes cluster func clusterRun(ctx context.Context, opts flag.Options, cluster k8s.Cluster) error { -<<<<<<< HEAD -======= // TODO: replace with log.Logger logger, _ := zap.NewProduction() ->>>>>>> 660c113f6 (feat: change flag name to disable-node-collector) if err := validateReportArguments(opts); err != nil { return err } @@ -36,7 +29,6 @@ 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 k8sOpts := []trivyk8s.K8sOption{ trivyk8s.WithExcludeNamespaces(opts.ExcludeNamespaces), trivyk8s.WithIncludeNamespaces(opts.IncludeNamespaces), @@ -46,11 +38,6 @@ func clusterRun(ctx context.Context, opts flag.Options, cluster k8s.Cluster) err } if opts.Scanners.AnyEnabled(types.MisconfigScanner) && !opts.DisableNodeCollector { artifacts, err = trivyk8s.New(cluster, k8sOpts...).ListArtifactAndNodeInfo(ctx, -======= - - if opts.Scanners.AnyEnabled(types.MisconfigScanner) && !opts.DisableNodeCollector { - artifacts, err = trivyk8s.New(cluster, logger.Sugar(), trivyk8s.WithExcludeOwned(opts.ExcludeOwned)).ListArtifactAndNodeInfo(ctx, ->>>>>>> 660c113f6 (feat: change flag name to disable-node-collector) trivyk8s.WithScanJobNamespace(opts.NodeCollectorNamespace), trivyk8s.WithIgnoreLabels(opts.ExcludeNodes), trivyk8s.WithScanJobImageRef(opts.NodeCollectorImageRef),