package cmd import ( "fmt" "regexp" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) const ( vizChartName = "linkerd-viz" defaultLinkerdNamespace = "linkerd" defaultVizNamespace = "linkerd-viz" ) var ( apiAddr string // An empty value means "use the Kubernetes configuration" controlPlaneNamespace string namespace string kubeconfigPath string kubeContext string impersonate string impersonateGroup []string verbose bool // These regexs are not as strict as they could be, but are a quick and dirty // sanity check against illegal characters. alphaNumDash = regexp.MustCompile(`^[a-zA-Z0-9-]+$`) ) // NewCmdViz returns a new jeager command func NewCmdViz() *cobra.Command { vizCmd := &cobra.Command{ Use: "viz", Short: "viz manages the linkerd-viz extension of Linkerd service mesh", Long: `viz manages the linkerd-viz extension of Linkerd service mesh.`, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { // enable / disable logging if verbose { log.SetLevel(log.DebugLevel) } else { log.SetLevel(log.PanicLevel) } if !alphaNumDash.MatchString(controlPlaneNamespace) { return fmt.Errorf("%s is not a valid namespace", controlPlaneNamespace) } return nil }, } vizCmd.PersistentFlags().StringVarP(&controlPlaneNamespace, "linkerd-namespace", "L", defaultLinkerdNamespace, "Namespace in which Linkerd is installed") vizCmd.PersistentFlags().StringVarP(&namespace, "namespace", "n", defaultVizNamespace, "Namespace in which viz extension is installed") vizCmd.PersistentFlags().StringVar(&kubeconfigPath, "kubeconfig", "", "Path to the kubeconfig file to use for CLI requests") vizCmd.PersistentFlags().StringVar(&kubeContext, "context", "", "Name of the kubeconfig context to use") vizCmd.PersistentFlags().StringVar(&impersonate, "as", "", "Username to impersonate for Kubernetes operations") vizCmd.PersistentFlags().StringArrayVar(&impersonateGroup, "as-group", []string{}, "Group to impersonate for Kubernetes operations") vizCmd.PersistentFlags().StringVar(&apiAddr, "api-addr", "", "Override kubeconfig and communicate directly with the control plane at host:port (mostly for testing)") vizCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "Turn on debug logging") vizCmd.AddCommand(newCmdInstall()) vizCmd.AddCommand(newCmdUninstall()) return vizCmd }