diff --git a/cmd/kor/all.go b/cmd/kor/all.go index 57db787d..de1619de 100644 --- a/cmd/kor/all.go +++ b/cmd/kor/all.go @@ -11,9 +11,9 @@ var allCmd = &cobra.Command{ Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { if outputFormat == "json" { - kor.GetUnusedAllJSON(namespace, kubeconfig) + kor.GetUnusedAllJSON(includeExcludeLists, kubeconfig) } else { - kor.GetUnusedAll(namespace, kubeconfig) + kor.GetUnusedAll(includeExcludeLists, kubeconfig) } }, diff --git a/cmd/kor/configmaps.go b/cmd/kor/configmaps.go index 3ff52509..42131056 100644 --- a/cmd/kor/configmaps.go +++ b/cmd/kor/configmaps.go @@ -12,9 +12,9 @@ var configmapCmd = &cobra.Command{ Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { if outputFormat == "json" { - kor.GetUnusedConfigmapsJSON(namespace, kubeconfig) + kor.GetUnusedConfigmapsJSON(includeExcludeLists, kubeconfig) } else { - kor.GetUnusedConfigmaps(namespace, kubeconfig) + kor.GetUnusedConfigmaps(includeExcludeLists, kubeconfig) } }, diff --git a/cmd/kor/deployments.go b/cmd/kor/deployments.go index 37ad8d19..1dfa9be5 100644 --- a/cmd/kor/deployments.go +++ b/cmd/kor/deployments.go @@ -12,9 +12,9 @@ var deployCmd = &cobra.Command{ Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { if outputFormat == "json" { - kor.GetUnusedDeploymentsJSON(namespace, kubeconfig) + kor.GetUnusedDeploymentsJSON(includeExcludeLists, kubeconfig) } else { - kor.GetUnusedDeployments(namespace, kubeconfig) + kor.GetUnusedDeployments(includeExcludeLists, kubeconfig) } }, diff --git a/cmd/kor/hpas.go b/cmd/kor/hpas.go index c43bfd7e..39750a4e 100644 --- a/cmd/kor/hpas.go +++ b/cmd/kor/hpas.go @@ -11,9 +11,9 @@ var hpaCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { if outputFormat == "json" { - kor.GetUnusedHpasJson(namespace, kubeconfig) + kor.GetUnusedHpasJson(includeExcludeLists, kubeconfig) } else { - kor.GetUnusedHpas(namespace, kubeconfig) + kor.GetUnusedHpas(includeExcludeLists, kubeconfig) } }, } diff --git a/cmd/kor/pvc.go b/cmd/kor/pvc.go index acc24ac8..fe305cb4 100644 --- a/cmd/kor/pvc.go +++ b/cmd/kor/pvc.go @@ -11,9 +11,9 @@ var pvcCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { if outputFormat == "json" { - kor.GetUnusedPvcsJson(namespace, kubeconfig) + kor.GetUnusedPvcsJson(includeExcludeLists, kubeconfig) } else { - kor.GetUnusedPvcs(namespace, kubeconfig) + kor.GetUnusedPvcs(includeExcludeLists, kubeconfig) } }, } diff --git a/cmd/kor/roles.go b/cmd/kor/roles.go index d8e2a4f7..1e8a5c0d 100644 --- a/cmd/kor/roles.go +++ b/cmd/kor/roles.go @@ -11,9 +11,9 @@ var roleCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { if outputFormat == "json" { - kor.GetUnusedRolesJSON(namespace, kubeconfig) + kor.GetUnusedRolesJSON(includeExcludeLists, kubeconfig) } else { - kor.GetUnusedRoles(namespace, kubeconfig) + kor.GetUnusedRoles(includeExcludeLists, kubeconfig) } }, } diff --git a/cmd/kor/root.go b/cmd/kor/root.go index e24f9688..fa99d12e 100644 --- a/cmd/kor/root.go +++ b/cmd/kor/root.go @@ -5,6 +5,7 @@ import ( "os" "github.com/spf13/cobra" + "github.com/yonahd/kor/pkg/kor" ) var rootCmd = &cobra.Command{ @@ -14,17 +15,19 @@ var rootCmd = &cobra.Command{ kor can currently discover unused configmaps and secrets`, Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - }, } -var namespace string -var outputFormat string -var kubeconfig string +var ( + outputFormat string + kubeconfig string + includeExcludeLists kor.IncludeExcludeLists +) func Execute() { rootCmd.PersistentFlags().StringVarP(&kubeconfig, "kubeconfig", "k", "", "Path to kubeconfig file (optional)") - rootCmd.PersistentFlags().StringVarP(&namespace, "namespace", "n", "", "Namespace to run on") + 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 or json)") if err := rootCmd.Execute(); err != nil { fmt.Fprintf(os.Stderr, "Error while executing your CLI '%s'", err) diff --git a/cmd/kor/secrets.go b/cmd/kor/secrets.go index e714ccfb..5d7b9f1e 100644 --- a/cmd/kor/secrets.go +++ b/cmd/kor/secrets.go @@ -12,9 +12,9 @@ var secretCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { if outputFormat == "json" { - kor.GetUnusedSecretsJSON(namespace, kubeconfig) + kor.GetUnusedSecretsJSON(includeExcludeLists, kubeconfig) } else { - kor.GetUnusedSecrets(namespace, kubeconfig) + kor.GetUnusedSecrets(includeExcludeLists, kubeconfig) } }, diff --git a/cmd/kor/serviceaccounts.go b/cmd/kor/serviceaccounts.go index 8eaaf9f5..1eca91db 100644 --- a/cmd/kor/serviceaccounts.go +++ b/cmd/kor/serviceaccounts.go @@ -12,9 +12,9 @@ var serviceAccountCmd = &cobra.Command{ Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { if outputFormat == "json" { - kor.GetUnusedServiceAccountsJSON(namespace, kubeconfig) + kor.GetUnusedServiceAccountsJSON(includeExcludeLists, kubeconfig) } else { - kor.GetUnusedServiceAccounts(namespace, kubeconfig) + kor.GetUnusedServiceAccounts(includeExcludeLists, kubeconfig) } }, diff --git a/cmd/kor/services.go b/cmd/kor/services.go index 6cbe7a81..7c3301db 100644 --- a/cmd/kor/services.go +++ b/cmd/kor/services.go @@ -12,9 +12,9 @@ var serviceCmd = &cobra.Command{ Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { if outputFormat == "json" { - kor.GetUnusedServicesJSON(namespace, kubeconfig) + kor.GetUnusedServicesJSON(includeExcludeLists, kubeconfig) } else { - kor.GetUnusedServices(namespace, kubeconfig) + kor.GetUnusedServices(includeExcludeLists, kubeconfig) } }, diff --git a/cmd/kor/statefulsets.go b/cmd/kor/statefulsets.go index 7e534ab8..a6a49c4d 100644 --- a/cmd/kor/statefulsets.go +++ b/cmd/kor/statefulsets.go @@ -12,9 +12,9 @@ var stsCmd = &cobra.Command{ Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { if outputFormat == "json" { - kor.GetUnusedStatefulsetsJSON(namespace, kubeconfig) + kor.GetUnusedStatefulsetsJSON(includeExcludeLists, kubeconfig) } else { - kor.GetUnusedStatefulsets(namespace, kubeconfig) + kor.GetUnusedStatefulsets(includeExcludeLists, kubeconfig) } }, diff --git a/pkg/kor/all.go b/pkg/kor/all.go index c305973b..d6fda322 100644 --- a/pkg/kor/all.go +++ b/pkg/kor/all.go @@ -99,13 +99,13 @@ func getUnusedPvcs(kubeClient *kubernetes.Clientset, namespace string) ResourceD return namespacePvcDiff } -func GetUnusedAll(namespace string, kubeconfig string) { +func GetUnusedAll(includeExcludeLists IncludeExcludeLists, kubeconfig string) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) for _, namespace := range namespaces { var allDiffs []ResourceDiff namespaceCMDiff := getUnusedCMs(kubeClient, namespace) @@ -132,13 +132,13 @@ func GetUnusedAll(namespace string, kubeconfig string) { } } -func GetUnusedAllJSON(namespace string, kubeconfig string) (string, error) { +func GetUnusedAllJSON(includeExcludeLists IncludeExcludeLists, kubeconfig string) (string, error) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) // Create the JSON response object response := make(map[string]map[string][]string) diff --git a/pkg/kor/confimgmaps.go b/pkg/kor/confimgmaps.go index bc861bb0..b4593089 100644 --- a/pkg/kor/confimgmaps.go +++ b/pkg/kor/confimgmaps.go @@ -106,13 +106,13 @@ func processNamespaceCM(kubeClient *kubernetes.Clientset, namespace string) ([]s } -func GetUnusedConfigmaps(namespace string, kubeconfig string) { +func GetUnusedConfigmaps(includeExcludeLists IncludeExcludeLists, kubeconfig string) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) for _, namespace := range namespaces { diff, err := processNamespaceCM(kubeClient, namespace) @@ -126,12 +126,12 @@ func GetUnusedConfigmaps(namespace string, kubeconfig string) { } } -func GetUnusedConfigmapsJSON(namespace string, kubeconfig string) (string, error) { +func GetUnusedConfigmapsJSON(includeExcludeLists IncludeExcludeLists, kubeconfig string) (string, error) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) response := make(map[string]map[string][]string) for _, namespace := range namespaces { diff --git a/pkg/kor/deployments.go b/pkg/kor/deployments.go index c90b17d5..50728b1f 100644 --- a/pkg/kor/deployments.go +++ b/pkg/kor/deployments.go @@ -37,13 +37,13 @@ func ProcessNamespaceDeployments(clientset *kubernetes.Clientset, namespace stri } -func GetUnusedDeployments(namespace string, kubeconfig string) { +func GetUnusedDeployments(includeExcludeLists IncludeExcludeLists, kubeconfig string) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) for _, namespace := range namespaces { diff, err := ProcessNamespaceDeployments(kubeClient, namespace) @@ -57,12 +57,12 @@ func GetUnusedDeployments(namespace string, kubeconfig string) { } } -func GetUnusedDeploymentsJSON(namespace string, kubeconfig string) (string, error) { +func GetUnusedDeploymentsJSON(includeExcludeLists IncludeExcludeLists, kubeconfig string) (string, error) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) response := make(map[string]map[string][]string) for _, namespace := range namespaces { diff --git a/pkg/kor/hpas.go b/pkg/kor/hpas.go index f1022199..ee91f6bb 100644 --- a/pkg/kor/hpas.go +++ b/pkg/kor/hpas.go @@ -75,13 +75,13 @@ func processNamespaceHpas(clientset *kubernetes.Clientset, namespace string) ([] return unusedHpas, nil } -func GetUnusedHpas(namespace string, kubeconfig string) { +func GetUnusedHpas(includeExcludeLists IncludeExcludeLists, kubeconfig string) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) for _, namespace := range namespaces { diff, err := processNamespaceHpas(kubeClient, namespace) @@ -96,13 +96,13 @@ func GetUnusedHpas(namespace string, kubeconfig string) { } -func GetUnusedHpasJson(namespace string, kubeconfig string) (string, error) { +func GetUnusedHpasJson(includeExcludeLists IncludeExcludeLists, kubeconfig string) (string, error) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) response := make(map[string]map[string][]string) for _, namespace := range namespaces { diff --git a/pkg/kor/kor.go b/pkg/kor/kor.go index 440ff2cd..e8f1989b 100644 --- a/pkg/kor/kor.go +++ b/pkg/kor/kor.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "sort" + "strings" "github.com/olekukonko/tablewriter" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -19,6 +20,10 @@ type ExceptionResource struct { ResourceName string Namespace string } +type IncludeExcludeLists struct { + IncludeListStr string + ExcludeListStr string +} func RemoveDuplicatesAndSort(slice []string) []string { uniqueSet := make(map[string]bool) @@ -56,18 +61,44 @@ func GetKubeClient(kubeconfig string) *kubernetes.Clientset { return clientset } -func SetNamespaceList(namespace string, kubeClient *kubernetes.Clientset) []string { - var namespaces []string - if namespace != "" { - namespaces = append(namespaces, namespace) - } else { - namespaceList, err := kubeClient.CoreV1().Namespaces().List(context.TODO(), metav1.ListOptions{}) - if err != nil { - fmt.Fprintf(os.Stderr, "Failed to retrieve namespaces: %v\n", err) - os.Exit(1) +func SetNamespaceList(namespaceLists IncludeExcludeLists, kubeClient *kubernetes.Clientset) []string { + namespaces := make([]string, 0) + namespacesMap := make(map[string]bool) + if namespaceLists.IncludeListStr != "" && namespaceLists.ExcludeListStr != "" { + fmt.Fprintf(os.Stderr, "Exclude namespaces can't be used together with include namespaces. Ignoring --exclude-namespace(-e) flag\n") + namespaceLists.ExcludeListStr = "" + } + includeNamespaces := strings.Split(namespaceLists.IncludeListStr, ",") + excludeNamespaces := strings.Split(namespaceLists.ExcludeListStr, ",") + namespaceList, err := kubeClient.CoreV1().Namespaces().List(context.TODO(), metav1.ListOptions{}) + if err != nil { + fmt.Fprintf(os.Stderr, "Failed to retrieve namespaces: %v\n", err) + os.Exit(1) + } + if namespaceLists.IncludeListStr != "" { + for _, ns := range namespaceList.Items { + namespacesMap[ns.Name] = false } + for _, ns := range includeNamespaces { + if _, exists := namespacesMap[ns]; exists { + namespacesMap[ns] = true + } else { + fmt.Fprintf(os.Stderr, "namespace [%s] not found\n", ns) + } + } + } else { for _, ns := range namespaceList.Items { - namespaces = append(namespaces, ns.Name) + namespacesMap[ns.Name] = true + } + for _, ns := range excludeNamespaces { + if _, exists := namespacesMap[ns]; exists { + namespacesMap[ns] = false + } + } + } + for ns := range namespacesMap { + if namespacesMap[ns] { + namespaces = append(namespaces, ns) } } return namespaces diff --git a/pkg/kor/pvc.go b/pkg/kor/pvc.go index 1a9e2c43..31581154 100644 --- a/pkg/kor/pvc.go +++ b/pkg/kor/pvc.go @@ -49,13 +49,13 @@ func processNamespacePvcs(kubeClient *kubernetes.Clientset, namespace string) ([ return diff, nil } -func GetUnusedPvcs(namespace string, kubeconfig string) { +func GetUnusedPvcs(includeExcludeLists IncludeExcludeLists, kubeconfig string) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) for _, namespace := range namespaces { diff, err := processNamespacePvcs(kubeClient, namespace) @@ -70,13 +70,13 @@ func GetUnusedPvcs(namespace string, kubeconfig string) { } -func GetUnusedPvcsJson(namespace string, kubeconfig string) (string, error) { +func GetUnusedPvcsJson(includeExcludeLists IncludeExcludeLists, kubeconfig string) (string, error) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) response := make(map[string]map[string][]string) for _, namespace := range namespaces { diff --git a/pkg/kor/roles.go b/pkg/kor/roles.go index 31a72588..09b22c63 100644 --- a/pkg/kor/roles.go +++ b/pkg/kor/roles.go @@ -67,12 +67,12 @@ func processNamespaceRoles(kubeClient *kubernetes.Clientset, namespace string) ( } -func GetUnusedRoles(namespace string, kubeconfig string) { +func GetUnusedRoles(includeExcludeLists IncludeExcludeLists, kubeconfig string) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) for _, namespace := range namespaces { diff, err := processNamespaceRoles(kubeClient, namespace) @@ -86,12 +86,12 @@ func GetUnusedRoles(namespace string, kubeconfig string) { } } -func GetUnusedRolesJSON(namespace string, kubeconfig string) (string, error) { +func GetUnusedRolesJSON(includeExcludeLists IncludeExcludeLists, kubeconfig string) (string, error) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) response := make(map[string]map[string][]string) for _, namespace := range namespaces { diff --git a/pkg/kor/secrets.go b/pkg/kor/secrets.go index e6028203..a16bb29f 100644 --- a/pkg/kor/secrets.go +++ b/pkg/kor/secrets.go @@ -119,13 +119,13 @@ func processNamespaceSecret(kubeClient *kubernetes.Clientset, namespace string) } -func GetUnusedSecrets(namespace string, kubeconfig string) { +func GetUnusedSecrets(includeExcludeLists IncludeExcludeLists, kubeconfig string) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) for _, namespace := range namespaces { diff, err := processNamespaceSecret(kubeClient, namespace) @@ -139,12 +139,12 @@ func GetUnusedSecrets(namespace string, kubeconfig string) { } } -func GetUnusedSecretsJSON(namespace string, kubeconfig string) (string, error) { +func GetUnusedSecretsJSON(includeExcludeLists IncludeExcludeLists, kubeconfig string) (string, error) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) response := make(map[string]map[string][]string) for _, namespace := range namespaces { diff --git a/pkg/kor/serviceaccounts.go b/pkg/kor/serviceaccounts.go index bdab5c8f..179a0804 100644 --- a/pkg/kor/serviceaccounts.go +++ b/pkg/kor/serviceaccounts.go @@ -120,13 +120,13 @@ func processNamespaceSA(kubeClient *kubernetes.Clientset, namespace string) ([]s } -func GetUnusedServiceAccounts(namespace string, kubeconfig string) { +func GetUnusedServiceAccounts(includeExcludeLists IncludeExcludeLists, kubeconfig string) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) for _, namespace := range namespaces { diff, err := processNamespaceSA(kubeClient, namespace) @@ -140,12 +140,12 @@ func GetUnusedServiceAccounts(namespace string, kubeconfig string) { } } -func GetUnusedServiceAccountsJSON(namespace string, kubeconfig string) (string, error) { +func GetUnusedServiceAccountsJSON(includeExcludeLists IncludeExcludeLists, kubeconfig string) (string, error) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) response := make(map[string]map[string][]string) for _, namespace := range namespaces { diff --git a/pkg/kor/services.go b/pkg/kor/services.go index 7c96d3cf..fb16989e 100644 --- a/pkg/kor/services.go +++ b/pkg/kor/services.go @@ -37,13 +37,13 @@ func ProcessNamespaceServices(clientset *kubernetes.Clientset, namespace string) } -func GetUnusedServices(namespace string, kubeconfig string) { +func GetUnusedServices(includeExcludeLists IncludeExcludeLists, kubeconfig string) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) for _, namespace := range namespaces { diff, err := ProcessNamespaceServices(kubeClient, namespace) @@ -57,12 +57,12 @@ func GetUnusedServices(namespace string, kubeconfig string) { } } -func GetUnusedServicesJSON(namespace string, kubeconfig string) (string, error) { +func GetUnusedServicesJSON(includeExcludeLists IncludeExcludeLists, kubeconfig string) (string, error) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) response := make(map[string]map[string][]string) for _, namespace := range namespaces { diff --git a/pkg/kor/statefulsets.go b/pkg/kor/statefulsets.go index c0deafde..d4fc8471 100644 --- a/pkg/kor/statefulsets.go +++ b/pkg/kor/statefulsets.go @@ -37,13 +37,13 @@ func ProcessNamespaceStatefulsets(clientset *kubernetes.Clientset, namespace str } -func GetUnusedStatefulsets(namespace string, kubeconfig string) { +func GetUnusedStatefulsets(includeExcludeLists IncludeExcludeLists, kubeconfig string) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) for _, namespace := range namespaces { diff, err := ProcessNamespaceStatefulsets(kubeClient, namespace) @@ -57,12 +57,12 @@ func GetUnusedStatefulsets(namespace string, kubeconfig string) { } } -func GetUnusedStatefulsetsJSON(namespace string, kubeconfig string) (string, error) { +func GetUnusedStatefulsetsJSON(includeExcludeLists IncludeExcludeLists, kubeconfig string) (string, error) { var kubeClient *kubernetes.Clientset var namespaces []string kubeClient = GetKubeClient(kubeconfig) - namespaces = SetNamespaceList(namespace, kubeClient) + namespaces = SetNamespaceList(includeExcludeLists, kubeClient) response := make(map[string]map[string][]string) for _, namespace := range namespaces {