BREAKING: support exclude kinds/namespaces and include kinds/namespaces (#6323)

Signed-off-by: chenk <hen.keinan@gmail.com>
This commit is contained in:
chenk
2024-04-27 17:30:17 +03:00
committed by GitHub
parent 2d090ef2df
commit 060d0bb641
12 changed files with 129 additions and 407 deletions

View File

@@ -934,22 +934,21 @@ func NewKubernetesCommand(globalFlags *flag.GlobalFlagGroup) *cobra.Command {
VulnerabilityFlagGroup: flag.NewVulnerabilityFlagGroup(),
}
cmd := &cobra.Command{
Use: "kubernetes [flags] { cluster | all | specific resources like kubectl. eg: pods, pod/NAME }",
Use: "kubernetes [flags] [CONTEXT]",
Aliases: []string{"k8s"},
GroupID: groupScanning,
Short: "[EXPERIMENTAL] Scan kubernetes cluster",
Long: `Default context in kube configuration will be used unless specified`,
Example: ` # cluster scanning
$ trivy k8s --report summary cluster
$ trivy k8s --report summary
# namespace scanning:
$ trivy k8s -n kube-system --report summary all
# cluster scanning with specific namespace:
$ trivy k8s --include-namespaces kube-system --report summary
# resources scanning:
$ trivy k8s --report=summary deploy
$ trivy k8s --namespace=kube-system --report=summary deploy,configmaps
# resource scanning:
$ trivy k8s deployment/orion
# cluster with specific context:
$ trivy k8s kind-kind --report summary
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if err := k8sFlags.Bind(cmd); err != nil {
@@ -1236,7 +1235,7 @@ func validateArgs(cmd *cobra.Command, args []string) error {
return nil
}
if len(args) == 0 && viper.GetString(flag.InputFlag.ConfigName) == "" {
if len(args) == 0 && viper.GetString(flag.InputFlag.ConfigName) == "" && cmd.Name() != "kubernetes" {
if err := cmd.Help(); err != nil {
return err
}