...

Source file src/github.com/linkerd/linkerd2/viz/cmd/root.go

Documentation: github.com/linkerd/linkerd2/viz/cmd

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  	"regexp"
     6  
     7  	"github.com/fatih/color"
     8  	pkgcmd "github.com/linkerd/linkerd2/pkg/cmd"
     9  	"github.com/linkerd/linkerd2/pkg/healthcheck"
    10  	log "github.com/sirupsen/logrus"
    11  	"github.com/spf13/cobra"
    12  )
    13  
    14  const (
    15  	// ExtensionName is the value that the viz extension resources should be labeled with
    16  	ExtensionName = "viz"
    17  
    18  	// LegacyExtensionName is the value that the viz extension resources were labeled with
    19  	// until 15d1809bd043192bb21cacbc96112cce35bf384f
    20  	LegacyExtensionName = "linkerd-viz"
    21  
    22  	vizChartName            = "linkerd-viz"
    23  	defaultNamespace        = "linkerd-viz"
    24  	defaultLinkerdNamespace = "linkerd"
    25  	maxRps                  = 100.0
    26  
    27  	jsonOutput     = healthcheck.JSONOutput
    28  	tableOutput    = healthcheck.TableOutput
    29  	wideOutput     = healthcheck.WideOutput
    30  	jsonPathOutput = "jsonpath"
    31  )
    32  
    33  var (
    34  	// special handling for Windows, on all other platforms these resolve to
    35  	// os.Stdout and os.Stderr, thanks to https://github.com/mattn/go-colorable
    36  	stdout = color.Output
    37  	stderr = color.Error
    38  
    39  	apiAddr               string // An empty value means "use the Kubernetes configuration"
    40  	controlPlaneNamespace string
    41  	kubeconfigPath        string
    42  	kubeContext           string
    43  	vizNamespace          string
    44  	impersonate           string
    45  	impersonateGroup      []string
    46  	verbose               bool
    47  
    48  	// These regexs are not as strict as they could be, but are a quick and dirty
    49  	// sanity check against illegal characters.
    50  	alphaNumDash = regexp.MustCompile(`^[a-zA-Z0-9-]+$`)
    51  )
    52  
    53  // NewCmdViz returns a new jaeger command
    54  func NewCmdViz() *cobra.Command {
    55  	vizCmd := &cobra.Command{
    56  		Use:   "viz",
    57  		Short: "viz manages the linkerd-viz extension of Linkerd service mesh",
    58  		Long:  `viz manages the linkerd-viz extension of Linkerd service mesh.`,
    59  		PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
    60  			// enable / disable logging
    61  			if verbose {
    62  				log.SetLevel(log.DebugLevel)
    63  			} else {
    64  				log.SetLevel(log.PanicLevel)
    65  			}
    66  
    67  			if !alphaNumDash.MatchString(controlPlaneNamespace) {
    68  				return fmt.Errorf("%s is not a valid namespace", controlPlaneNamespace)
    69  			}
    70  
    71  			return nil
    72  		},
    73  	}
    74  
    75  	vizCmd.PersistentFlags().StringVarP(&controlPlaneNamespace, "linkerd-namespace", "L", defaultLinkerdNamespace, "Namespace in which Linkerd is installed")
    76  	vizCmd.PersistentFlags().StringVar(&kubeconfigPath, "kubeconfig", "", "Path to the kubeconfig file to use for CLI requests")
    77  	vizCmd.PersistentFlags().StringVar(&kubeContext, "context", "", "Name of the kubeconfig context to use")
    78  	vizCmd.PersistentFlags().StringVar(&impersonate, "as", "", "Username to impersonate for Kubernetes operations")
    79  	vizCmd.PersistentFlags().StringArrayVar(&impersonateGroup, "as-group", []string{}, "Group to impersonate for Kubernetes operations")
    80  	vizCmd.PersistentFlags().StringVar(&apiAddr, "api-addr", "", "Override kubeconfig and communicate directly with the control plane at host:port (mostly for testing)")
    81  	vizCmd.PersistentFlags().StringVar(&vizNamespace, "viz-namespace", "", "Name of the linkerd-viz namespace. If not set, it's automatically detected")
    82  	vizCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "Turn on debug logging")
    83  	vizCmd.AddCommand(NewCmdAuthz())
    84  	vizCmd.AddCommand(NewCmdCheck())
    85  	vizCmd.AddCommand(NewCmdDashboard())
    86  	vizCmd.AddCommand(NewCmdEdges())
    87  	vizCmd.AddCommand(newCmdInstall())
    88  	vizCmd.AddCommand(newCmdList())
    89  	vizCmd.AddCommand(newCmdProfile())
    90  	vizCmd.AddCommand(NewCmdRoutes())
    91  	vizCmd.AddCommand(NewCmdStat())
    92  	vizCmd.AddCommand(NewCmdTap())
    93  	vizCmd.AddCommand(NewCmdTop())
    94  	vizCmd.AddCommand(newCmdUninstall())
    95  	vizCmd.AddCommand(newCmdAllowScrapes())
    96  	vizCmd.AddCommand(newCmdPrune())
    97  
    98  	// resource-aware completion flag configurations
    99  	pkgcmd.ConfigureNamespaceFlagCompletion(
   100  		vizCmd, []string{"linkerd-namespace"},
   101  		kubeconfigPath, impersonate, impersonateGroup, kubeContext)
   102  
   103  	pkgcmd.ConfigureKubeContextFlagCompletion(vizCmd, kubeconfigPath)
   104  	return vizCmd
   105  }
   106  

View as plain text