optimize code

This commit is contained in:
p_caiwfeng
2021-10-20 15:12:30 +08:00
parent db39003e4f
commit cdb4f9a7d3
2 changed files with 5 additions and 5 deletions

View File

@@ -15,7 +15,7 @@ import (
var connect pkg.ConnectOptions
func init() {
connectCmd.Flags().StringVar(&connect.Kubeconfigpath, "kubeconfig", clientcmd.RecommendedHomeFile, "kubeconfig")
connectCmd.Flags().StringVar(&connect.KubeconfigPath, "kubeconfig", clientcmd.RecommendedHomeFile, "kubeconfig")
connectCmd.Flags().StringVarP(&connect.Namespace, "namespace", "n", "", "namespace")
connectCmd.PersistentFlags().StringArrayVar(&connect.Workloads, "workloads", []string{}, "workloads, like: services/tomcat, deployment/nginx, replicaset/tomcat...")
connectCmd.Flags().StringVar((*string)(&connect.Mode), "mode", string(pkg.Reverse), "default mode is reverse")

View File

@@ -30,11 +30,11 @@ const (
)
type ConnectOptions struct {
nodeConfig Route
Kubeconfigpath string
KubeconfigPath string
Namespace string
Mode Mode
Workloads []string
nodeConfig Route
clientset *kubernetes.Clientset
restclient *rest.RESTClient
config *rest.Config
@@ -265,7 +265,7 @@ func getCIDR(clientset *kubernetes.Clientset, namespace string) ([]*net.IPNet, e
func (c *ConnectOptions) InitClient() {
var err error
configFlags := genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag()
configFlags.KubeConfig = &c.Kubeconfigpath
configFlags.KubeConfig = &c.KubeconfigPath
c.factory = cmdutil.NewFactory(cmdutil.NewMatchVersionFlags(configFlags))
if c.config, err = c.factory.ToRESTConfig(); err != nil {
@@ -282,5 +282,5 @@ func (c *ConnectOptions) InitClient() {
log.Fatal(err)
}
}
log.Infof("kubeconfig path: %s, namespace: %s, serivces: %v", c.Kubeconfigpath, c.Namespace, c.Workloads)
log.Infof("kubeconfig path: %s, namespace: %s, serivces: %v", c.KubeconfigPath, c.Namespace, c.Workloads)
}