This repository has been archived by the owner on Sep 16, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move deprecation logic to "deprecation list"
Signed-off-by: Christian Kotzbauer <christian.kotzbauer@gmail.com>
- Loading branch information
1 parent
16d5fca
commit 0a8acf2
Showing
4 changed files
with
64 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,19 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/ckotzbauer/chekr/pkg/deprecation" | ||
"github.com/ckotzbauer/chekr/pkg/kubernetes" | ||
"github.com/ckotzbauer/chekr/pkg/printer" | ||
"github.com/ckotzbauer/chekr/cmd/deprecation" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// deprecationCmd represents the deprecation command | ||
var deprecationCmd = &cobra.Command{ | ||
Use: "deprecation", | ||
Short: "Lists deprecated objects in cluster.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
namespace, _ := cmd.Flags().GetString("namespace") | ||
k8sVersion, _ := cmd.Flags().GetString("k8s-version") | ||
ignoredKinds, _ := cmd.Flags().GetStringSlice("ignored-kinds") | ||
throttleBurst, _ := cmd.Flags().GetInt("throttle-burst") | ||
|
||
r := deprecation.Deprecation{ | ||
KubeOverrides: overrides, | ||
KubeClient: kubernetes.NewClient(cmd, overrides), | ||
Namespace: namespace, | ||
K8sVersion: k8sVersion, | ||
IgnoredKinds: ignoredKinds, | ||
ThrottleBurst: throttleBurst, | ||
} | ||
|
||
list := r.Execute() | ||
|
||
output, _ := cmd.Flags().GetString("output") | ||
outputFile, _ := cmd.Flags().GetString("output-file") | ||
omitExitCode, _ := cmd.Flags().GetBool("omit-exit-code") | ||
|
||
printer := printer.Printer{Type: output, File: outputFile} | ||
printer.Print(list) | ||
|
||
items := list.(deprecation.DeprecatedResourceList) | ||
if len(items.Items) > 0 && !omitExitCode { | ||
os.Exit(1) | ||
} | ||
}, | ||
Short: "Handle deprecated objects in cluster.", | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(deprecationCmd) | ||
deprecationCmd.Flags().StringP("k8s-version", "V", "", "Highest K8s major.minor version to show deprecations for (e.g. 1.21)") | ||
deprecationCmd.Flags().StringSliceP("ignored-kinds", "i", []string{}, "All kinds you want to ignore (e.g. Deployment,DaemonSet)") | ||
deprecationCmd.Flags().IntP("throttle-burst", "t", 100, "Burst used for throttling of Kubernetes discovery-client") | ||
deprecationCmd.Flags().Bool("omit-exit-code", false, "Omits the non-zero exit code if deprecations were found.") | ||
|
||
deprecation.InitListCmd(deprecationCmd, overrides) | ||
// Output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package deprecation | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/ckotzbauer/chekr/pkg/deprecation" | ||
"github.com/ckotzbauer/chekr/pkg/kubernetes" | ||
"github.com/ckotzbauer/chekr/pkg/printer" | ||
"github.com/spf13/cobra" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
func createListCmd(overrides *clientcmd.ConfigOverrides) *cobra.Command { | ||
// listCmd represents the deprecation list command | ||
listCmd := &cobra.Command{ | ||
Use: "list", | ||
Short: "Lists deprecated objects in cluster.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
k8sVersion, _ := cmd.Flags().GetString("k8s-version") | ||
ignoredKinds, _ := cmd.Flags().GetStringSlice("ignored-kinds") | ||
throttleBurst, _ := cmd.Flags().GetInt("throttle-burst") | ||
|
||
r := deprecation.Deprecation{ | ||
KubeOverrides: overrides, | ||
KubeClient: kubernetes.NewClient(cmd, overrides), | ||
K8sVersion: k8sVersion, | ||
IgnoredKinds: ignoredKinds, | ||
ThrottleBurst: throttleBurst, | ||
} | ||
|
||
list := r.Execute() | ||
|
||
output, _ := cmd.Flags().GetString("output") | ||
outputFile, _ := cmd.Flags().GetString("output-file") | ||
omitExitCode, _ := cmd.Flags().GetBool("omit-exit-code") | ||
|
||
printer := printer.Printer{Type: output, File: outputFile} | ||
printer.Print(list) | ||
|
||
items := list.(deprecation.DeprecatedResourceList) | ||
if len(items.Items) > 0 && !omitExitCode { | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
listCmd.Flags().StringP("k8s-version", "V", "", "Highest K8s major.minor version to show deprecations for (e.g. 1.21)") | ||
listCmd.Flags().StringSliceP("ignored-kinds", "i", []string{}, "All kinds you want to ignore (e.g. Deployment,DaemonSet)") | ||
listCmd.Flags().Bool("omit-exit-code", false, "Omits the non-zero exit code if deprecations were found.") | ||
listCmd.Flags().IntP("throttle-burst", "t", 100, "Burst used for throttling of Kubernetes discovery-client") | ||
return listCmd | ||
} | ||
|
||
func InitListCmd(deprecationCmd *cobra.Command, overrides *clientcmd.ConfigOverrides) { | ||
deprecationCmd.AddCommand(createListCmd(overrides)) | ||
// Output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters