Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/kor/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var allCmd = &cobra.Command{
}

func init() {
allCmd.Flags().BoolVar(&opts.Namespaced, "namespaced", true, "If false, non-namespaced resources will be returned, otherwise returning namespaced resources by default. If not used, both are returned")
addGroupByFlag(allCmd)
addNamespacedFlag(allCmd)
rootCmd.AddCommand(allCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/clusterrolebindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ var clusterRoleBindingCmd = &cobra.Command{
}

func init() {
addGroupByFlag(clusterRoleBindingCmd)
rootCmd.AddCommand(clusterRoleBindingCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/clusterroles.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ var clusterRoleCmd = &cobra.Command{
}

func init() {
addGroupByFlag(clusterRoleCmd)
rootCmd.AddCommand(clusterRoleCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ var configmapCmd = &cobra.Command{
}

func init() {
addGroupByFlag(configmapCmd)
rootCmd.AddCommand(configmapCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ var crdCmd = &cobra.Command{
}

func init() {
addGroupByFlag(crdCmd)
rootCmd.AddCommand(crdCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/daemonsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ var dsCmd = &cobra.Command{
}

func init() {
addGroupByFlag(dsCmd)
rootCmd.AddCommand(dsCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ var deployCmd = &cobra.Command{
}

func init() {
addGroupByFlag(deployCmd)
rootCmd.AddCommand(deployCmd)
}
4 changes: 2 additions & 2 deletions cmd/kor/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var exporterCmd = &cobra.Command{
}

func init() {
exporterCmd.Flags().StringSliceVarP(&resourceList, "resources", "r", nil, "Comma-separated list of resources to monitor (e.g., deployment,service)")
exporterCmd.Flags().BoolVar(&opts.Namespaced, "namespaced", true, "If false, non-namespaced resources will be returned, otherwise returning namespaced resources by default. If not used, both are returned")
addNamespacedFlag(exporterCmd)
addResourcesFlag(exporterCmd)
rootCmd.AddCommand(exporterCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/finalizers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ var finalizerCmd = &cobra.Command{
}

func init() {
addGroupByFlag(finalizerCmd)
rootCmd.AddCommand(finalizerCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/hpas.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ var hpaCmd = &cobra.Command{
}

func init() {
addGroupByFlag(hpaCmd)
rootCmd.AddCommand(hpaCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/ingresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ var ingressCmd = &cobra.Command{
}

func init() {
addGroupByFlag(ingressCmd)
rootCmd.AddCommand(ingressCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ var jobCmd = &cobra.Command{
}

func init() {
addGroupByFlag(jobCmd)
rootCmd.AddCommand(jobCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/networkpolicies.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ var netpolCmd = &cobra.Command{
}

func init() {
addGroupByFlag(netpolCmd)
rootCmd.AddCommand(netpolCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/pdbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ var pdbCmd = &cobra.Command{
}

func init() {
addGroupByFlag(pdbCmd)
rootCmd.AddCommand(pdbCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ var podCmd = &cobra.Command{
}

func init() {
addGroupByFlag(podCmd)
rootCmd.AddCommand(podCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/priorityclasses.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ var priorityClassCmd = &cobra.Command{
}

func init() {
addGroupByFlag(priorityClassCmd)
rootCmd.AddCommand(priorityClassCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/pv.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ var pvCmd = &cobra.Command{
}

func init() {
addGroupByFlag(pvCmd)
rootCmd.AddCommand(pvCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ var pvcCmd = &cobra.Command{
}

func init() {
addGroupByFlag(pvcCmd)
rootCmd.AddCommand(pvcCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/replicasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ var replicaSetCmd = &cobra.Command{
}

func init() {
addGroupByFlag(replicaSetCmd)
rootCmd.AddCommand(replicaSetCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/rolebindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ var roleBindingCmd = &cobra.Command{
}

func init() {
addGroupByFlag(roleBindingCmd)
rootCmd.AddCommand(roleBindingCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ var roleCmd = &cobra.Command{
}

func init() {
addGroupByFlag(roleCmd)
rootCmd.AddCommand(roleCmd)
}
14 changes: 13 additions & 1 deletion cmd/kor/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func init() {
initFlags()
initViper()
addFilterOptionsFlag(rootCmd, filterOptions)
addGroupByFlag(rootCmd)
}

func initKindsList() {
Expand All @@ -83,7 +84,6 @@ func initFlags() {
rootCmd.PersistentFlags().BoolVar(&opts.DeleteFlag, "delete", false, "Delete unused resources")
rootCmd.PersistentFlags().BoolVar(&opts.NoInteractive, "no-interactive", false, "Do not prompt for confirmation when deleting resources. Be careful when using this flag!")
rootCmd.PersistentFlags().BoolVarP(&opts.Verbose, "verbose", "v", false, "Verbose output (print empty namespaces)")
rootCmd.PersistentFlags().StringVar(&opts.GroupBy, "group-by", "namespace", "Group output by (namespace, resource)")
rootCmd.PersistentFlags().BoolVar(&opts.ShowReason, "show-reason", false, "Print reason resource is considered unused")
}

Expand Down Expand Up @@ -125,6 +125,18 @@ func Execute() {
}
}

func addGroupByFlag(cmd *cobra.Command) {
cmd.Flags().StringVar(&opts.GroupBy, "group-by", "namespace", "Group output by (namespace, resource)")
}

func addNamespacedFlag(cmd *cobra.Command) {
cmd.Flags().BoolVar(&opts.Namespaced, "namespaced", true, "If false, non-namespaced resources will be returned, otherwise returning namespaced resources by default. If not used, both are returned")
}

func addResourcesFlag(cmd *cobra.Command) {
cmd.Flags().StringSliceVarP(&resourceList, "resources", "r", nil, "Comma-separated list of resources to monitor (e.g., deployment,service)")
}

func addFilterOptionsFlag(cmd *cobra.Command, opts *filters.Options) {
cmd.PersistentFlags().StringSliceVarP(&opts.ExcludeLabels, "exclude-labels", "l", opts.ExcludeLabels, "Selector to filter out, Example: --exclude-labels key1=value1,key2=value2. If --include-labels is set, --exclude-labels will be ignored")
cmd.PersistentFlags().StringVar(&opts.NewerThan, "newer-than", opts.NewerThan, "The maximum age of the resources to be considered unused. This flag cannot be used together with older-than flag. Example: --newer-than=1h2m")
Expand Down
1 change: 1 addition & 0 deletions cmd/kor/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ var secretCmd = &cobra.Command{
}

func init() {
addGroupByFlag(secretCmd)
rootCmd.AddCommand(secretCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/serviceaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ var serviceAccountCmd = &cobra.Command{
}

func init() {
addGroupByFlag(serviceAccountCmd)
rootCmd.AddCommand(serviceAccountCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ var serviceCmd = &cobra.Command{
}

func init() {
addGroupByFlag(serviceCmd)
rootCmd.AddCommand(serviceCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/statefulsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ var stsCmd = &cobra.Command{
}

func init() {
addGroupByFlag(stsCmd)
rootCmd.AddCommand(stsCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/storageclasses.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ var scCmd = &cobra.Command{
}

func init() {
addGroupByFlag(scCmd)
rootCmd.AddCommand(scCmd)
}
1 change: 1 addition & 0 deletions cmd/kor/volumeattachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ var volumeAttachmentCmd = &cobra.Command{
}

func init() {
addGroupByFlag(volumeAttachmentCmd)
rootCmd.AddCommand(volumeAttachmentCmd)
}