Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
Fix duplicate results (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
genevieveluyt authored Jul 21, 2020
1 parent 42c0a10 commit a528f5a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func init() {
RootCmd.PersistentFlags().StringVarP(&rootConfig.kubeConfig, "kubeconfig", "c", "", "Path to local Kubernetes config file. Only used in local mode (default is $HOME/.kube/config)")
RootCmd.PersistentFlags().StringVarP(&rootConfig.minSeverity, "minseverity", "m", "INFO", "Set the lowest severity level to report (one of \"ERROR\", \"WARN\", \"INFO\")")
RootCmd.PersistentFlags().BoolVarP(&rootConfig.json, "json", "j", false, "Output audit results in JSON")
RootCmd.PersistentFlags().StringVarP(&rootConfig.namespace, "namespace", "n", apiv1.NamespaceAll, "Only audit resources in the specified namespace. Only used in cluster mode.")
RootCmd.PersistentFlags().StringVarP(&rootConfig.namespace, "namespace", "n", apiv1.NamespaceAll, "Only audit resources in the specified namespace. Not currently supported in manifest mode.")
RootCmd.PersistentFlags().StringVarP(&rootConfig.manifest, "manifest", "f", "", "Path to the yaml configuration to audit. Only used in manifest mode.")
}

Expand Down
7 changes: 2 additions & 5 deletions internal/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ func IsRunningInCluster(client Client) bool {
type ClientOptions struct {
// Namespace filters resources by namespace. Defaults to all namespaces.
Namespace string
// ExcludeGenerated filters out generated resources (eg. pods generated by deployments). Defaults to including generated resources.
ExcludeGenerated bool
}

// GetAllResources gets all supported resources from the cluster
Expand Down Expand Up @@ -117,13 +115,12 @@ func GetAllResources(clientset kubernetes.Interface, options ClientOptions) []k8
resources = append(resources, resource.DeepCopyObject())
}

if options.ExcludeGenerated {
resources = excludeGenerated(resources)
}
resources = excludeGenerated(resources)

return resources
}

// excludeGenerated filters out generated resources (eg. pods generated by deployments)
func excludeGenerated(resources []k8stypes.Resource) []k8stypes.Resource {
var filteredResources []k8stypes.Resource
for _, resource := range resources {
Expand Down
2 changes: 1 addition & 1 deletion internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func GetReport(t *testing.T, fixtureDir, fixture string, auditables []kubeaudit.
defer deleteNamespace(t, namespace)
createNamespace(t, namespace)
applyManifest(t, fixture, namespace)
report, err = auditor.AuditLocal("", k8s.ClientOptions{Namespace: namespace, ExcludeGenerated: true})
report, err = auditor.AuditLocal("", k8s.ClientOptions{Namespace: namespace})
}

require.NoError(err)
Expand Down

0 comments on commit a528f5a

Please sign in to comment.