diff --git a/cmd/kor/root.go b/cmd/kor/root.go index 48b0500f..17c818e9 100644 --- a/cmd/kor/root.go +++ b/cmd/kor/root.go @@ -8,6 +8,7 @@ import ( "github.com/spf13/cobra" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" "github.com/yonahd/kor/pkg/kor" "github.com/yonahd/kor/pkg/utils" @@ -46,7 +47,7 @@ var rootCmd = &cobra.Command{ var ( outputFormat string kubeconfig string - opts kor.Opts + opts common.Opts filterOptions = &filters.Options{} ) diff --git a/pkg/common/params.go b/pkg/common/params.go new file mode 100644 index 00000000..2effe960 --- /dev/null +++ b/pkg/common/params.go @@ -0,0 +1,12 @@ +package common + +type Opts struct { + DeleteFlag bool + NoInteractive bool + Verbose bool + WebhookURL string + Channel string + Token string + GroupBy string + ShowReason bool +} diff --git a/pkg/kor/all.go b/pkg/kor/all.go index 1d8a81da..37af741f 100644 --- a/pkg/kor/all.go +++ b/pkg/kor/all.go @@ -10,6 +10,7 @@ import ( "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -263,7 +264,7 @@ func getUnusedNetworkPolicies(clientset kubernetes.Interface, namespace string, return namespaceNetpolDiff } -func GetUnusedAllNamespaced(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedAllNamespaced(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { switch opts.GroupBy { @@ -325,7 +326,7 @@ func GetUnusedAllNamespaced(filterOpts *filters.Options, clientset kubernetes.In return unusedAllNamespaced, nil } -func GetUnusedAllNonNamespaced(filterOpts *filters.Options, clientset kubernetes.Interface, apiExtClient apiextensionsclientset.Interface, dynamicClient dynamic.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedAllNonNamespaced(filterOpts *filters.Options, clientset kubernetes.Interface, apiExtClient apiextensionsclientset.Interface, dynamicClient dynamic.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) switch opts.GroupBy { case "namespace": @@ -361,7 +362,7 @@ func GetUnusedAllNonNamespaced(filterOpts *filters.Options, clientset kubernetes return unusedAllNonNamespaced, nil } -func GetUnusedAll(filterOpts *filters.Options, clientset kubernetes.Interface, apiExtClient apiextensionsclientset.Interface, dynamicClient dynamic.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedAll(filterOpts *filters.Options, clientset kubernetes.Interface, apiExtClient apiextensionsclientset.Interface, dynamicClient dynamic.Interface, outputFormat string, opts common.Opts) (string, error) { unusedAllNamespaced, err := GetUnusedAllNamespaced(filterOpts, clientset, outputFormat, opts) if err != nil { fmt.Printf("err: %v\n", err) diff --git a/pkg/kor/clusterroles.go b/pkg/kor/clusterroles.go index ee3dd6dc..d11f54a0 100644 --- a/pkg/kor/clusterroles.go +++ b/pkg/kor/clusterroles.go @@ -15,6 +15,7 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth/oidc" "k8s.io/utils/strings/slices" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -179,7 +180,7 @@ func processClusterRoles(clientset kubernetes.Interface, filterOpts *filters.Opt } -func GetUnusedClusterRoles(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedClusterRoles(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) diff, err := processClusterRoles(clientset, filterOpts) if err != nil { diff --git a/pkg/kor/clusterroles_test.go b/pkg/kor/clusterroles_test.go index 0a8adf59..6283488a 100644 --- a/pkg/kor/clusterroles_test.go +++ b/pkg/kor/clusterroles_test.go @@ -14,6 +14,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -138,7 +139,7 @@ func TestProcessClusterRoles(t *testing.T) { func TestGetUnusedClusterRolesStructured(t *testing.T) { clientset := createTestClusterRoles(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/configmaps.go b/pkg/kor/configmaps.go index fe9e5cfc..44b57fd9 100644 --- a/pkg/kor/configmaps.go +++ b/pkg/kor/configmaps.go @@ -12,6 +12,7 @@ import ( "k8s.io/client-go/kubernetes" _ "k8s.io/client-go/plugin/pkg/client/auth/oidc" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -158,7 +159,7 @@ func processNamespaceCM(clientset kubernetes.Interface, namespace string, filter return diff, nil } -func GetUnusedConfigmaps(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedConfigmaps(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff, err := processNamespaceCM(clientset, namespace, filterOpts) diff --git a/pkg/kor/configmaps_test.go b/pkg/kor/configmaps_test.go index 02140886..a0d8f410 100644 --- a/pkg/kor/configmaps_test.go +++ b/pkg/kor/configmaps_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -197,7 +198,7 @@ func TestRetrieveUsedCM(t *testing.T) { func TestGetUnusedConfigmapsStructured(t *testing.T) { clientset := createTestConfigmaps(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/crds.go b/pkg/kor/crds.go index af61b528..1975b2e4 100644 --- a/pkg/kor/crds.go +++ b/pkg/kor/crds.go @@ -14,6 +14,7 @@ import ( "k8s.io/client-go/dynamic" _ "k8s.io/client-go/plugin/pkg/client/auth/oidc" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -65,7 +66,7 @@ func processCrds(apiExtClient apiextensionsclientset.Interface, dynamicClient dy return unusedCRDs, nil } -func GetUnusedCrds(_ *filters.Options, apiExtClient apiextensionsclientset.Interface, dynamicClient dynamic.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedCrds(_ *filters.Options, apiExtClient apiextensionsclientset.Interface, dynamicClient dynamic.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) diff, err := processCrds(apiExtClient, dynamicClient, &filters.Options{}) if err != nil { diff --git a/pkg/kor/daemonsets.go b/pkg/kor/daemonsets.go index 7437ff9d..1c88d6b7 100644 --- a/pkg/kor/daemonsets.go +++ b/pkg/kor/daemonsets.go @@ -11,6 +11,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -59,7 +60,7 @@ func processNamespaceDaemonSets(clientset kubernetes.Interface, namespace string return daemonSetsWithoutReplicas, nil } -func GetUnusedDaemonSets(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedDaemonSets(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff, err := processNamespaceDaemonSets(clientset, namespace, filterOpts) diff --git a/pkg/kor/daemonsets_test.go b/pkg/kor/daemonsets_test.go index 78bf3268..a5fb2e38 100644 --- a/pkg/kor/daemonsets_test.go +++ b/pkg/kor/daemonsets_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -82,7 +83,7 @@ func TestProcessNamespaceDaemonSets(t *testing.T) { func TestGetUnusedDaemonSetsStructured(t *testing.T) { clientset := createTestDaemonSets(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/deployments.go b/pkg/kor/deployments.go index 50d67841..efc7c05d 100644 --- a/pkg/kor/deployments.go +++ b/pkg/kor/deployments.go @@ -10,6 +10,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -41,7 +42,7 @@ func processNamespaceDeployments(clientset kubernetes.Interface, namespace strin return deploymentsWithoutReplicas, nil } -func GetUnusedDeployments(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedDeployments(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff, err := processNamespaceDeployments(clientset, namespace, filterOpts) diff --git a/pkg/kor/deployments_test.go b/pkg/kor/deployments_test.go index f659d6fc..ca4c3f8d 100644 --- a/pkg/kor/deployments_test.go +++ b/pkg/kor/deployments_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -74,7 +75,7 @@ func TestProcessNamespaceDeployments(t *testing.T) { func TestGetUnusedDeploymentsStructured(t *testing.T) { clientset := createTestDeployments(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/exporter.go b/pkg/kor/exporter.go index 830e6504..39b66c3b 100644 --- a/pkg/kor/exporter.go +++ b/pkg/kor/exporter.go @@ -15,6 +15,7 @@ import ( "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -33,7 +34,7 @@ func init() { } // TODO: add option to change port / url !? -func Exporter(filterOptions *filters.Options, clientset kubernetes.Interface, apiExtClient apiextensionsclientset.Interface, dynamicClient dynamic.Interface, outputFormat string, opts Opts, resourceList []string) { +func Exporter(filterOptions *filters.Options, clientset kubernetes.Interface, apiExtClient apiextensionsclientset.Interface, dynamicClient dynamic.Interface, outputFormat string, opts common.Opts, resourceList []string) { http.Handle("/metrics", promhttp.Handler()) fmt.Println("Server listening on :8080") go exportMetrics(filterOptions, clientset, apiExtClient, dynamicClient, outputFormat, opts, resourceList) // Start exporting metrics in the background @@ -42,7 +43,7 @@ func Exporter(filterOptions *filters.Options, clientset kubernetes.Interface, ap } } -func exportMetrics(filterOptions *filters.Options, clientset kubernetes.Interface, apiExtClient apiextensionsclientset.Interface, dynamicClient dynamic.Interface, outputFormat string, opts Opts, resourceList []string) { +func exportMetrics(filterOptions *filters.Options, clientset kubernetes.Interface, apiExtClient apiextensionsclientset.Interface, dynamicClient dynamic.Interface, outputFormat string, opts common.Opts, resourceList []string) { exporterInterval := os.Getenv("EXPORTER_INTERVAL") if exporterInterval == "" { exporterInterval = "10" @@ -79,7 +80,7 @@ func exportMetrics(filterOptions *filters.Options, clientset kubernetes.Interfac } } -func getUnusedResources(filterOptions *filters.Options, clientset kubernetes.Interface, apiExtClient apiextensionsclientset.Interface, dynamicClient dynamic.Interface, outputFormat string, opts Opts, resourceList []string) (string, error) { +func getUnusedResources(filterOptions *filters.Options, clientset kubernetes.Interface, apiExtClient apiextensionsclientset.Interface, dynamicClient dynamic.Interface, outputFormat string, opts common.Opts, resourceList []string) (string, error) { if len(resourceList) == 0 || (len(resourceList) == 1 && resourceList[0] == "all") { return GetUnusedAll(filterOptions, clientset, apiExtClient, dynamicClient, outputFormat, opts) } diff --git a/pkg/kor/finalizers.go b/pkg/kor/finalizers.go index 7c80598a..198206a1 100644 --- a/pkg/kor/finalizers.go +++ b/pkg/kor/finalizers.go @@ -14,6 +14,7 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth/oidc" "k8s.io/utils/strings/slices" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -78,7 +79,7 @@ func getResourcesWithFinalizersPendingDeletion(clientset kubernetes.Interface, d return retrievePendingDeletionResources(resourceTypes, dynamicClient, filterOpts) } -func GetUnusedfinalizers(filterOpts *filters.Options, clientset kubernetes.Interface, dynamicClient *dynamic.DynamicClient, outputFormat string, opts Opts) (string, error) { +func GetUnusedfinalizers(filterOpts *filters.Options, clientset kubernetes.Interface, dynamicClient *dynamic.DynamicClient, outputFormat string, opts common.Opts) (string, error) { var outputBuffer bytes.Buffer namespaces := filterOpts.Namespaces(clientset) response := make(map[string]map[string][]ResourceInfo) diff --git a/pkg/kor/formatter.go b/pkg/kor/formatter.go index 092593b4..cec7a0c5 100644 --- a/pkg/kor/formatter.go +++ b/pkg/kor/formatter.go @@ -8,6 +8,9 @@ import ( "github.com/olekukonko/tablewriter" "sigs.k8s.io/yaml" + + "github.com/yonahd/kor/pkg/common" + "github.com/yonahd/kor/pkg/utils" ) type ResourceInfo struct { @@ -22,13 +25,13 @@ func getTableRow(index int, columns ...string) []string { return row } -func unusedResourceFormatter(outputFormat string, outputBuffer bytes.Buffer, opts Opts, jsonResponse []byte) (string, error) { +func unusedResourceFormatter(outputFormat string, outputBuffer bytes.Buffer, opts common.Opts, jsonResponse []byte) (string, error) { switch outputFormat { case "table": if opts.WebhookURL == "" || opts.Channel == "" || opts.Token != "" { return outputBuffer.String(), nil } - if err := SendToSlack(SlackMessage{}, opts, outputBuffer.String()); err != nil { + if err := utils.SendToSlack(utils.SlackMessage{}, opts, outputBuffer.String()); err != nil { return "", fmt.Errorf("failed to send message to slack: %w", err) } case "json", "yaml": @@ -81,7 +84,7 @@ func unusedResourceFormatter(outputFormat string, outputBuffer bytes.Buffer, opt return "", fmt.Errorf("unsupported output format: %s", outputFormat) } -func FormatOutput(resources map[string]map[string][]ResourceInfo, opts Opts) bytes.Buffer { +func FormatOutput(resources map[string]map[string][]ResourceInfo, opts common.Opts) bytes.Buffer { var output bytes.Buffer switch opts.GroupBy { case "namespace": @@ -96,7 +99,7 @@ func FormatOutput(resources map[string]map[string][]ResourceInfo, opts Opts) byt return output } -func formatOutputForNamespace(namespace string, resources map[string][]ResourceInfo, opts Opts) string { +func formatOutputForNamespace(namespace string, resources map[string][]ResourceInfo, opts common.Opts) string { var buf strings.Builder table := tablewriter.NewWriter(&buf) table.SetColWidth(60) @@ -125,7 +128,7 @@ func formatOutputForNamespace(namespace string, resources map[string][]ResourceI return fmt.Sprintf("Unused resources in namespace: %q\n%s\n", namespace, buf.String()) } -func formatOutputForResource(resource string, resources map[string][]ResourceInfo, opts Opts) string { +func formatOutputForResource(resource string, resources map[string][]ResourceInfo, opts common.Opts) string { if len(resources) == 0 { if opts.Verbose { return fmt.Sprintf("No unused %ss found\n", resource) @@ -207,7 +210,7 @@ func getTableRowResourceInfo(index int, resourceType string, resource ResourceIn return row } -func FormatOutputAll(namespace string, allDiffs []ResourceDiff, opts Opts) string { +func FormatOutputAll(namespace string, allDiffs []ResourceDiff, opts common.Opts) string { var buf strings.Builder table := tablewriter.NewWriter(&buf) table.SetColWidth(60) diff --git a/pkg/kor/hpas.go b/pkg/kor/hpas.go index 572cdae7..27876713 100644 --- a/pkg/kor/hpas.go +++ b/pkg/kor/hpas.go @@ -12,6 +12,7 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth/oidc" "k8s.io/utils/strings/slices" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -80,7 +81,7 @@ func processNamespaceHpas(clientset kubernetes.Interface, namespace string, filt return unusedHpas, nil } -func GetUnusedHpas(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedHpas(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff, err := processNamespaceHpas(clientset, namespace, filterOpts) diff --git a/pkg/kor/hpas_test.go b/pkg/kor/hpas_test.go index b566edf7..786e19fd 100644 --- a/pkg/kor/hpas_test.go +++ b/pkg/kor/hpas_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -83,7 +84,7 @@ func TestExtractUnusedHpas(t *testing.T) { func TestGetUnusedHpasStructured(t *testing.T) { clientset := createTestHpas(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/ingresses.go b/pkg/kor/ingresses.go index f73b070d..11951b3f 100644 --- a/pkg/kor/ingresses.go +++ b/pkg/kor/ingresses.go @@ -12,6 +12,7 @@ import ( "k8s.io/client-go/kubernetes" _ "k8s.io/client-go/plugin/pkg/client/auth/oidc" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -116,7 +117,7 @@ func processNamespaceIngresses(clientset kubernetes.Interface, namespace string, } -func GetUnusedIngresses(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedIngresses(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff, err := processNamespaceIngresses(clientset, namespace, filterOpts) diff --git a/pkg/kor/ingresses_test.go b/pkg/kor/ingresses_test.go index 53983102..c1735896 100644 --- a/pkg/kor/ingresses_test.go +++ b/pkg/kor/ingresses_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -81,7 +82,7 @@ func TestRetrieveUsedIngress(t *testing.T) { func TestGetUnusedIngressesStructured(t *testing.T) { clientset := createTestIngresses(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/jobs.go b/pkg/kor/jobs.go index f203e547..d25757f3 100644 --- a/pkg/kor/jobs.go +++ b/pkg/kor/jobs.go @@ -12,6 +12,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -65,7 +66,7 @@ func processNamespaceJobs(clientset kubernetes.Interface, namespace string, filt return unusedJobNames, nil } -func GetUnusedJobs(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedJobs(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff, err := processNamespaceJobs(clientset, namespace, filterOpts) diff --git a/pkg/kor/jobs_test.go b/pkg/kor/jobs_test.go index 5a895954..557f6799 100644 --- a/pkg/kor/jobs_test.go +++ b/pkg/kor/jobs_test.go @@ -15,6 +15,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -112,7 +113,7 @@ func TestProcessNamespaceJobs(t *testing.T) { func TestGetUnusedJobsStructured(t *testing.T) { clientset := createTestJobs(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/kor.go b/pkg/kor/kor.go index 5e65a0e1..2be6a72a 100644 --- a/pkg/kor/kor.go +++ b/pkg/kor/kor.go @@ -41,17 +41,6 @@ type Config struct { // Add other configurations if needed } -type Opts struct { - DeleteFlag bool - NoInteractive bool - Verbose bool - WebhookURL string - Channel string - Token string - GroupBy string - ShowReason bool -} - func RemoveDuplicatesAndSort(slice []string) []string { uniqueSet := make(map[string]bool) for _, item := range slice { diff --git a/pkg/kor/multi.go b/pkg/kor/multi.go index 2d29c0e1..38aa5b9e 100644 --- a/pkg/kor/multi.go +++ b/pkg/kor/multi.go @@ -11,6 +11,7 @@ import ( "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -96,7 +97,7 @@ func retrieveNamespaceDiffs(clientset kubernetes.Interface, namespace string, re return allDiffs } -func GetUnusedMulti(resourceNames string, filterOpts *filters.Options, clientset kubernetes.Interface, apiExtClient apiextensionsclientset.Interface, dynamicClient dynamic.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedMulti(resourceNames string, filterOpts *filters.Options, clientset kubernetes.Interface, apiExtClient apiextensionsclientset.Interface, dynamicClient dynamic.Interface, outputFormat string, opts common.Opts) (string, error) { resourceList := strings.Split(resourceNames, ",") namespaces := filterOpts.Namespaces(clientset) resources := make(map[string]map[string][]ResourceInfo) diff --git a/pkg/kor/networkpolicies.go b/pkg/kor/networkpolicies.go index 560a09b5..71a975ac 100644 --- a/pkg/kor/networkpolicies.go +++ b/pkg/kor/networkpolicies.go @@ -13,6 +13,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -161,7 +162,7 @@ func processNamespaceNetworkPolicies(clientset kubernetes.Interface, namespace s return unusedNetpols, nil } -func GetUnusedNetworkPolicies(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedNetworkPolicies(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff --git a/pkg/kor/networkpolicies_test.go b/pkg/kor/networkpolicies_test.go index d689a0b8..3e0c39d4 100644 --- a/pkg/kor/networkpolicies_test.go +++ b/pkg/kor/networkpolicies_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -231,7 +232,7 @@ func TestProcessNamespaceNetworkPolicies(t *testing.T) { func TestGetUnusedNetworkPolicies(t *testing.T) { clientset := createTestNetworkPolicies(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/pdbs.go b/pkg/kor/pdbs.go index 3836a16a..c7001458 100644 --- a/pkg/kor/pdbs.go +++ b/pkg/kor/pdbs.go @@ -12,6 +12,7 @@ import ( "k8s.io/client-go/kubernetes" _ "k8s.io/client-go/plugin/pkg/client/auth/oidc" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -81,7 +82,7 @@ func processNamespacePdbs(clientset kubernetes.Interface, namespace string, filt return unusedPdbs, nil } -func GetUnusedPdbs(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedPdbs(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff, err := processNamespacePdbs(clientset, namespace, filterOpts) diff --git a/pkg/kor/pdbs_test.go b/pkg/kor/pdbs_test.go index 8f2b6b8c..d9183656 100644 --- a/pkg/kor/pdbs_test.go +++ b/pkg/kor/pdbs_test.go @@ -10,6 +10,7 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/fake" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -93,7 +94,7 @@ func TestProcessNamespacePdbs(t *testing.T) { func TestGetUnusedPdbsStructured(t *testing.T) { clientset := createTestPdbs(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/pods.go b/pkg/kor/pods.go index 70e1740c..8a1f0aa6 100644 --- a/pkg/kor/pods.go +++ b/pkg/kor/pods.go @@ -11,6 +11,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -43,7 +44,7 @@ func processNamespacePods(clientset kubernetes.Interface, namespace string, filt return evictedPods, nil } -func GetUnusedPods(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedPods(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff, err := processNamespacePods(clientset, namespace, filterOpts) diff --git a/pkg/kor/pods_test.go b/pkg/kor/pods_test.go index 3cab1466..a13ef96e 100644 --- a/pkg/kor/pods_test.go +++ b/pkg/kor/pods_test.go @@ -12,6 +12,7 @@ import ( fake "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -115,7 +116,7 @@ func TestProcessNamespacePods(t *testing.T) { func TestGetUnusedPodsStructured(t *testing.T) { clientset := createTestPods(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/pv.go b/pkg/kor/pv.go index e9419c62..440cf001 100644 --- a/pkg/kor/pv.go +++ b/pkg/kor/pv.go @@ -11,6 +11,7 @@ import ( "k8s.io/client-go/kubernetes" _ "k8s.io/client-go/plugin/pkg/client/auth/oidc" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -44,7 +45,7 @@ func processPvs(clientset kubernetes.Interface, filterOpts *filters.Options) ([] } -func GetUnusedPvs(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedPvs(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) diff, err := processPvs(clientset, filterOpts) if err != nil { diff --git a/pkg/kor/pv_test.go b/pkg/kor/pv_test.go index d69e1603..189d7c80 100644 --- a/pkg/kor/pv_test.go +++ b/pkg/kor/pv_test.go @@ -9,6 +9,7 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/fake" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -61,7 +62,7 @@ func TestProcessPvs(t *testing.T) { func TestGetUnusedPvs(t *testing.T) { clientset := createTestPvs(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/pvc.go b/pkg/kor/pvc.go index 01054ee7..33ad1702 100644 --- a/pkg/kor/pvc.go +++ b/pkg/kor/pvc.go @@ -11,6 +11,7 @@ import ( "k8s.io/client-go/kubernetes" _ "k8s.io/client-go/plugin/pkg/client/auth/oidc" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -72,7 +73,7 @@ func processNamespacePvcs(clientset kubernetes.Interface, namespace string, filt return diff, nil } -func GetUnusedPvcs(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedPvcs(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff, err := processNamespacePvcs(clientset, namespace, filterOpts) diff --git a/pkg/kor/pvc_test.go b/pkg/kor/pvc_test.go index 6547a018..2abdcf76 100644 --- a/pkg/kor/pvc_test.go +++ b/pkg/kor/pvc_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -99,7 +100,7 @@ func TestProcessNamespacePvcs(t *testing.T) { func TestGetUnusedPvcsStructured(t *testing.T) { clientset := createTestPvcs(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/replicaset.go b/pkg/kor/replicaset.go index 1dab7985..96e1ece8 100644 --- a/pkg/kor/replicaset.go +++ b/pkg/kor/replicaset.go @@ -10,6 +10,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -36,7 +37,7 @@ func processNamespaceReplicaSets(clientset kubernetes.Interface, namespace strin return unusedReplicaSetNames, nil } -func GetUnusedReplicaSets(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedReplicaSets(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff, err := processNamespaceReplicaSets(clientset, namespace, filterOpts) diff --git a/pkg/kor/replicaset_test.go b/pkg/kor/replicaset_test.go index 1f7c2910..2c4ca9d9 100644 --- a/pkg/kor/replicaset_test.go +++ b/pkg/kor/replicaset_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -57,7 +58,7 @@ func createTestReplicaSets(t *testing.T) *fake.Clientset { func TestProcessNamespaceReplicaSets(t *testing.T) { clientset := createTestReplicaSets(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/roles.go b/pkg/kor/roles.go index 3fe837ad..71b86940 100644 --- a/pkg/kor/roles.go +++ b/pkg/kor/roles.go @@ -12,6 +12,7 @@ import ( "k8s.io/client-go/kubernetes" _ "k8s.io/client-go/plugin/pkg/client/auth/oidc" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -101,7 +102,7 @@ func processNamespaceRoles(clientset kubernetes.Interface, namespace string, fil return diff, nil } -func GetUnusedRoles(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedRoles(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff, err := processNamespaceRoles(clientset, namespace, filterOpts) diff --git a/pkg/kor/roles_test.go b/pkg/kor/roles_test.go index 05143bf0..f424d1b0 100644 --- a/pkg/kor/roles_test.go +++ b/pkg/kor/roles_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -109,7 +110,7 @@ func TestProcessNamespaceRoles(t *testing.T) { func TestGetUnusedRolesStructured(t *testing.T) { clientset := createTestRoles(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/secrets.go b/pkg/kor/secrets.go index 107ce985..270e7b94 100644 --- a/pkg/kor/secrets.go +++ b/pkg/kor/secrets.go @@ -13,6 +13,7 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth/oidc" "k8s.io/utils/strings/slices" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -195,7 +196,7 @@ func processNamespaceSecret(clientset kubernetes.Interface, namespace string, fi } -func GetUnusedSecrets(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedSecrets(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff, err := processNamespaceSecret(clientset, namespace, filterOpts) diff --git a/pkg/kor/secrets_test.go b/pkg/kor/secrets_test.go index cbe066b7..7873b113 100644 --- a/pkg/kor/secrets_test.go +++ b/pkg/kor/secrets_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -276,7 +277,7 @@ func TestProcessNamespaceSecret(t *testing.T) { func TestGetUnusedSecretsStructured(t *testing.T) { clientset := createTestSecrets(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/serviceaccounts.go b/pkg/kor/serviceaccounts.go index 0ee2866a..4ccb765f 100644 --- a/pkg/kor/serviceaccounts.go +++ b/pkg/kor/serviceaccounts.go @@ -11,6 +11,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -163,7 +164,7 @@ func processNamespaceSA(clientset kubernetes.Interface, namespace string, filter return unusedServiceAccounts, nil } -func GetUnusedServiceAccounts(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedServiceAccounts(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff, err := processNamespaceSA(clientset, namespace, filterOpts) diff --git a/pkg/kor/serviceaccounts_test.go b/pkg/kor/serviceaccounts_test.go index 3458fda5..cf906c1e 100644 --- a/pkg/kor/serviceaccounts_test.go +++ b/pkg/kor/serviceaccounts_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -184,7 +185,7 @@ func TestGetUnusedServiceAccountsStructured(t *testing.T) { t.Fatalf("Error creating fake %s: %v", "clusterRoleBinding", err) } - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/services.go b/pkg/kor/services.go index 13e09036..6b1128a2 100644 --- a/pkg/kor/services.go +++ b/pkg/kor/services.go @@ -11,6 +11,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -59,7 +60,7 @@ func processNamespaceServices(clientset kubernetes.Interface, namespace string, return endpointsWithoutSubsets, nil } -func GetUnusedServices(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedServices(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff --git a/pkg/kor/services_test.go b/pkg/kor/services_test.go index 9acf854b..eb017f5d 100644 --- a/pkg/kor/services_test.go +++ b/pkg/kor/services_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -74,7 +75,7 @@ func TestGetEndpointsWithoutSubsets(t *testing.T) { func TestGetUnusedServicesStructured(t *testing.T) { clientset := createTestServices(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/statefulsets.go b/pkg/kor/statefulsets.go index 0bc88415..2398957f 100644 --- a/pkg/kor/statefulsets.go +++ b/pkg/kor/statefulsets.go @@ -10,6 +10,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -43,7 +44,7 @@ func processNamespaceStatefulSets(clientset kubernetes.Interface, namespace stri return statefulSetsWithoutReplicas, nil } -func GetUnusedStatefulSets(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedStatefulSets(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) for _, namespace := range filterOpts.Namespaces(clientset) { diff, err := processNamespaceStatefulSets(clientset, namespace, filterOpts) diff --git a/pkg/kor/statefulsets_test.go b/pkg/kor/statefulsets_test.go index 249821b1..d2f5c2ce 100644 --- a/pkg/kor/statefulsets_test.go +++ b/pkg/kor/statefulsets_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/scheme" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -74,7 +75,7 @@ func TestProcessNamespaceStatefulSets(t *testing.T) { func TestGetUnusedStatefulSetsStructured(t *testing.T) { clientset := createTestStatefulSets(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/storageclasses.go b/pkg/kor/storageclasses.go index 8e3a3307..43df4f8c 100644 --- a/pkg/kor/storageclasses.go +++ b/pkg/kor/storageclasses.go @@ -12,6 +12,7 @@ import ( "k8s.io/client-go/kubernetes" _ "k8s.io/client-go/plugin/pkg/client/auth/oidc" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -98,7 +99,7 @@ func processStorageClasses(clientset kubernetes.Interface, filterOpts *filters.O return unusedStorageClasses, nil } -func GetUnusedStorageClasses(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts Opts) (string, error) { +func GetUnusedStorageClasses(filterOpts *filters.Options, clientset kubernetes.Interface, outputFormat string, opts common.Opts) (string, error) { resources := make(map[string]map[string][]ResourceInfo) diff, err := processStorageClasses(clientset, filterOpts) if err != nil { diff --git a/pkg/kor/storageclasses_test.go b/pkg/kor/storageclasses_test.go index 8df66efa..95eba164 100644 --- a/pkg/kor/storageclasses_test.go +++ b/pkg/kor/storageclasses_test.go @@ -9,6 +9,7 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/fake" + "github.com/yonahd/kor/pkg/common" "github.com/yonahd/kor/pkg/filters" ) @@ -69,7 +70,7 @@ func TestProcessStorageClasses(t *testing.T) { func TestGetUnusedStorageClassesStructured(t *testing.T) { clientset := createTestStorageClass(t) - opts := Opts{ + opts := common.Opts{ WebhookURL: "", Channel: "", Token: "", diff --git a/pkg/kor/slack.go b/pkg/utils/slack.go similarity index 89% rename from pkg/kor/slack.go rename to pkg/utils/slack.go index 8bb3cb6d..9d582c5f 100644 --- a/pkg/kor/slack.go +++ b/pkg/utils/slack.go @@ -1,4 +1,4 @@ -package kor +package utils import ( "bytes" @@ -9,20 +9,22 @@ import ( "net/http" "os" "path/filepath" + + "github.com/yonahd/kor/pkg/common" ) type SendMessageToSlack interface { - SendToSlack(opts Opts, outputBuffer string) error + SendToSlack(opts common.Opts, outputBuffer string) error } type SlackMessage struct { } -func SendToSlack(sm SendMessageToSlack, opts Opts, outputBuffer string) error { +func SendToSlack(sm SendMessageToSlack, opts common.Opts, outputBuffer string) error { return sm.SendToSlack(opts, outputBuffer) } -func (sm SlackMessage) SendToSlack(opts Opts, outputBuffer string) error { +func (sm SlackMessage) SendToSlack(opts common.Opts, outputBuffer string) error { if opts.WebhookURL != "" { payload := []byte(`{"text": "` + outputBuffer + `"}`) _, err := http.Post(opts.WebhookURL, "application/json", bytes.NewBuffer(payload)) diff --git a/pkg/kor/slack_test.go b/pkg/utils/slack_test.go similarity index 91% rename from pkg/kor/slack_test.go rename to pkg/utils/slack_test.go index f19b5389..ff82ca40 100644 --- a/pkg/kor/slack_test.go +++ b/pkg/utils/slack_test.go @@ -1,4 +1,4 @@ -package kor +package utils import ( "bytes" @@ -6,25 +6,27 @@ import ( "net/http/httptest" "os" "testing" + + "github.com/yonahd/kor/pkg/common" ) type SendToSlackTestCase struct { Name string - Opts Opts + Opts common.Opts OutputBuffer string } var testCases = []SendToSlackTestCase{ { Name: "Test using WebhookURL", - Opts: Opts{ + Opts: common.Opts{ WebhookURL: "slack.webhookurl.com", }, OutputBuffer: "Test message", }, { Name: "Test using Channel and Token", - Opts: Opts{ + Opts: common.Opts{ Channel: "your_channel", Token: "your_token", }, @@ -32,7 +34,7 @@ var testCases = []SendToSlackTestCase{ }, { Name: "Test with empty Opts", - Opts: Opts{}, + Opts: common.Opts{}, OutputBuffer: "Test message", }, }