You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 9, 2021. It is now read-only.
// Initialize generate the clientset for paramsfunc (params*AdminParams) Initialize() error {
ifparams.ClientSet==nil {
restConfig, err:=params.RestConfig()
iferr!=nil {
returnerr
}
params.ClientSet, err=kubernetes.NewForConfig(restConfig)
iferr!=nil {
fmt.Println("failed to create client:", err)
os.Exit(1)
}
}
returnnil
}
// rootCmd represents the base command when called without any subcommandsfuncNewAdminCommand(params...pkg.AdminParams) *cobra.Command {
p:=&pkg.AdminParams{}
p.Initialize()
rootCmd:=&cobra.Command{
Use: "kn\u00A0admin",
Short: "A plugin of kn client to manage Knative",
Long: `kn admin: a plugin of kn client to manage Knative for administrators`,
...
I think we can do some improvements for the above functions so that we can avoid outputting runtime error if kubectl context is not set:
In Initialize(), we'd better return error when fail to create ClientSet
In NewAdminCommand(), we should check the error from p.Initialize(), if error is returned, we can print the error message and exit to run command.
If the kubectl context is not set or run
kubectl config unset current-contextto unset it, we will get runtime error when runkn admin, for example:I checked the codes in
AdminParams:I think we can do some improvements for the above functions so that we can avoid outputting runtime error if kubectl context is not set:
Initialize(), we'd better return error when fail to createClientSetNewAdminCommand(), we should check the error fromp.Initialize(), if error is returned, we can print the error message and exit to run command.