Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package kor for openSUSE:Factory checked in at 2023-11-14 21:43:33 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/kor (Old) and /work/SRC/openSUSE:Factory/.kor.new.17445 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "kor" Tue Nov 14 21:43:33 2023 rev:5 rq:1125866 version:0.2.9 Changes: -------- --- /work/SRC/openSUSE:Factory/kor/kor.changes 2023-11-13 22:25:16.913247232 +0100 +++ /work/SRC/openSUSE:Factory/.kor.new.17445/kor.changes 2023-11-14 21:43:41.798094829 +0100 @@ -1,0 +2,12 @@ +Tue Nov 14 12:09:19 UTC 2023 - ka...@b1-systems.de + +- Update to version 0.2.9: + * doc: add verbose flag (#154) + * fix: fix output banner for yaml and json (#153) + * fix incorrect example namespace flags (#152) + * fix: fix output for yaml and json, banner (#149) + * chore: add missing filters to service and SA (#148) + * fix: make verbose logs a flag (#147) + * chore: cleanup unused and remove dup (#146) + +------------------------------------------------------------------- Old: ---- kor-0.2.8.obscpio New: ---- kor-0.2.9.obscpio ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ kor.spec ++++++ --- /var/tmp/diff_new_pack.ADJpAg/_old 2023-11-14 21:43:42.502120889 +0100 +++ /var/tmp/diff_new_pack.ADJpAg/_new 2023-11-14 21:43:42.502120889 +0100 @@ -19,7 +19,7 @@ %define __arch_install_post export NO_BRP_STRIP_DEBUG=true Name: kor -Version: 0.2.8 +Version: 0.2.9 Release: 0 Summary: Tool to discover unused Kubernetes Resources License: MIT ++++++ _service ++++++ --- /var/tmp/diff_new_pack.ADJpAg/_old 2023-11-14 21:43:42.542122371 +0100 +++ /var/tmp/diff_new_pack.ADJpAg/_new 2023-11-14 21:43:42.546122518 +0100 @@ -3,7 +3,7 @@ <param name="url">https://github.com/yonahd/kor</param> <param name="scm">git</param> <param name="exclude">.git</param> - <param name="revision">v0.2.8</param> + <param name="revision">v0.2.9</param> <param name="versionformat">@PARENT_TAG@</param> <param name="changesgenerate">enable</param> <param name="versionrewrite-pattern">v(.*)</param> ++++++ _servicedata ++++++ --- /var/tmp/diff_new_pack.ADJpAg/_old 2023-11-14 21:43:42.574123555 +0100 +++ /var/tmp/diff_new_pack.ADJpAg/_new 2023-11-14 21:43:42.578123703 +0100 @@ -1,6 +1,6 @@ <servicedata> <service name="tar_scm"> <param name="url">https://github.com/yonahd/kor</param> - <param name="changesrevision">dec8161f811a3710916c3eb85d6e89272d6de0f7</param></service></servicedata> + <param name="changesrevision">4a93e141b15605a66d661979e66976c5ed7c17d9</param></service></servicedata> (No newline at EOF) ++++++ kor-0.2.8.obscpio -> kor-0.2.9.obscpio ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/README.md new/kor-0.2.9/README.md --- old/kor-0.2.8/README.md 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/README.md 2023-11-14 13:02:29.000000000 +0100 @@ -98,17 +98,18 @@ --newer-than string The maximum age of the resources to be considered unused. This flag cannot be used together with older-than flag. Example: --newer-than=1h2m --no-interactive Do not prompt for confirmation when deleting resources. Be careful using this flag! --older-than string The minimum age of the resources to be considered unused. This flag cannot be used together with newer-than flag. Example: --older-than=1h2m - --output string Output format (table, json or yaml) (default "table") + -o, --output string Output format (table, json or yaml) (default "table") --slack-auth-token string Slack auth token to send notifications to. --slack-auth-token requires --slack-channel to be set. --slack-channel string Slack channel to send notifications to. --slack-channel requires --slack-auth-token to be set. --slack-webhook-url string Slack webhook URL to send notifications to + -v, --verbose Verbose output (print empty namespaces) ``` To use a specific subcommand, run `kor [subcommand] [flags]`. ```sh -kor all --namespace my-namespace +kor all --include-namespaces my-namespace ``` For more information about each subcommand and its available flags, you can use the `--help` flag. @@ -138,7 +139,7 @@ ## Deleting Unused resources If you want to delete resources in an interactive way using Kor you can run: ```sh -kor configmap --namespace my-namespace --delete +kor configmap --include-namespaces my-namespace --delete ``` You will be prompted with: ```sh @@ -147,7 +148,7 @@ To delete with no prompt ( â ï¸ use with caution): ```sh -kor configmap --namespace my-namespace --delete --no-interactive +kor configmap --include-namespaces my-namespace --delete --no-interactive ``` ## Ignore Resources diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/charts/kor/Chart.yaml new/kor-0.2.9/charts/kor/Chart.yaml --- old/kor-0.2.8/charts/kor/Chart.yaml 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/charts/kor/Chart.yaml 2023-11-14 13:02:29.000000000 +0100 @@ -21,4 +21,4 @@ # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "0.2.7" +appVersion: "0.2.8" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/charts/kor/README.md new/kor-0.2.9/charts/kor/README.md --- old/kor-0.2.8/charts/kor/README.md 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/charts/kor/README.md 2023-11-14 13:02:29.000000000 +0100 @@ -1,6 +1,6 @@ # kor -   +   A Helm chart for Kubernetes diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/cmd/kor/all.go new/kor-0.2.9/cmd/kor/all.go --- old/kor-0.2.8/cmd/kor/all.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/cmd/kor/all.go 2023-11-14 13:02:29.000000000 +0100 @@ -5,6 +5,7 @@ "github.com/spf13/cobra" "github.com/yonahd/kor/pkg/kor" + "github.com/yonahd/kor/pkg/utils" ) var allCmd = &cobra.Command{ @@ -19,6 +20,7 @@ if response, err := kor.GetUnusedAll(includeExcludeLists, filterOptions, clientset, apiExtClient, dynamicClient, outputFormat, opts); err != nil { fmt.Println(err) } else { + utils.PrintLogo(outputFormat) fmt.Println(response) } }, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/cmd/kor/configmaps.go new/kor-0.2.9/cmd/kor/configmaps.go --- old/kor-0.2.8/cmd/kor/configmaps.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/cmd/kor/configmaps.go 2023-11-14 13:02:29.000000000 +0100 @@ -5,6 +5,7 @@ "github.com/spf13/cobra" "github.com/yonahd/kor/pkg/kor" + "github.com/yonahd/kor/pkg/utils" ) var configmapCmd = &cobra.Command{ @@ -17,6 +18,7 @@ if response, err := kor.GetUnusedConfigmaps(includeExcludeLists, filterOptions, clientset, outputFormat, opts); err != nil { fmt.Println(err) } else { + utils.PrintLogo(outputFormat) fmt.Println(response) } }, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/cmd/kor/crds.go new/kor-0.2.9/cmd/kor/crds.go --- old/kor-0.2.8/cmd/kor/crds.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/cmd/kor/crds.go 2023-11-14 13:02:29.000000000 +0100 @@ -5,6 +5,7 @@ "github.com/spf13/cobra" "github.com/yonahd/kor/pkg/kor" + "github.com/yonahd/kor/pkg/utils" ) var crdCmd = &cobra.Command{ @@ -18,6 +19,7 @@ if response, err := kor.GetUnusedCrds(apiExtClient, dynamicClient, outputFormat, opts); err != nil { fmt.Println(err) } else { + utils.PrintLogo(outputFormat) fmt.Println(response) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/cmd/kor/deployments.go new/kor-0.2.9/cmd/kor/deployments.go --- old/kor-0.2.8/cmd/kor/deployments.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/cmd/kor/deployments.go 2023-11-14 13:02:29.000000000 +0100 @@ -5,6 +5,7 @@ "github.com/spf13/cobra" "github.com/yonahd/kor/pkg/kor" + "github.com/yonahd/kor/pkg/utils" ) var deployCmd = &cobra.Command{ @@ -17,6 +18,7 @@ if response, err := kor.GetUnusedDeployments(includeExcludeLists, filterOptions, clientset, outputFormat, opts); err != nil { fmt.Println(err) } else { + utils.PrintLogo(outputFormat) fmt.Println(response) } }, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/cmd/kor/hpas.go new/kor-0.2.9/cmd/kor/hpas.go --- old/kor-0.2.8/cmd/kor/hpas.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/cmd/kor/hpas.go 2023-11-14 13:02:29.000000000 +0100 @@ -5,6 +5,7 @@ "github.com/spf13/cobra" "github.com/yonahd/kor/pkg/kor" + "github.com/yonahd/kor/pkg/utils" ) var hpaCmd = &cobra.Command{ @@ -18,6 +19,7 @@ if response, err := kor.GetUnusedHpas(includeExcludeLists, filterOptions, clientset, outputFormat, opts); err != nil { fmt.Println(err) } else { + utils.PrintLogo(outputFormat) fmt.Println(response) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/cmd/kor/ingresses.go new/kor-0.2.9/cmd/kor/ingresses.go --- old/kor-0.2.8/cmd/kor/ingresses.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/cmd/kor/ingresses.go 2023-11-14 13:02:29.000000000 +0100 @@ -5,6 +5,7 @@ "github.com/spf13/cobra" "github.com/yonahd/kor/pkg/kor" + "github.com/yonahd/kor/pkg/utils" ) var ingressCmd = &cobra.Command{ @@ -18,6 +19,7 @@ if response, err := kor.GetUnusedIngresses(includeExcludeLists, filterOptions, clientset, outputFormat, opts); err != nil { fmt.Println(err) } else { + utils.PrintLogo(outputFormat) fmt.Println(response) } }, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/cmd/kor/pdbs.go new/kor-0.2.9/cmd/kor/pdbs.go --- old/kor-0.2.8/cmd/kor/pdbs.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/cmd/kor/pdbs.go 2023-11-14 13:02:29.000000000 +0100 @@ -5,6 +5,7 @@ "github.com/spf13/cobra" "github.com/yonahd/kor/pkg/kor" + "github.com/yonahd/kor/pkg/utils" ) var pdbCmd = &cobra.Command{ @@ -18,6 +19,7 @@ if response, err := kor.GetUnusedPdbs(includeExcludeLists, filterOptions, clientset, outputFormat, opts); err != nil { fmt.Println(err) } else { + utils.PrintLogo(outputFormat) fmt.Println(response) } }, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/cmd/kor/pvc.go new/kor-0.2.9/cmd/kor/pvc.go --- old/kor-0.2.8/cmd/kor/pvc.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/cmd/kor/pvc.go 2023-11-14 13:02:29.000000000 +0100 @@ -5,6 +5,7 @@ "github.com/spf13/cobra" "github.com/yonahd/kor/pkg/kor" + "github.com/yonahd/kor/pkg/utils" ) var pvcCmd = &cobra.Command{ @@ -18,6 +19,7 @@ if response, err := kor.GetUnusedPvcs(includeExcludeLists, filterOptions, clientset, outputFormat, opts); err != nil { fmt.Println(err) } else { + utils.PrintLogo(outputFormat) fmt.Println(response) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/cmd/kor/roles.go new/kor-0.2.9/cmd/kor/roles.go --- old/kor-0.2.8/cmd/kor/roles.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/cmd/kor/roles.go 2023-11-14 13:02:29.000000000 +0100 @@ -5,6 +5,7 @@ "github.com/spf13/cobra" "github.com/yonahd/kor/pkg/kor" + "github.com/yonahd/kor/pkg/utils" ) var roleCmd = &cobra.Command{ @@ -18,6 +19,7 @@ if response, err := kor.GetUnusedRoles(includeExcludeLists, filterOptions, clientset, outputFormat, opts); err != nil { fmt.Println(err) } else { + utils.PrintLogo(outputFormat) fmt.Println(response) } }, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/cmd/kor/root.go new/kor-0.2.9/cmd/kor/root.go --- old/kor-0.2.8/cmd/kor/root.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/cmd/kor/root.go 2023-11-14 13:02:29.000000000 +0100 @@ -3,7 +3,6 @@ import ( "fmt" "os" - "strings" "github.com/spf13/cobra" "github.com/yonahd/kor/pkg/kor" @@ -18,20 +17,15 @@ Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { resourceNames := args[0] + clientset := kor.GetKubeClient(kubeconfig) + apiExtClient := kor.GetAPIExtensionsClient(kubeconfig) + dynamicClient := kor.GetDynamicClient(kubeconfig) - // Checks whether the string contains a comma, indicating that it represents a list of resources - if strings.ContainsRune(resourceNames, 44) { - clientset := kor.GetKubeClient(kubeconfig) - apiExtClient := kor.GetAPIExtensionsClient(kubeconfig) - dynamicClient := kor.GetDynamicClient(kubeconfig) - - if response, err := kor.GetUnusedMulti(includeExcludeLists, resourceNames, filterOptions, clientset, apiExtClient, dynamicClient, outputFormat, opts); err != nil { - fmt.Println(err) - } else { - fmt.Println(response) - } + if response, err := kor.GetUnusedMulti(includeExcludeLists, resourceNames, filterOptions, clientset, apiExtClient, dynamicClient, outputFormat, opts); err != nil { + fmt.Println(err) } else { - fmt.Printf("Subcommand %q was not found, try using 'kor --help' for available subcommands", args[0]) + utils.PrintLogo(outputFormat) + fmt.Println(response) } }, } @@ -45,16 +39,16 @@ ) func Execute() { - utils.PrintLogo() rootCmd.PersistentFlags().StringVarP(&kubeconfig, "kubeconfig", "k", "", "Path to kubeconfig file (optional)") rootCmd.PersistentFlags().StringVarP(&includeExcludeLists.IncludeListStr, "include-namespaces", "n", "", "Namespaces to run on, splited by comma. Example: --include-namespace ns1,ns2,ns3. ") rootCmd.PersistentFlags().StringVarP(&includeExcludeLists.ExcludeListStr, "exclude-namespaces", "e", "", "Namespaces to be excluded, splited by comma. Example: --exclude-namespace ns1,ns2,ns3. If --include-namespace is set, --exclude-namespaces will be ignored.") - rootCmd.PersistentFlags().StringVar(&outputFormat, "output", "table", "Output format (table, json or yaml)") + rootCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "table", "Output format (table, json or yaml)") rootCmd.PersistentFlags().StringVar(&opts.WebhookURL, "slack-webhook-url", "", "Slack webhook URL to send notifications to") rootCmd.PersistentFlags().StringVar(&opts.Channel, "slack-channel", "", "Slack channel to send notifications to. --slack-channel requires --slack-auth-token to be set.") rootCmd.PersistentFlags().StringVar(&opts.Token, "slack-auth-token", "", "Slack auth token to send notifications to. --slack-auth-token requires --slack-channel to be set.") 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 using this flag!") + rootCmd.PersistentFlags().BoolVarP(&opts.Verbose, "verbose", "v", false, "Verbose output (print empty namespaces)") addFilterOptionsFlag(rootCmd, filterOptions) if err := filterOptions.Validate(); err != nil { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/cmd/kor/secrets.go new/kor-0.2.9/cmd/kor/secrets.go --- old/kor-0.2.8/cmd/kor/secrets.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/cmd/kor/secrets.go 2023-11-14 13:02:29.000000000 +0100 @@ -5,6 +5,7 @@ "github.com/spf13/cobra" "github.com/yonahd/kor/pkg/kor" + "github.com/yonahd/kor/pkg/utils" ) var secretCmd = &cobra.Command{ @@ -18,6 +19,7 @@ if response, err := kor.GetUnusedSecrets(includeExcludeLists, filterOptions, clientset, outputFormat, opts); err != nil { fmt.Println(err) } else { + utils.PrintLogo(outputFormat) fmt.Println(response) } }, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/cmd/kor/serviceaccounts.go new/kor-0.2.9/cmd/kor/serviceaccounts.go --- old/kor-0.2.8/cmd/kor/serviceaccounts.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/cmd/kor/serviceaccounts.go 2023-11-14 13:02:29.000000000 +0100 @@ -5,6 +5,7 @@ "github.com/spf13/cobra" "github.com/yonahd/kor/pkg/kor" + "github.com/yonahd/kor/pkg/utils" ) var serviceAccountCmd = &cobra.Command{ @@ -15,9 +16,10 @@ Run: func(cmd *cobra.Command, args []string) { clientset := kor.GetKubeClient(kubeconfig) - if response, err := kor.GetUnusedServiceAccounts(includeExcludeLists, clientset, outputFormat, opts); err != nil { + if response, err := kor.GetUnusedServiceAccounts(includeExcludeLists, filterOptions, clientset, outputFormat, opts); err != nil { fmt.Println(err) } else { + utils.PrintLogo(outputFormat) fmt.Println(response) } }, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/cmd/kor/services.go new/kor-0.2.9/cmd/kor/services.go --- old/kor-0.2.8/cmd/kor/services.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/cmd/kor/services.go 2023-11-14 13:02:29.000000000 +0100 @@ -5,6 +5,7 @@ "github.com/spf13/cobra" "github.com/yonahd/kor/pkg/kor" + "github.com/yonahd/kor/pkg/utils" ) var serviceCmd = &cobra.Command{ @@ -15,9 +16,10 @@ Run: func(cmd *cobra.Command, args []string) { clientset := kor.GetKubeClient(kubeconfig) - if response, err := kor.GetUnusedServices(includeExcludeLists, clientset, outputFormat, opts); err != nil { + if response, err := kor.GetUnusedServices(includeExcludeLists, filterOptions, clientset, outputFormat, opts); err != nil { fmt.Println(err) } else { + utils.PrintLogo(outputFormat) fmt.Println(response) } }, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/cmd/kor/statefulsets.go new/kor-0.2.9/cmd/kor/statefulsets.go --- old/kor-0.2.8/cmd/kor/statefulsets.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/cmd/kor/statefulsets.go 2023-11-14 13:02:29.000000000 +0100 @@ -5,6 +5,7 @@ "github.com/spf13/cobra" "github.com/yonahd/kor/pkg/kor" + "github.com/yonahd/kor/pkg/utils" ) var stsCmd = &cobra.Command{ @@ -18,6 +19,7 @@ if response, err := kor.GetUnusedStatefulSets(includeExcludeLists, filterOptions, clientset, outputFormat, opts); err != nil { fmt.Println(err) } else { + utils.PrintLogo(outputFormat) fmt.Println(response) } }, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/all.go new/kor-0.2.9/pkg/kor/all.go --- old/kor-0.2.8/pkg/kor/all.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/all.go 2023-11-14 13:02:29.000000000 +0100 @@ -30,8 +30,8 @@ return namespaceCMDiff } -func getUnusedSVCs(clientset kubernetes.Interface, namespace string) ResourceDiff { - svcDiff, err := ProcessNamespaceServices(clientset, namespace) +func getUnusedSVCs(clientset kubernetes.Interface, namespace string, filterOpts *FilterOptions) ResourceDiff { + svcDiff, err := ProcessNamespaceServices(clientset, namespace, filterOpts) if err != nil { fmt.Fprintf(os.Stderr, "Failed to get %s namespace %s: %v\n", "services", namespace, err) } @@ -48,8 +48,8 @@ return namespaceSecretDiff } -func getUnusedServiceAccounts(clientset kubernetes.Interface, namespace string) ResourceDiff { - saDiff, err := processNamespaceSA(clientset, namespace) +func getUnusedServiceAccounts(clientset kubernetes.Interface, namespace string, filterOpts *FilterOptions) ResourceDiff { + saDiff, err := processNamespaceSA(clientset, namespace, filterOpts) if err != nil { fmt.Fprintf(os.Stderr, "Failed to get %s namespace %s: %v\n", "serviceaccounts", namespace, err) } @@ -139,11 +139,11 @@ var allDiffs []ResourceDiff namespaceCMDiff := getUnusedCMs(clientset, namespace, filterOpts) allDiffs = append(allDiffs, namespaceCMDiff) - namespaceSVCDiff := getUnusedSVCs(clientset, namespace) + namespaceSVCDiff := getUnusedSVCs(clientset, namespace, filterOpts) allDiffs = append(allDiffs, namespaceSVCDiff) namespaceSecretDiff := getUnusedSecrets(clientset, namespace, filterOpts) allDiffs = append(allDiffs, namespaceSecretDiff) - namespaceSADiff := getUnusedServiceAccounts(clientset, namespace) + namespaceSADiff := getUnusedServiceAccounts(clientset, namespace, filterOpts) allDiffs = append(allDiffs, namespaceSADiff) namespaceDeploymentDiff := getUnusedDeployments(clientset, namespace, filterOpts) allDiffs = append(allDiffs, namespaceDeploymentDiff) @@ -160,7 +160,7 @@ namespacePdbDiff := getUnusedPdbs(clientset, namespace, filterOpts) allDiffs = append(allDiffs, namespacePdbDiff) - output := FormatOutputAll(namespace, allDiffs) + output := FormatOutputAll(namespace, allDiffs, opts) outputBuffer.WriteString(output) outputBuffer.WriteString("\n") @@ -176,7 +176,7 @@ crdDiff := getUnusedCrds(apiExtClient, dynamicClient) allDiffs = append(allDiffs, crdDiff) - output := FormatOutputAll("", allDiffs) + output := FormatOutputAll("", allDiffs, opts) outputBuffer.WriteString(output) outputBuffer.WriteString("\n") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/confimgmaps.go new/kor-0.2.9/pkg/kor/confimgmaps.go --- old/kor-0.2.8/pkg/kor/confimgmaps.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/confimgmaps.go 2023-11-14 13:02:29.000000000 +0100 @@ -156,13 +156,15 @@ fmt.Fprintf(os.Stderr, "Failed to delete ConfigMap %s in namespace %s: %v\n", diff, namespace, err) } } - output := FormatOutput(namespace, diff, "Configmaps") - outputBuffer.WriteString(output) - outputBuffer.WriteString("\n") + output := FormatOutput(namespace, diff, "Configmaps", opts) + if output != "" { + outputBuffer.WriteString(output) + outputBuffer.WriteString("\n") - resourceMap := make(map[string][]string) - resourceMap["ConfigMap"] = diff - response[namespace] = resourceMap + resourceMap := make(map[string][]string) + resourceMap["ConfigMap"] = diff + response[namespace] = resourceMap + } } jsonResponse, err := json.MarshalIndent(response, "", " ") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/crds.go new/kor-0.2.9/pkg/kor/crds.go --- old/kor-0.2.8/pkg/kor/crds.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/crds.go 2023-11-14 13:02:29.000000000 +0100 @@ -61,13 +61,14 @@ } response[""]["Crd"] = diff } - output := FormatOutput("", diff, "Crds") + output := FormatOutput("", diff, "Crds", opts) + if output != "" { + outputBuffer.WriteString(output) + outputBuffer.WriteString("\n") - outputBuffer.WriteString(output) - outputBuffer.WriteString("\n") - - resourceMap := make(map[string][]string) - resourceMap["Crd"] = diff + resourceMap := make(map[string][]string) + resourceMap["Crd"] = diff + } jsonResponse, err := json.MarshalIndent(response, "", " ") if err != nil { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/deployments.go new/kor-0.2.9/pkg/kor/deployments.go --- old/kor-0.2.8/pkg/kor/deployments.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/deployments.go 2023-11-14 13:02:29.000000000 +0100 @@ -60,13 +60,15 @@ fmt.Fprintf(os.Stderr, "Failed to delete Deployment %s in namespace %s: %v\n", diff, namespace, err) } } - output := FormatOutput(namespace, diff, "Deployments") - outputBuffer.WriteString(output) - outputBuffer.WriteString("\n") + output := FormatOutput(namespace, diff, "Deployments", opts) + if output != "" { + outputBuffer.WriteString(output) + outputBuffer.WriteString("\n") - resourceMap := make(map[string][]string) - resourceMap["Deployments"] = diff - response[namespace] = resourceMap + resourceMap := make(map[string][]string) + resourceMap["Deployments"] = diff + response[namespace] = resourceMap + } } jsonResponse, err := json.MarshalIndent(response, "", " ") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/hpas.go new/kor-0.2.9/pkg/kor/hpas.go --- old/kor-0.2.8/pkg/kor/hpas.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/hpas.go 2023-11-14 13:02:29.000000000 +0100 @@ -107,13 +107,15 @@ fmt.Fprintf(os.Stderr, "Failed to delete HPA %s in namespace %s: %v\n", diff, namespace, err) } } - output := FormatOutput(namespace, diff, "HPAs") - outputBuffer.WriteString(output) - outputBuffer.WriteString("\n") + output := FormatOutput(namespace, diff, "HPAs", opts) + if output != "" { + outputBuffer.WriteString(output) + outputBuffer.WriteString("\n") - resourceMap := make(map[string][]string) - resourceMap["Hpa"] = diff - response[namespace] = resourceMap + resourceMap := make(map[string][]string) + resourceMap["Hpa"] = diff + response[namespace] = resourceMap + } } jsonResponse, err := json.MarshalIndent(response, "", " ") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/ingresses.go new/kor-0.2.9/pkg/kor/ingresses.go --- old/kor-0.2.8/pkg/kor/ingresses.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/ingresses.go 2023-11-14 13:02:29.000000000 +0100 @@ -120,13 +120,15 @@ fmt.Fprintf(os.Stderr, "Failed to delete Ingress %s in namespace %s: %v\n", diff, namespace, err) } } - output := FormatOutput(namespace, diff, "Ingresses") - outputBuffer.WriteString(output) - outputBuffer.WriteString("\n") + output := FormatOutput(namespace, diff, "Ingresses", opts) + if output != "" { + outputBuffer.WriteString(output) + outputBuffer.WriteString("\n") - resourceMap := make(map[string][]string) - resourceMap["Ingresses"] = diff - response[namespace] = resourceMap + resourceMap := make(map[string][]string) + resourceMap["Ingresses"] = diff + response[namespace] = resourceMap + } } jsonResponse, err := json.MarshalIndent(response, "", " ") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/kor.go new/kor-0.2.9/pkg/kor/kor.go --- old/kor-0.2.8/pkg/kor/kor.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/kor.go 2023-11-14 13:02:29.000000000 +0100 @@ -32,6 +32,7 @@ type Opts struct { DeleteFlag bool NoInteractive bool + Verbose bool WebhookURL string Channel string Token string @@ -159,9 +160,11 @@ return namespaces } -func FormatOutput(namespace string, resources []string, resourceType string) string { - if len(resources) == 0 { +func FormatOutput(namespace string, resources []string, resourceType string, opts Opts) string { + if opts.Verbose && len(resources) == 0 { return fmt.Sprintf("No unused %s found in the namespace: %s \n", resourceType, namespace) + } else if len(resources) == 0 { + return "" } var buf bytes.Buffer @@ -177,7 +180,7 @@ return fmt.Sprintf("Unused %s in Namespace: %s\n%s", resourceType, namespace, buf.String()) } -func FormatOutputAll(namespace string, allDiffs []ResourceDiff) string { +func FormatOutputAll(namespace string, allDiffs []ResourceDiff, opts Opts) string { i := 0 var buf bytes.Buffer table := tablewriter.NewWriter(&buf) @@ -199,8 +202,10 @@ } } - if allEmpty { + if opts.Verbose && allEmpty { return fmt.Sprintf("No unused resources found in the namespace: %s", namespace) + } else if allEmpty { + return "" } table.Render() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/multi.go new/kor-0.2.9/pkg/kor/multi.go --- old/kor-0.2.8/pkg/kor/multi.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/multi.go 2023-11-14 13:02:29.000000000 +0100 @@ -31,43 +31,34 @@ func retrieveNamespaceDiffs(clientset kubernetes.Interface, namespace string, resourceList []string, filterOpts *FilterOptions) []ResourceDiff { var allDiffs []ResourceDiff for _, resource := range resourceList { + var diffResult ResourceDiff switch resource { case "cm", "configmap", "configmaps": - namespaceCMDiff := getUnusedCMs(clientset, namespace, filterOpts) - allDiffs = append(allDiffs, namespaceCMDiff) + diffResult = getUnusedCMs(clientset, namespace, filterOpts) case "svc", "service", "services": - namespaceSVCDiff := getUnusedSVCs(clientset, namespace) - allDiffs = append(allDiffs, namespaceSVCDiff) + diffResult = getUnusedSVCs(clientset, namespace, filterOpts) case "scrt", "secret", "secrets": - namespaceSecretDiff := getUnusedSecrets(clientset, namespace, filterOpts) - allDiffs = append(allDiffs, namespaceSecretDiff) + diffResult = getUnusedSecrets(clientset, namespace, filterOpts) case "sa", "serviceaccount", "serviceaccounts": - namespaceSADiff := getUnusedServiceAccounts(clientset, namespace) - allDiffs = append(allDiffs, namespaceSADiff) + diffResult = getUnusedServiceAccounts(clientset, namespace, filterOpts) case "deploy", "deployment", "deployments": - namespaceDeploymentDiff := getUnusedDeployments(clientset, namespace, filterOpts) - allDiffs = append(allDiffs, namespaceDeploymentDiff) + diffResult = getUnusedDeployments(clientset, namespace, filterOpts) case "sts", "statefulset", "statefulsets": - namespaceStatefulsetDiff := getUnusedStatefulSets(clientset, namespace, filterOpts) - allDiffs = append(allDiffs, namespaceStatefulsetDiff) + diffResult = getUnusedStatefulSets(clientset, namespace, filterOpts) case "role", "roles": - namespaceRoleDiff := getUnusedRoles(clientset, namespace, filterOpts) - allDiffs = append(allDiffs, namespaceRoleDiff) + diffResult = getUnusedRoles(clientset, namespace, filterOpts) case "hpa", "horizontalpodautoscaler", "horizontalpodautoscalers": - namespaceHpaDiff := getUnusedHpas(clientset, namespace, filterOpts) - allDiffs = append(allDiffs, namespaceHpaDiff) + diffResult = getUnusedHpas(clientset, namespace, filterOpts) case "pvc", "persistentvolumeclaim", "persistentvolumeclaims": - namespacePvcDiff := getUnusedPvcs(clientset, namespace, filterOpts) - allDiffs = append(allDiffs, namespacePvcDiff) + diffResult = getUnusedPvcs(clientset, namespace, filterOpts) case "ing", "ingress", "ingresses": - namespaceIngressDiff := getUnusedIngresses(clientset, namespace, filterOpts) - allDiffs = append(allDiffs, namespaceIngressDiff) + diffResult = getUnusedIngresses(clientset, namespace, filterOpts) case "pdb", "poddisruptionbudget", "poddisruptionbudgets": - namespacePdbDiff := getUnusedPdbs(clientset, namespace, filterOpts) - allDiffs = append(allDiffs, namespacePdbDiff) + diffResult = getUnusedPdbs(clientset, namespace, filterOpts) default: fmt.Printf("resource type %q is not supported\n", resource) } + allDiffs = append(allDiffs, diffResult) } return allDiffs } @@ -83,7 +74,7 @@ crdDiff, resourceList := retrieveNoNamespaceDiff(apiExtClient, dynamicClient, outputFormat, opts, resourceList) if len(crdDiff) != 0 { - output := FormatOutputAll("", crdDiff) + output := FormatOutputAll("", crdDiff, opts) outputBuffer.WriteString(output) outputBuffer.WriteString("\n") @@ -106,15 +97,18 @@ } } - output := FormatOutputAll(namespace, allDiffs) - outputBuffer.WriteString(output) - outputBuffer.WriteString("\n") + output := FormatOutputAll(namespace, allDiffs, opts) + if output != "" { + outputBuffer.WriteString(output) + outputBuffer.WriteString("\n") - resourceMap := make(map[string][]string) - for _, diff := range allDiffs { - resourceMap[diff.resourceType] = diff.diff + resourceMap := make(map[string][]string) + for _, diff := range allDiffs { + resourceMap[diff.resourceType] = diff.diff + } + response[namespace] = resourceMap } - response[namespace] = resourceMap + } jsonResponse, err := json.MarshalIndent(response, "", " ") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/pdbs.go new/kor-0.2.9/pkg/kor/pdbs.go --- old/kor-0.2.8/pkg/kor/pdbs.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/pdbs.go 2023-11-14 13:02:29.000000000 +0100 @@ -76,13 +76,15 @@ fmt.Fprintf(os.Stderr, "Failed to delete PDB %s in namespace %s: %v\n", diff, namespace, err) } } - output := FormatOutput(namespace, diff, "PDBs") - outputBuffer.WriteString(output) - outputBuffer.WriteString("\n") + output := FormatOutput(namespace, diff, "PDBs", opts) + if output != "" { + outputBuffer.WriteString(output) + outputBuffer.WriteString("\n") - resourceMap := make(map[string][]string) - resourceMap["Pdb"] = diff - response[namespace] = resourceMap + resourceMap := make(map[string][]string) + resourceMap["Pdb"] = diff + response[namespace] = resourceMap + } } jsonResponse, err := json.MarshalIndent(response, "", " ") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/pvc.go new/kor-0.2.9/pkg/kor/pvc.go --- old/kor-0.2.8/pkg/kor/pvc.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/pvc.go 2023-11-14 13:02:29.000000000 +0100 @@ -81,13 +81,15 @@ fmt.Fprintf(os.Stderr, "Failed to delete PVC %s in namespace %s: %v\n", diff, namespace, err) } } - output := FormatOutput(namespace, diff, "PVCs") - outputBuffer.WriteString(output) - outputBuffer.WriteString("\n") + output := FormatOutput(namespace, diff, "PVCs", opts) + if output != "" { + outputBuffer.WriteString(output) + outputBuffer.WriteString("\n") - resourceMap := make(map[string][]string) - resourceMap["Pvc"] = diff - response[namespace] = resourceMap + resourceMap := make(map[string][]string) + resourceMap["Pvc"] = diff + response[namespace] = resourceMap + } } jsonResponse, err := json.MarshalIndent(response, "", " ") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/roles.go new/kor-0.2.9/pkg/kor/roles.go --- old/kor-0.2.8/pkg/kor/roles.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/roles.go 2023-11-14 13:02:29.000000000 +0100 @@ -94,13 +94,15 @@ fmt.Fprintf(os.Stderr, "Failed to delete Role %s in namespace %s: %v\n", diff, namespace, err) } } - output := FormatOutput(namespace, diff, "Roles") - outputBuffer.WriteString(output) - outputBuffer.WriteString("\n") + output := FormatOutput(namespace, diff, "Roles", opts) + if output != "" { + outputBuffer.WriteString(output) + outputBuffer.WriteString("\n") - resourceMap := make(map[string][]string) - resourceMap["Roles"] = diff - response[namespace] = resourceMap + resourceMap := make(map[string][]string) + resourceMap["Roles"] = diff + response[namespace] = resourceMap + } } jsonResponse, err := json.MarshalIndent(response, "", " ") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/secrets.go new/kor-0.2.9/pkg/kor/secrets.go --- old/kor-0.2.8/pkg/kor/secrets.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/secrets.go 2023-11-14 13:02:29.000000000 +0100 @@ -168,13 +168,15 @@ fmt.Fprintf(os.Stderr, "Failed to delete Secret %s in namespace %s: %v\n", diff, namespace, err) } } - output := FormatOutput(namespace, diff, "Secrets") - outputBuffer.WriteString(output) - outputBuffer.WriteString("\n") + output := FormatOutput(namespace, diff, "Secrets", opts) + if output != "" { + outputBuffer.WriteString(output) + outputBuffer.WriteString("\n") - resourceMap := make(map[string][]string) - resourceMap["Secrets"] = diff - response[namespace] = resourceMap + resourceMap := make(map[string][]string) + resourceMap["Secrets"] = diff + response[namespace] = resourceMap + } } jsonResponse, err := json.MarshalIndent(response, "", " ") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/serviceaccounts.go new/kor-0.2.9/pkg/kor/serviceaccounts.go --- old/kor-0.2.8/pkg/kor/serviceaccounts.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/serviceaccounts.go 2023-11-14 13:02:29.000000000 +0100 @@ -101,7 +101,7 @@ return podServiceAccounts, roleServiceAccounts, clusterRoleServiceAccounts, nil } -func retrieveServiceAccountNames(clientset kubernetes.Interface, namespace string) ([]string, error) { +func retrieveServiceAccountNames(clientset kubernetes.Interface, namespace string, filterOpts *FilterOptions) ([]string, error) { serviceaccounts, err := clientset.CoreV1().ServiceAccounts(namespace).List(context.TODO(), metav1.ListOptions{}) if err != nil { return nil, err @@ -112,12 +112,20 @@ continue } + if excluded, _ := HasExcludedLabel(serviceaccount.Labels, filterOpts.ExcludeLabels); excluded { + continue + } + + if included, _ := HasIncludedAge(serviceaccount.CreationTimestamp, filterOpts); !included { + continue + } + names = append(names, serviceaccount.Name) } return names, nil } -func processNamespaceSA(clientset kubernetes.Interface, namespace string) ([]string, error) { +func processNamespaceSA(clientset kubernetes.Interface, namespace string, filterOpts *FilterOptions) ([]string, error) { usedServiceAccounts, roleServiceAccounts, clusterRoleServiceAccounts, err := retrieveUsedSA(clientset, namespace) if err != nil { return nil, err @@ -129,7 +137,7 @@ usedServiceAccounts = append(append(usedServiceAccounts, roleServiceAccounts...), clusterRoleServiceAccounts...) - serviceAccountNames, err := retrieveServiceAccountNames(clientset, namespace) + serviceAccountNames, err := retrieveServiceAccountNames(clientset, namespace, filterOpts) if err != nil { return nil, err } @@ -139,14 +147,14 @@ } -func GetUnusedServiceAccounts(includeExcludeLists IncludeExcludeLists, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedServiceAccounts(includeExcludeLists IncludeExcludeLists, filterOpts *FilterOptions, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { var outputBuffer bytes.Buffer namespaces := SetNamespaceList(includeExcludeLists, clientset) response := make(map[string]map[string][]string) for _, namespace := range namespaces { - diff, err := processNamespaceSA(clientset, namespace) + diff, err := processNamespaceSA(clientset, namespace, filterOpts) if err != nil { fmt.Fprintf(os.Stderr, "Failed to process namespace %s: %v\n", namespace, err) continue @@ -157,13 +165,15 @@ fmt.Fprintf(os.Stderr, "Failed to delete Serviceaccount %s in namespace %s: %v\n", diff, namespace, err) } } - output := FormatOutput(namespace, diff, "Serviceaccounts") - outputBuffer.WriteString(output) - outputBuffer.WriteString("\n") - - resourceMap := make(map[string][]string) - resourceMap["ServiceAccounts"] = diff - response[namespace] = resourceMap + output := FormatOutput(namespace, diff, "Serviceaccounts", opts) + if output != "" { + outputBuffer.WriteString(output) + outputBuffer.WriteString("\n") + + resourceMap := make(map[string][]string) + resourceMap["ServiceAccounts"] = diff + response[namespace] = resourceMap + } } jsonResponse, err := json.MarshalIndent(response, "", " ") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/serviceaccounts_test.go new/kor-0.2.9/pkg/kor/serviceaccounts_test.go --- old/kor-0.2.8/pkg/kor/serviceaccounts_test.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/serviceaccounts_test.go 2023-11-14 13:02:29.000000000 +0100 @@ -117,7 +117,7 @@ func TestRetrieveServiceAccountNames(t *testing.T) { clientset := createTestServiceAccounts(t) - serviceAccountNames, err := retrieveServiceAccountNames(clientset, testNamespace) + serviceAccountNames, err := retrieveServiceAccountNames(clientset, testNamespace, &FilterOptions{}) if err != nil { t.Fatalf("Expected no error, got %v", err) } @@ -147,7 +147,7 @@ t.Fatalf("Error creating fake %s: %v", "Pod", err) } - unusedServiceAccounts, err := processNamespaceSA(clientset, testNamespace) + unusedServiceAccounts, err := processNamespaceSA(clientset, testNamespace, &FilterOptions{}) if err != nil { t.Fatalf("Expected no error, got %v", err) } @@ -183,7 +183,7 @@ NoInteractive: true, } - output, err := GetUnusedServiceAccounts(includeExcludeLists, clientset, "json", opts) + output, err := GetUnusedServiceAccounts(includeExcludeLists, &FilterOptions{}, clientset, "json", opts) if err != nil { t.Fatalf("Error calling GetUnusedServiceAccountsStructured: %v", err) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/services.go new/kor-0.2.9/pkg/kor/services.go --- old/kor-0.2.8/pkg/kor/services.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/services.go 2023-11-14 13:02:29.000000000 +0100 @@ -11,7 +11,7 @@ "k8s.io/client-go/kubernetes" ) -func ProcessNamespaceServices(clientset kubernetes.Interface, namespace string) ([]string, error) { +func ProcessNamespaceServices(clientset kubernetes.Interface, namespace string, filterOpts *FilterOptions) ([]string, error) { endpointsList, err := clientset.CoreV1().Endpoints(namespace).List(context.TODO(), metav1.ListOptions{}) if err != nil { return nil, err @@ -24,6 +24,14 @@ continue } + if excluded, _ := HasExcludedLabel(endpoints.Labels, filterOpts.ExcludeLabels); excluded { + continue + } + + if included, _ := HasIncludedAge(endpoints.CreationTimestamp, filterOpts); !included { + continue + } + if len(endpoints.Subsets) == 0 { endpointsWithoutSubsets = append(endpointsWithoutSubsets, endpoints.Name) } @@ -32,14 +40,14 @@ return endpointsWithoutSubsets, nil } -func GetUnusedServices(includeExcludeLists IncludeExcludeLists, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedServices(includeExcludeLists IncludeExcludeLists, filterOpts *FilterOptions, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { var outputBuffer bytes.Buffer namespaces := SetNamespaceList(includeExcludeLists, clientset) response := make(map[string]map[string][]string) for _, namespace := range namespaces { - diff, err := ProcessNamespaceServices(clientset, namespace) + diff, err := ProcessNamespaceServices(clientset, namespace, filterOpts) if err != nil { fmt.Fprintf(os.Stderr, "Failed to process namespace %s: %v\n", namespace, err) continue @@ -50,13 +58,15 @@ fmt.Fprintf(os.Stderr, "Failed to delete Service %s in namespace %s: %v\n", diff, namespace, err) } } - output := FormatOutput(namespace, diff, "Services") - outputBuffer.WriteString(output) - outputBuffer.WriteString("\n") - - resourceMap := make(map[string][]string) - resourceMap["Services"] = diff - response[namespace] = resourceMap + output := FormatOutput(namespace, diff, "Services", opts) + if output != "" { + outputBuffer.WriteString(output) + outputBuffer.WriteString("\n") + + resourceMap := make(map[string][]string) + resourceMap["Services"] = diff + response[namespace] = resourceMap + } } jsonResponse, err := json.MarshalIndent(response, "", " ") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/services_test.go new/kor-0.2.9/pkg/kor/services_test.go --- old/kor-0.2.8/pkg/kor/services_test.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/services_test.go 2023-11-14 13:02:29.000000000 +0100 @@ -43,7 +43,7 @@ func TestGetEndpointsWithoutSubsets(t *testing.T) { clientset := createTestServices(t) - servicesWithoutEndpoints, err := ProcessNamespaceServices(clientset, testNamespace) + servicesWithoutEndpoints, err := ProcessNamespaceServices(clientset, testNamespace, &FilterOptions{}) if err != nil { t.Errorf("Expected no error, got %v", err) } @@ -73,7 +73,7 @@ NoInteractive: true, } - output, err := GetUnusedServices(includeExcludeLists, clientset, "json", opts) + output, err := GetUnusedServices(includeExcludeLists, &FilterOptions{}, clientset, "json", opts) if err != nil { t.Fatalf("Error calling GetUnusedServicesStructured: %v", err) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/kor/statefulsets.go new/kor-0.2.9/pkg/kor/statefulsets.go --- old/kor-0.2.8/pkg/kor/statefulsets.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/kor/statefulsets.go 2023-11-14 13:02:29.000000000 +0100 @@ -55,13 +55,15 @@ fmt.Fprintf(os.Stderr, "Failed to delete Statefulset %s in namespace %s: %v\n", diff, namespace, err) } } - output := FormatOutput(namespace, diff, "Statefulsets") - outputBuffer.WriteString(output) - outputBuffer.WriteString("\n") + output := FormatOutput(namespace, diff, "Statefulsets", opts) + if output != "" { + outputBuffer.WriteString(output) + outputBuffer.WriteString("\n") - resourceMap := make(map[string][]string) - resourceMap["Statefulsets"] = diff - response[namespace] = resourceMap + resourceMap := make(map[string][]string) + resourceMap["Statefulsets"] = diff + response[namespace] = resourceMap + } } jsonResponse, err := json.MarshalIndent(response, "", " ") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/kor-0.2.8/pkg/utils/banner.go new/kor-0.2.9/pkg/utils/banner.go --- old/kor-0.2.8/pkg/utils/banner.go 2023-11-12 18:35:19.000000000 +0100 +++ new/kor-0.2.9/pkg/utils/banner.go 2023-11-14 13:02:29.000000000 +0100 @@ -4,7 +4,7 @@ "github.com/fatih/color" ) -func PrintLogo() { +func PrintLogo(outputFormat string) { boldBlue := color.New(color.FgHiBlue, color.Bold) asciiLogo := ` _ _____ ____ @@ -13,6 +13,10 @@ | . \ |_| | _ < |_|\_\___/|_| \_\ ` + // processing of the `outputFormat` happens inside of the rootCmd so this requires a pretty large change + // to keep the banner. Instead just loop through os args and find if the format was set and handle it there - boldBlue.Println(asciiLogo) + if outputFormat != "yaml" && outputFormat != "json" { + boldBlue.Println(asciiLogo) + } } ++++++ kor.obsinfo ++++++ --- /var/tmp/diff_new_pack.ADJpAg/_old 2023-11-14 21:43:42.698128145 +0100 +++ /var/tmp/diff_new_pack.ADJpAg/_new 2023-11-14 21:43:42.706128442 +0100 @@ -1,5 +1,5 @@ name: kor -version: 0.2.8 -mtime: 1699810519 -commit: dec8161f811a3710916c3eb85d6e89272d6de0f7 +version: 0.2.9 +mtime: 1699963349 +commit: 4a93e141b15605a66d661979e66976c5ed7c17d9 ++++++ vendor.tar.gz ++++++ /work/SRC/openSUSE:Factory/kor/vendor.tar.gz /work/SRC/openSUSE:Factory/.kor.new.17445/vendor.tar.gz differ: char 5, line 1