From a1803e38863a915a66c9f0ec99b7bfa977fa4245 Mon Sep 17 00:00:00 2001 From: Priyanshu Pandey Date: Tue, 28 Feb 2023 14:14:37 -0800 Subject: [PATCH] PWX-29068: Improving storkctl create clusterpair help output. (#1314) * PWX-29068: Improving storkctl create clusterpair help output. Signed-off-by: Priyanshu Pandey * Moving (currently supported only for Rancher) to the top Signed-off-by: Priyanshu Pandey --------- Signed-off-by: Priyanshu Pandey --- cmd/stork/stork.go | 4 ++-- pkg/storkctl/clusterpair.go | 35 ++++++++++++++++++++--------------- pkg/storkctl/factory.go | 12 ++++++------ 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/cmd/stork/stork.go b/cmd/stork/stork.go index 4a6d1ae0ec..a8633381b9 100644 --- a/cmd/stork/stork.go +++ b/cmd/stork/stork.go @@ -187,12 +187,12 @@ func main() { cli.IntFlag{ Name: "k8s-api-qps", Value: 100, - Usage: "Restrict number of k8s api requests from stork (default: 100 QPS)", + Usage: "Restrict number of k8s API requests from stork (default: 100 QPS)", }, cli.IntFlag{ Name: "k8s-api-burst", Value: 100, - Usage: "Restrict number of k8s api requests from stork (default: 100 Burst)", + Usage: "Restrict number of k8s API requests from stork (default: 100 Burst)", }, cli.BoolTFlag{ Name: "kdmp-controller", diff --git a/pkg/storkctl/clusterpair.go b/pkg/storkctl/clusterpair.go index 4efbf1fbff..5873309cf2 100644 --- a/pkg/storkctl/clusterpair.go +++ b/pkg/storkctl/clusterpair.go @@ -33,7 +33,15 @@ const ( gcloudBinaryName = "gcloud" ) -var clusterPairColumns = []string{"NAME", "STORAGE-STATUS", "SCHEDULER-STATUS", "CREATED"} +var ( + clusterPairColumns = []string{"NAME", "STORAGE-STATUS", "SCHEDULER-STATUS", "CREATED"} + + projectMappingHelpString = "Project mappings between source and destination clusters (currently supported only for Rancher).\n" + + "Use comma-separated = pairs.\n" + + "For the project-id, you can also have a cluster-id field added as a prefix to the project-id.\n" + + "It is recommended to include both one-to-one mappings of the project-id and Rancher cluster-id prefixed project-id as follows:\n" + + "=,:=:" +) func newGetClusterPairCommand(cmdFactory Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { getClusterPairCommand := &cobra.Command{ @@ -208,8 +216,7 @@ func newGenerateClusterPairCommand(cmdFactory Factory, ioStreams genericclioptio if len(projectMappingsStr) > 0 { projectIDMap, err := utils.ParseKeyValueList(strings.Split(projectMappingsStr, ",")) if err != nil { - util.CheckErr(fmt.Errorf("invalid project-mappings provided, use comma-separated" + - "= pairs (Currently supported only for Rancher)")) + util.CheckErr(fmt.Errorf("invalid %v", projectMappingHelpString)) } clusterPair.Spec.PlatformOptions = storkv1.PlatformSpec{ Rancher: &storkv1.RancherSpec{ProjectMappings: projectIDMap}, @@ -224,8 +231,7 @@ func newGenerateClusterPairCommand(cmdFactory Factory, ioStreams genericclioptio } generateClusterPairCommand.Flags().StringVarP(&storageOptions, "storageoptions", "s", "", "comma seperated key-value pair storage options") - generateClusterPairCommand.Flags().StringVarP(&projectMappingsStr, "project-mappings", "", "", - "project mappings between source and destination clusters, use comma-separated = pairs (Currently supported only for Rancher)") + generateClusterPairCommand.Flags().StringVarP(&projectMappingsStr, "project-mappings", "", "", projectMappingHelpString) return generateClusterPairCommand } @@ -325,16 +331,15 @@ func newCreateClusterPairCommand(cmdFactory Factory, ioStreams genericclioptions }, } - createClusterPairCommand.Flags().StringVarP(&sIP, "src-ip", "", "", "ip of storage node from source cluster") - createClusterPairCommand.Flags().StringVarP(&sPort, "src-port", "", "9001", "port of storage node from source cluster") - createClusterPairCommand.Flags().StringVarP(&sFile, "src-kube-file", "", "", "kube-config of source cluster") - createClusterPairCommand.Flags().StringVarP(&dIP, "dest-ip", "", "", "kube-config of destination cluster") - createClusterPairCommand.Flags().StringVarP(&dPort, "dest-port", "", "9001", "port of storage node from destination cluster") - createClusterPairCommand.Flags().StringVarP(&dFile, "dest-kube-file", "", "", "kube-config of destination cluster") - createClusterPairCommand.Flags().StringVarP(&srcToken, "src-token", "", "", "(optional)source cluster token for cluster pairing") - createClusterPairCommand.Flags().StringVarP(&destToken, "dest-token", "", "", "(optional)destination cluster token for cluster pairing") - createClusterPairCommand.Flags().StringVarP(&projectMappingsStr, "project-mappings", "", "", - "project mappings between source and destination clusters, use comma-separated = pairs (Currently supported only for Rancher)") + createClusterPairCommand.Flags().StringVarP(&sIP, "src-ip", "", "", "IP of storage node from source cluster") + createClusterPairCommand.Flags().StringVarP(&sPort, "src-port", "", "9001", "Port of storage node from source cluster") + createClusterPairCommand.Flags().StringVarP(&sFile, "src-kube-file", "", "", "Path to the kubeconfig of source cluster") + createClusterPairCommand.Flags().StringVarP(&dIP, "dest-ip", "", "", "IP of storage node from destination cluster") + createClusterPairCommand.Flags().StringVarP(&dPort, "dest-port", "", "9001", "Port of storage node from destination cluster") + createClusterPairCommand.Flags().StringVarP(&dFile, "dest-kube-file", "", "", "Path to the kubeconfig of destination cluster") + createClusterPairCommand.Flags().StringVarP(&srcToken, "src-token", "", "", "(Optional)Source cluster token for cluster pairing") + createClusterPairCommand.Flags().StringVarP(&destToken, "dest-token", "", "", "(Optional)Destination cluster token for cluster pairing") + createClusterPairCommand.Flags().StringVarP(&projectMappingsStr, "project-mappings", "", "", projectMappingHelpString) return createClusterPairCommand } diff --git a/pkg/storkctl/factory.go b/pkg/storkctl/factory.go index ba2e07969d..a7bcca4e9a 100644 --- a/pkg/storkctl/factory.go +++ b/pkg/storkctl/factory.go @@ -73,12 +73,12 @@ func NewFactory() Factory { func (f *factory) BindFlags(flags *pflag.FlagSet) { flags.StringVarP(&f.namespace, "namespace", "n", "default", "If present, the namespace scope for this CLI request") - flags.StringVar(&f.kubeconfig, "kubeconfig", "", "Path to the kubeconfig file to use for CLI requests") - flags.StringVar(&f.context, "context", "", "The name of the kubeconfig context to use") - flags.StringVarP(&f.outputFormat, "output", "o", outputFormatTable, "Output format. One of: table|json|yaml") - flags.BoolVarP(&f.watch, "watch", "w", false, "watch stork resourrces") - flags.IntVarP(&f.qps, "qps", "", 100, "Restrict number of k8s api requests from stork") - flags.IntVarP(&f.burst, "burst", "", 100, "Restrict number of k8s api requests from stork") + flags.StringVar(&f.kubeconfig, "kubeconfig", "", "path to the kubeconfig file to use for CLI requests") + flags.StringVar(&f.context, "context", "", "name of the kubeconfig context to use") + flags.StringVarP(&f.outputFormat, "output", "o", outputFormatTable, "output format. One of: table|json|yaml") + flags.BoolVarP(&f.watch, "watch", "w", false, "watch stork resources") + flags.IntVarP(&f.qps, "qps", "", 100, "restrict number of k8s API requests from stork") + flags.IntVarP(&f.burst, "burst", "", 100, "restrict number of k8s API requests from stork") } func (f *factory) BindGetFlags(flags *pflag.FlagSet) {