Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistent naming of resource types #72

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/kor/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

var configmapCmd = &cobra.Command{
Use: "configmap",
Aliases: []string{"cm"},
Aliases: []string{"cm", "configmaps"},
Short: "Gets unused configmaps",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/kor/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

var deployCmd = &cobra.Command{
Use: "deployments",
Aliases: []string{"deploy"},
Use: "deployment",
Aliases: []string{"deploy", "deployments"},
Short: "Gets unused deployments",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
Expand Down
7 changes: 4 additions & 3 deletions cmd/kor/hpas.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
)

var hpaCmd = &cobra.Command{
Use: "hpa",
Short: "Gets unused hpas",
Args: cobra.NoArgs,
Use: "horizontalpodautoscaler",
Aliases: []string{"hpa", "horizontalpodautoscalers"},
Short: "Gets unused hpas",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
if outputFormat == "json" || outputFormat == "yaml" {
if response, err := kor.GetUnusedHpasStructured(includeExcludeLists, kubeconfig, outputFormat); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/kor/ingresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

var ingressCmd = &cobra.Command{
Use: "ingress",
Aliases: []string{"ing"},
Aliases: []string{"ing", "ingresses"},
Short: "Gets unused ingresses",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
Expand Down
7 changes: 4 additions & 3 deletions cmd/kor/pdbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
)

var pdbCmd = &cobra.Command{
Use: "pdb",
Short: "Gets unused pdbs",
Args: cobra.NoArgs,
Use: "poddisruptionbudget",
Aliases: []string{"pdb", "poddisruptionbudgets"},
Short: "Gets unused pdbs",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
if outputFormat == "json" || outputFormat == "yaml" {
if response, err := kor.GetUnusedPdbsStructured(includeExcludeLists, kubeconfig, outputFormat); err != nil {
Expand Down
7 changes: 4 additions & 3 deletions cmd/kor/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
)

var pvcCmd = &cobra.Command{
Use: "pvc",
Short: "Gets unused pvcs",
Args: cobra.NoArgs,
Use: "persistentvolumeclaim",
Aliases: []string{"pvc", "persistentvolumeclaims"},
Short: "Gets unused pvcs",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
if outputFormat == "json" || outputFormat == "yaml" {
if response, err := kor.GetUnusedPvcsStructured(includeExcludeLists, kubeconfig, outputFormat); err != nil {
Expand Down
7 changes: 4 additions & 3 deletions cmd/kor/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
)

var roleCmd = &cobra.Command{
Use: "role",
Short: "Gets unused roles",
Args: cobra.NoArgs,
Use: "role",
Aliases: []string{"roles"},
Short: "Gets unused roles",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
if outputFormat == "json" || outputFormat == "yaml" {
if response, err := kor.GetUnusedRolesStructured(includeExcludeLists, kubeconfig, outputFormat); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/kor/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var rootCmd = &cobra.Command{
} else {
kor.GetUnusedMulti(includeExcludeLists, kubeconfig, resourceNames)
}
} else {
fmt.Printf("Subcommand %q was not found, try using 'kor --help' for available subcommands", args[0])
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kor/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

var secretCmd = &cobra.Command{
Use: "secret",
Aliases: []string{"scrt"},
Aliases: []string{"scrt", "secrets"},
Short: "Gets unused secrets",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/kor/serviceaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

var serviceAccountCmd = &cobra.Command{
Use: "serviceaccount",
Aliases: []string{"sa"},
Aliases: []string{"sa", "serviceaccounts"},
Short: "Gets unused service accounts",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/kor/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

var serviceCmd = &cobra.Command{
Use: "services",
Aliases: []string{"svc"},
Use: "service",
Aliases: []string{"svc", "services"},
Short: "Gets unused services",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/kor/statefulsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

var stsCmd = &cobra.Command{
Use: "statefulsets",
Aliases: []string{"sts"},
Use: "statefulset",
Aliases: []string{"sts", "statefulsets"},
Short: "Gets unused statefulsets",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
Expand Down
22 changes: 12 additions & 10 deletions pkg/kor/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,41 @@ func retrieveNamespaceDiffs(kubeClient *kubernetes.Clientset, namespace string,
var allDiffs []ResourceDiff
for _, resource := range resourceList {
switch resource {
case "cm", "configmap":
case "cm", "configmap", "configmaps":
namespaceCMDiff := getUnusedCMs(kubeClient, namespace)
allDiffs = append(allDiffs, namespaceCMDiff)
case "svc", "service", "services":
namespaceSVCDiff := getUnusedSVCs(kubeClient, namespace)
allDiffs = append(allDiffs, namespaceSVCDiff)
case "scrt", "secret":
case "scrt", "secret", "secrets":
namespaceSecretDiff := getUnusedSecrets(kubeClient, namespace)
allDiffs = append(allDiffs, namespaceSecretDiff)
case "sa", "serviceaccount":
case "sa", "serviceaccount", "serviceaccounts":
namespaceSADiff := getUnusedServiceAccounts(kubeClient, namespace)
allDiffs = append(allDiffs, namespaceSADiff)
case "deploy", "deployments":
case "deploy", "deployment", "deployments":
namespaceDeploymentDiff := getUnusedDeployments(kubeClient, namespace)
allDiffs = append(allDiffs, namespaceDeploymentDiff)
case "sts", "statefulsets":
case "sts", "statefulset", "statefulsets":
namespaceStatefulsetDiff := getUnusedStatefulsets(kubeClient, namespace)
allDiffs = append(allDiffs, namespaceStatefulsetDiff)
case "role":
case "role", "roles":
namespaceRoleDiff := getUnusedRoles(kubeClient, namespace)
allDiffs = append(allDiffs, namespaceRoleDiff)
case "hpa":
case "hpa", "horizontalpodautoscaler", "horizontalpodautoscalers":
namespaceHpaDiff := getUnusedHpas(kubeClient, namespace)
allDiffs = append(allDiffs, namespaceHpaDiff)
case "pvc":
case "pvc", "persistentvolumeclaim", "persistentvolumeclaims":
namespacePvcDiff := getUnusedPvcs(kubeClient, namespace)
allDiffs = append(allDiffs, namespacePvcDiff)
case "ing", "ingress":
case "ing", "ingress", "ingresses":
namespaceIngressDiff := getUnusedIngresses(kubeClient, namespace)
allDiffs = append(allDiffs, namespaceIngressDiff)
case "pdb":
case "pdb", "poddisruptionbudget", "poddisruptionbudgets":
namespacePdbDiff := getUnusedPdbs(kubeClient, namespace)
allDiffs = append(allDiffs, namespacePdbDiff)
default:
fmt.Printf("resource type %q is not supported\n", resource)
}
}
return allDiffs
Expand Down