From baa4d10c2fffe362215800e045ecd1a84e8d02ed Mon Sep 17 00:00:00 2001 From: Kevin Lingerfelt Date: Fri, 6 Apr 2018 14:47:31 -0700 Subject: [PATCH] CLI: change conduit namespace shorthand flag to -c (#714) * CLI: change conduit namespace shorthand flag to -c All of the conduit CLI subcommands accept a --conduit-namespace flag, indicating the namespace where conduit is running. Some of the subcommands also provide a --namespace flag, indicating the kubernetes namespace where a user's application code is running. To prevent confusion, I'm changing the shorthand flag for the conduit namespace to -c, and using the -n shorthand when referring to user namespaces. As part of this change I've also standardized the capitalization of all of our command line flags, removed the -r shorthand for the install --registry flag, and made the global --kubeconfig and --api-addr flags apply to all subcommands. * Switch flag descriptions from lowercase to Capital Signed-off-by: Kevin Lingerfelt --- cli/cmd/check.go | 2 +- cli/cmd/dashboard.go | 7 +++---- cli/cmd/get.go | 1 - cli/cmd/inject.go | 18 +++++++++--------- cli/cmd/install.go | 10 +++++----- cli/cmd/root.go | 15 ++++----------- cli/cmd/stat.go | 3 +-- cli/cmd/stat_summary.go | 20 ++++++++------------ cli/cmd/tap.go | 1 - cli/cmd/version.go | 2 +- 10 files changed, 32 insertions(+), 47 deletions(-) diff --git a/cli/cmd/check.go b/cli/cmd/check.go index c74f4cd6e..50359eb72 100644 --- a/cli/cmd/check.go +++ b/cli/cmd/check.go @@ -122,6 +122,6 @@ func statusCheckResultWasError(w io.Writer) error { func init() { RootCmd.AddCommand(checkCmd) - addControlPlaneNetworkingArgs(checkCmd) + checkCmd.Args = cobra.NoArgs checkCmd.PersistentFlags().StringVar(&versionOverride, "expected-version", "", "Overrides the version used when checking if Conduit is running the latest version (mostly for testing)") } diff --git a/cli/cmd/dashboard.go b/cli/cmd/dashboard.go index f6dd8b5ed..894eed013 100644 --- a/cli/cmd/dashboard.go +++ b/cli/cmd/dashboard.go @@ -71,7 +71,7 @@ var dashboardCmd = &cobra.Command{ if err != nil || !dashboardAvailable { fmt.Fprintf(os.Stderr, "Conduit is not running in the \"%s\" namespace\n", controlPlaneNamespace) - fmt.Fprintf(os.Stderr, "Install with: conduit install -n %s | kubectl apply -f -\n", controlPlaneNamespace) + fmt.Fprintf(os.Stderr, "Install with: conduit install --conduit-namespace %s | kubectl apply -f -\n", controlPlaneNamespace) os.Exit(1) } @@ -126,11 +126,10 @@ func isDashboardAvailable(client pb.ApiClient) (bool, error) { func init() { RootCmd.AddCommand(dashboardCmd) - addControlPlaneNetworkingArgs(dashboardCmd) dashboardCmd.Args = cobra.NoArgs // This is identical to what `kubectl proxy --help` reports, `--port 0` // indicates a random port. - dashboardCmd.PersistentFlags().IntVarP(&dashboardProxyPort, "port", "p", 0, "The port on which to run the proxy. When set to 0, a random port will be used.") - dashboardCmd.PersistentFlags().StringVar(&dashboardShow, "show", "conduit", "Open a dashboard in a browser or show URLs in the CLI. Must be one of: conduit, grafana, url.") + dashboardCmd.PersistentFlags().IntVarP(&dashboardProxyPort, "port", "p", 0, "The port on which to run the proxy (when set to 0, a random port will be used)") + dashboardCmd.PersistentFlags().StringVar(&dashboardShow, "show", "conduit", "Open a dashboard in a browser or show URLs in the CLI (one of: conduit, grafana, url)") } diff --git a/cli/cmd/get.go b/cli/cmd/get.go index 847b5f8b9..7af7897b3 100644 --- a/cli/cmd/get.go +++ b/cli/cmd/get.go @@ -53,7 +53,6 @@ Only pod resources (aka pods, po) are supported.`, func init() { RootCmd.AddCommand(getCmd) - addControlPlaneNetworkingArgs(getCmd) } func getPods(apiClient pb.ApiClient) ([]string, error) { diff --git a/cli/cmd/inject.go b/cli/cmd/inject.go index 5c4319bec..01be14ec8 100644 --- a/cli/cmd/inject.go +++ b/cli/cmd/inject.go @@ -322,19 +322,19 @@ func init() { RootCmd.AddCommand(injectCmd) addProxyConfigFlags(injectCmd) injectCmd.PersistentFlags().StringVar(&initImage, "init-image", "gcr.io/runconduit/proxy-init", "Conduit init container image name") - injectCmd.PersistentFlags().UintVar(&inboundPort, "inbound-port", 4143, "proxy port to use for inbound traffic") - injectCmd.PersistentFlags().UintVar(&outboundPort, "outbound-port", 4140, "proxy port to use for outbound traffic") - injectCmd.PersistentFlags().UintSliceVar(&ignoreInboundPorts, "skip-inbound-ports", nil, "ports that should skip the proxy and send directly to the application") - injectCmd.PersistentFlags().UintSliceVar(&ignoreOutboundPorts, "skip-outbound-ports", nil, "outbound ports that should skip the proxy") + injectCmd.PersistentFlags().UintVar(&inboundPort, "inbound-port", 4143, "Proxy port to use for inbound traffic") + injectCmd.PersistentFlags().UintVar(&outboundPort, "outbound-port", 4140, "Proxy port to use for outbound traffic") + injectCmd.PersistentFlags().UintSliceVar(&ignoreInboundPorts, "skip-inbound-ports", nil, "Ports that should skip the proxy and send directly to the application") + injectCmd.PersistentFlags().UintSliceVar(&ignoreOutboundPorts, "skip-outbound-ports", nil, "Outbound ports that should skip the proxy") } func addProxyConfigFlags(cmd *cobra.Command) { - cmd.PersistentFlags().StringVarP(&conduitVersion, "conduit-version", "v", version.Version, "tag to be used for Conduit images") + cmd.PersistentFlags().StringVarP(&conduitVersion, "conduit-version", "v", version.Version, "Tag to be used for Conduit images") cmd.PersistentFlags().StringVar(&proxyImage, "proxy-image", "gcr.io/runconduit/proxy", "Conduit proxy container image name") cmd.PersistentFlags().StringVar(&imagePullPolicy, "image-pull-policy", "IfNotPresent", "Docker image pull policy") cmd.PersistentFlags().Int64Var(&proxyUID, "proxy-uid", 2102, "Run the proxy under this user ID") - cmd.PersistentFlags().StringVar(&proxyLogLevel, "proxy-log-level", "warn,conduit_proxy=info", "log level for the proxy") - cmd.PersistentFlags().UintVar(&proxyAPIPort, "api-port", 8086, "port where the Conduit controller is running") - cmd.PersistentFlags().UintVar(&proxyControlPort, "control-port", 4190, "proxy port to use for control") - cmd.PersistentFlags().UintVar(&proxyMetricsPort, "metrics-port", 4191, "proxy port to serve metrics on") + cmd.PersistentFlags().StringVar(&proxyLogLevel, "proxy-log-level", "warn,conduit_proxy=info", "Log level for the proxy") + cmd.PersistentFlags().UintVar(&proxyAPIPort, "api-port", 8086, "Port where the Conduit controller is running") + cmd.PersistentFlags().UintVar(&proxyControlPort, "control-port", 4190, "Proxy port to use for control") + cmd.PersistentFlags().UintVar(&proxyMetricsPort, "metrics-port", 4191, "Proxy port to serve metrics on") } diff --git a/cli/cmd/install.go b/cli/cmd/install.go index 05387b121..d810dbb33 100644 --- a/cli/cmd/install.go +++ b/cli/cmd/install.go @@ -118,9 +118,9 @@ func validate() error { func init() { RootCmd.AddCommand(installCmd) addProxyConfigFlags(installCmd) - installCmd.PersistentFlags().StringVarP(&dockerRegistry, "registry", "r", "gcr.io/runconduit", "Docker registry to pull images from") - installCmd.PersistentFlags().UintVar(&controllerReplicas, "controller-replicas", 1, "replicas of the controller to deploy") - installCmd.PersistentFlags().UintVar(&webReplicas, "web-replicas", 1, "replicas of the web server to deploy") - installCmd.PersistentFlags().UintVar(&prometheusReplicas, "prometheus-replicas", 1, "replicas of prometheus to deploy") - installCmd.PersistentFlags().StringVar(&controllerLogLevel, "controller-log-level", "info", "log level for the controller and web components") + installCmd.PersistentFlags().StringVar(&dockerRegistry, "registry", "gcr.io/runconduit", "Docker registry to pull images from") + installCmd.PersistentFlags().UintVar(&controllerReplicas, "controller-replicas", 1, "Replicas of the controller to deploy") + installCmd.PersistentFlags().UintVar(&webReplicas, "web-replicas", 1, "Replicas of the web server to deploy") + installCmd.PersistentFlags().UintVar(&prometheusReplicas, "prometheus-replicas", 1, "Replicas of prometheus to deploy") + installCmd.PersistentFlags().StringVar(&controllerLogLevel, "controller-log-level", "info", "Log level for the controller and web components") } diff --git a/cli/cmd/root.go b/cli/cmd/root.go index 6ab507111..a58b0413d 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -28,17 +28,10 @@ var RootCmd = &cobra.Command{ } func init() { - RootCmd.PersistentFlags().StringVarP(&controlPlaneNamespace, "conduit-namespace", "n", "conduit", "namespace in which Conduit is installed") - RootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "turn on debug logging") -} - -// TODO: decide if we want to use viper - -func addControlPlaneNetworkingArgs(cmd *cobra.Command) { - // Use the same argument name as `kubectl` (see the output of `kubectl options`). - //TODO: move these to init() as they are globally applicable - cmd.PersistentFlags().StringVar(&kubeconfigPath, "kubeconfig", "", "Path to the kubeconfig file to use for CLI requests") - cmd.PersistentFlags().StringVar(&apiAddr, "api-addr", "", "Override kubeconfig and communicate directly with the control plane at host:port (mostly for testing)") + RootCmd.PersistentFlags().StringVarP(&controlPlaneNamespace, "conduit-namespace", "c", "conduit", "Namespace in which Conduit is installed") + RootCmd.PersistentFlags().StringVar(&kubeconfigPath, "kubeconfig", "", "Path to the kubeconfig file to use for CLI requests") + RootCmd.PersistentFlags().StringVar(&apiAddr, "api-addr", "", "Override kubeconfig and communicate directly with the control plane at host:port (mostly for testing)") + RootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "Turn on debug logging") } func newPublicAPIClient() (pb.ApiClient, error) { diff --git a/cli/cmd/stat.go b/cli/cmd/stat.go index fb2d60ad4..f558c05e1 100644 --- a/cli/cmd/stat.go +++ b/cli/cmd/stat.go @@ -74,8 +74,7 @@ The optional [TARGET] argument can be used to target a specific deployment.`, func init() { RootCmd.AddCommand(statCmd) - addControlPlaneNetworkingArgs(statCmd) - statCmd.PersistentFlags().StringVarP(&timeWindow, "time-window", "t", "1m", "Stat window. One of: '10s', '1m', '10m', '1h'.") + statCmd.PersistentFlags().StringVarP(&timeWindow, "time-window", "t", "1m", "Stat window (one of: \"10s\", \"1m\", \"10m\", \"1h\")") } var resourceTypeToAggregationType = map[string]pb.AggregationType{ diff --git a/cli/cmd/stat_summary.go b/cli/cmd/stat_summary.go index a622fabff..dc46c6625 100644 --- a/cli/cmd/stat_summary.go +++ b/cli/cmd/stat_summary.go @@ -67,18 +67,14 @@ If no resource name is specified, displays stats about all resources of the spec func init() { RootCmd.AddCommand(statSummaryCommand) - addControlPlaneNetworkingArgs(statSummaryCommand) - // TODO: the -n flag is taken up by conduit-namespace :( we should move it to something else so this can have -n - statSummaryCommand.PersistentFlags().StringVarP(&namespace, "namespace", "a", "default", "namespace of the specified resource") - statSummaryCommand.PersistentFlags().StringVarP(&timeWindow, "time-window", "t", "1m", "Stat window. One of: '10s', '1m', '10m', '1h'.") - - statSummaryCommand.PersistentFlags().StringVarP(&outToName, "out-to", "", "", "If present, restricts outbound stats to the specified resource name") - statSummaryCommand.PersistentFlags().StringVarP(&outToNamespace, "out-to-namespace", "", "", "Sets the namespace used to lookup the '--out-to' resource. By default the current '--namespace' is used") - statSummaryCommand.PersistentFlags().StringVarP(&outToType, "out-to-resource", "", "", "If present, restricts outbound stats to the specified resource type") - - statSummaryCommand.PersistentFlags().StringVarP(&outFromName, "out-from", "", "", "If present, restricts outbound stats to the specified resource name") - statSummaryCommand.PersistentFlags().StringVarP(&outFromNamespace, "out-from-namespace", "", "", "Sets the namespace used to lookup the '--out-from' resource. By default the current '--namespace' is used") - statSummaryCommand.PersistentFlags().StringVarP(&outFromType, "out-from-resource", "", "", "If present, restricts outbound stats to the specified resource type") + statSummaryCommand.PersistentFlags().StringVarP(&namespace, "namespace", "n", "default", "Namespace of the specified resource") + statSummaryCommand.PersistentFlags().StringVarP(&timeWindow, "time-window", "t", "1m", "Stat window (one of: \"10s\", \"1m\", \"10m\", \"1h\")") + statSummaryCommand.PersistentFlags().StringVar(&outToName, "out-to", "", "If present, restricts outbound stats to the specified resource name") + statSummaryCommand.PersistentFlags().StringVar(&outToNamespace, "out-to-namespace", "", "Sets the namespace used to lookup the \"--out-to\" resource; by default the current \"--namespace\" is used") + statSummaryCommand.PersistentFlags().StringVar(&outToType, "out-to-resource", "", "If present, restricts outbound stats to the specified resource type") + statSummaryCommand.PersistentFlags().StringVar(&outFromName, "out-from", "", "If present, restricts outbound stats to the specified resource name") + statSummaryCommand.PersistentFlags().StringVar(&outFromNamespace, "out-from-namespace", "", "Sets the namespace used to lookup the \"--out-from\" resource; by default the current \"--namespace\" is used") + statSummaryCommand.PersistentFlags().StringVar(&outFromType, "out-from-resource", "", "If present, restricts outbound stats to the specified resource type") } func requestStatSummaryFromAPI(client pb.ApiClient) (string, error) { diff --git a/cli/cmd/tap.go b/cli/cmd/tap.go index 0f459d1c3..71965e55e 100644 --- a/cli/cmd/tap.go +++ b/cli/cmd/tap.go @@ -79,7 +79,6 @@ The TARGET argument is used to specify the pod or deployment to tap.`, func init() { RootCmd.AddCommand(tapCmd) - addControlPlaneNetworkingArgs(tapCmd) tapCmd.PersistentFlags().Float32Var(&maxRps, "max-rps", 1.0, "Maximum requests per second to tap.") tapCmd.PersistentFlags().Uint32Var(&toPort, "to-port", 0, "Display requests to this port") tapCmd.PersistentFlags().StringVar(&toIP, "to-ip", "", "Display requests to this IP") diff --git a/cli/cmd/version.go b/cli/cmd/version.go index befdfbd31..6f4d511a5 100644 --- a/cli/cmd/version.go +++ b/cli/cmd/version.go @@ -47,9 +47,9 @@ var versionCmd = &cobra.Command{ func init() { RootCmd.AddCommand(versionCmd) + versionCmd.Args = cobra.NoArgs versionCmd.PersistentFlags().BoolVar(&shortVersion, "short", false, "Print the version number(s) only, with no additional output") versionCmd.PersistentFlags().BoolVar(&onlyClientVersion, "client", false, "Print the client version only") - addControlPlaneNetworkingArgs(versionCmd) } func getServerVersion(client pb.ApiClient) string {