From bcc10f16ca3bb16d259c730e94cb4cf45cb2424c Mon Sep 17 00:00:00 2001 From: Maayan Friedman Date: Mon, 12 Jul 2021 17:24:17 +0300 Subject: [PATCH] Support kubecontexts in subctl benchmark In the same way it supported in subctl verify Fixes #1326 Signed-off-by: Maayan Friedman --- pkg/subctl/cmd/benchmark.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/pkg/subctl/cmd/benchmark.go b/pkg/subctl/cmd/benchmark.go index 90ed5ec04..ec3b76f0b 100644 --- a/pkg/subctl/cmd/benchmark.go +++ b/pkg/subctl/cmd/benchmark.go @@ -19,6 +19,7 @@ package cmd import ( "fmt" + "strings" "github.com/submariner-io/shipyard/test/e2e/framework" @@ -35,7 +36,7 @@ var ( Long: "This command runs various benchmark tests", } benchmarkThroughputCmd = &cobra.Command{ - Use: "throughput []", + Use: "throughput --kubecontexts [,]", Short: "Benchmark throughput", Long: "This command runs throughput tests within a cluster or between two clusters", Args: func(cmd *cobra.Command, args []string) error { @@ -44,7 +45,7 @@ var ( Run: testThroughput, } benchmarkLatencyCmd = &cobra.Command{ - Use: "latency []", + Use: "latency --kubecontexts [,]", Short: "Benchmark latency", Long: "This command runs latency benchmark tests within a cluster or between two clusters", Args: func(cmd *cobra.Command, args []string) error { @@ -66,15 +67,30 @@ func init() { } func addBenchmarkFlags(cmd *cobra.Command) { + AddKubeContextMultiFlag(cmd, "comma-separated list of one or two kubeconfig contexts to use.") cmd.PersistentFlags().BoolVar(&intraCluster, "intra-cluster", false, "run the test within a single cluster") cmd.PersistentFlags().BoolVar(&benchmark.Verbose, "verbose", false, "produce verbose logs during benchmark tests") } func checkBenchmarkArguments(args []string, intraCluster bool) error { - if !intraCluster && len(args) != 2 { - return fmt.Errorf("two kubeconfigs must be specified") - } else if intraCluster && len(args) != 1 { - return fmt.Errorf("only one kubeconfig should be specified") + if !intraCluster && len(args) != 2 && len(kubeContexts) != 2 { + return fmt.Errorf("two kubecontexts must be specified") + } else if intraCluster && len(args) != 1 && len(kubeContexts) != 1 { + return fmt.Errorf("only one kubecontext should be specified") + } + if len(args) == 2 { + if strings.Compare(args[0], args[1]) == 0 { + return fmt.Errorf("kubeconfig file and cannot be the same file") + } + same, err := CompareFiles(args[0], args[1]) + if err != nil { + return err + } + if same { + return fmt.Errorf("kubeconfig file and need to have a unique content") + } + } else if len(kubeContexts) == 2 && strings.Compare(kubeContexts[0], kubeContexts[1]) == 0 { + return fmt.Errorf("the two kubecontexts must be different") } return nil }