diff --git a/pkg/cli/cmd/bench/bench_test.go b/pkg/cli/cmd/bench/bench_test.go index 41201e3ec6e..b3c06d93a8c 100644 --- a/pkg/cli/cmd/bench/bench_test.go +++ b/pkg/cli/cmd/bench/bench_test.go @@ -99,24 +99,23 @@ var _ = Describe("bench", func() { It("test sysbench run", func() { o := &SysBenchOptions{ BenchBaseOptions: BenchBaseOptions{ - Driver: "mysql", - Database: "test", - Host: "svc-1", - Port: 3306, - User: "test", - Password: "test", - ClusterName: "test", - factory: tf, - namespace: namespace, - IOStreams: streams, + Driver: "mysql", + Database: "test", + Host: "svc-1", + Port: 3306, + User: "test", + Password: "test", + factory: tf, + namespace: namespace, + IOStreams: streams, }, Type: []string{"oltp_read_only"}, Tables: 1, Size: 100, Duration: 60, } - o.dynamic, _ = tf.DynamicClient() - o.client, _ = tf.KubernetesClientSet() + Expect(o.Complete([]string{})).Should(BeNil()) + Expect(o.Validate()).ShouldNot(BeNil()) Expect(o.Run()).Should(BeNil()) }) @@ -128,22 +127,21 @@ var _ = Describe("bench", func() { It("test pgbench run", func() { o := &PgBenchOptions{ BenchBaseOptions: BenchBaseOptions{ - Driver: pgBenchDriver, - Database: "test", - Host: "svc-1", - Port: 3306, - User: "test", - Password: "test", - ClusterName: "test", - factory: tf, - namespace: namespace, - IOStreams: streams, + Driver: pgBenchDriver, + Database: "test", + Host: "svc-1", + Port: 3306, + User: "test", + Password: "test", + factory: tf, + namespace: namespace, + IOStreams: streams, }, Scale: 100, Clients: []int{1}, } - o.dynamic, _ = tf.DynamicClient() - o.client, _ = tf.KubernetesClientSet() + Expect(o.Complete([]string{})).Should(BeNil()) + Expect(o.Validate()).ShouldNot(BeNil()) Expect(o.Run()).Should(BeNil()) }) @@ -155,23 +153,22 @@ var _ = Describe("bench", func() { It("test ycsb run", func() { o := &YcsbOptions{ BenchBaseOptions: BenchBaseOptions{ - Driver: "mysql", - Database: "test", - Host: "svc-1", - Port: 3306, - User: "test", - Password: "test", - ClusterName: "test", - factory: tf, - namespace: namespace, - IOStreams: streams, + Driver: "mysql", + Database: "test", + Host: "svc-1", + Port: 3306, + User: "test", + Password: "test", + factory: tf, + namespace: namespace, + IOStreams: streams, }, RecordCount: 1000, OperationCount: 1000, Threads: []int{1}, } - o.dynamic, _ = tf.DynamicClient() - o.client, _ = tf.KubernetesClientSet() + Expect(o.Complete([]string{})).Should(BeNil()) + Expect(o.Validate()).ShouldNot(BeNil()) Expect(o.Run()).Should(BeNil()) }) diff --git a/pkg/cli/cmd/bench/pgbench.go b/pkg/cli/cmd/bench/pgbench.go index b1fb5ec6af2..34de176f2e0 100644 --- a/pkg/cli/cmd/bench/pgbench.go +++ b/pkg/cli/cmd/bench/pgbench.go @@ -32,7 +32,6 @@ import ( "k8s.io/kubectl/pkg/util/templates" "github.com/apecloud/kubebench/api/v1alpha1" - "github.com/apecloud/kubeblocks/pkg/cli/cluster" "github.com/apecloud/kubeblocks/pkg/cli/types" ) @@ -120,20 +119,20 @@ func (o *PgBenchOptions) Complete(args []string) error { o.Step, o.name = parseStepAndName(args, "pgbench") - if o.ClusterName != "" { - o.namespace, _, err = o.factory.ToRawKubeConfigLoader().Namespace() - if err != nil { - return err - } + o.namespace, _, err = o.factory.ToRawKubeConfigLoader().Namespace() + if err != nil { + return err + } - if o.dynamic, err = o.factory.DynamicClient(); err != nil { - return err - } + if o.dynamic, err = o.factory.DynamicClient(); err != nil { + return err + } - if o.client, err = o.factory.KubernetesClientSet(); err != nil { - return err - } + if o.client, err = o.factory.KubernetesClientSet(); err != nil { + return err + } + if o.ClusterName != "" { clusterGetter := cluster.ObjectsGetter{ Client: o.client, Dynamic: o.dynamic, @@ -175,7 +174,7 @@ func (o *PgBenchOptions) Validate() error { } if o.Driver != pgBenchDriver { - return fmt.Errorf("pgbench only supports to run against PostgreSQL cluster, your cluster's driver is %s", o.Driver) + return fmt.Errorf("pgbench only supports drivers in [%s], current cluster driver is %s", pgBenchDriver, o.Driver) } if len(o.Clients) == 0 { diff --git a/pkg/cli/cmd/bench/sysbench.go b/pkg/cli/cmd/bench/sysbench.go index 48a29fb804c..561d00d39e9 100644 --- a/pkg/cli/cmd/bench/sysbench.go +++ b/pkg/cli/cmd/bench/sysbench.go @@ -22,6 +22,7 @@ package bench import ( "context" "fmt" + "strings" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -32,7 +33,6 @@ import ( "k8s.io/kubectl/pkg/util/templates" "github.com/apecloud/kubebench/api/v1alpha1" - "github.com/apecloud/kubeblocks/pkg/cli/cluster" "github.com/apecloud/kubeblocks/pkg/cli/types" ) @@ -42,6 +42,7 @@ var ( "mysql": "mysql", "postgresql": "pgsql", } + sysbenchSupportedDrivers = []string{"mysql", "pgsql"} ) var sysbenchExample = templates.Examples(` @@ -125,20 +126,20 @@ func (o *SysBenchOptions) Complete(args []string) error { o.Step, o.name = parseStepAndName(args, "sysbench") - if o.ClusterName != "" { - o.namespace, _, err = o.factory.ToRawKubeConfigLoader().Namespace() - if err != nil { - return err - } + o.namespace, _, err = o.factory.ToRawKubeConfigLoader().Namespace() + if err != nil { + return err + } - if o.dynamic, err = o.factory.DynamicClient(); err != nil { - return err - } + if o.dynamic, err = o.factory.DynamicClient(); err != nil { + return err + } - if o.client, err = o.factory.KubernetesClientSet(); err != nil { - return err - } + if o.client, err = o.factory.KubernetesClientSet(); err != nil { + return err + } + if o.ClusterName != "" { clusterGetter := cluster.ObjectsGetter{ Client: o.client, Dynamic: o.dynamic, @@ -195,7 +196,8 @@ func (o *SysBenchOptions) Validate() error { } } if !supported { - return fmt.Errorf("driver %s is not supported", o.Driver) + return fmt.Errorf("sysbench now only supports drivers in [%s], current cluster driver is %s", + strings.Join(sysbenchSupportedDrivers, ","), o.Driver) } if o.User == "" { diff --git a/pkg/cli/cmd/bench/tpcc.go b/pkg/cli/cmd/bench/tpcc.go index e4aff8fb122..1814ef51998 100644 --- a/pkg/cli/cmd/bench/tpcc.go +++ b/pkg/cli/cmd/bench/tpcc.go @@ -22,6 +22,7 @@ package bench import ( "context" "fmt" + "strings" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -32,7 +33,6 @@ import ( "k8s.io/kubectl/pkg/util/templates" "github.com/apecloud/kubebench/api/v1alpha1" - "github.com/apecloud/kubeblocks/pkg/cli/cluster" "github.com/apecloud/kubeblocks/pkg/cli/types" ) @@ -42,6 +42,7 @@ var ( "mysql": "mysql", "postgresql": "postgres", } + tpccSupportedDrivers = []string{"mysql", "postgres"} ) var tpccExample = templates.Examples(` @@ -130,20 +131,20 @@ func (o *TpccOptions) Complete(args []string) error { o.Step, o.name = parseStepAndName(args, "tpcc") - if o.ClusterName != "" { - o.namespace, _, err = o.factory.ToRawKubeConfigLoader().Namespace() - if err != nil { - return err - } + o.namespace, _, err = o.factory.ToRawKubeConfigLoader().Namespace() + if err != nil { + return err + } - if o.dynamic, err = o.factory.DynamicClient(); err != nil { - return err - } + if o.dynamic, err = o.factory.DynamicClient(); err != nil { + return err + } - if o.client, err = o.factory.KubernetesClientSet(); err != nil { - return err - } + if o.client, err = o.factory.KubernetesClientSet(); err != nil { + return err + } + if o.ClusterName != "" { clusterGetter := cluster.ObjectsGetter{ Client: o.client, Dynamic: o.dynamic, @@ -194,7 +195,8 @@ func (o *TpccOptions) Validate() error { } } if !supported { - return fmt.Errorf("driver %s is not supported", o.Driver) + return fmt.Errorf("tpcc now only supports drivers in [%s], current cluster driver is %s", + strings.Join(tpccSupportedDrivers, ","), o.Driver) } if o.User == "" { diff --git a/pkg/cli/cmd/bench/tpch.go b/pkg/cli/cmd/bench/tpch.go index cd552b766f4..fe10d06ce15 100644 --- a/pkg/cli/cmd/bench/tpch.go +++ b/pkg/cli/cmd/bench/tpch.go @@ -22,6 +22,7 @@ package bench import ( "context" "fmt" + "strings" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -32,7 +33,6 @@ import ( "k8s.io/kubectl/pkg/util/templates" "github.com/apecloud/kubebench/api/v1alpha1" - "github.com/apecloud/kubeblocks/pkg/cli/cluster" "github.com/apecloud/kubeblocks/pkg/cli/types" ) @@ -41,6 +41,7 @@ var ( tpchDriverMap = map[string]string{ "mysql": "mysql", } + tpchSupportedDrivers = []string{"mysql"} ) var tpchExample = templates.Examples(` @@ -90,20 +91,20 @@ func (o *TpchOptions) Complete(args []string) error { o.Step, o.name = parseStepAndName(args, "tpch") - if o.ClusterName != "" { - o.namespace, _, err = o.factory.ToRawKubeConfigLoader().Namespace() - if err != nil { - return err - } + o.namespace, _, err = o.factory.ToRawKubeConfigLoader().Namespace() + if err != nil { + return err + } - if o.dynamic, err = o.factory.DynamicClient(); err != nil { - return err - } + if o.dynamic, err = o.factory.DynamicClient(); err != nil { + return err + } - if o.client, err = o.factory.KubernetesClientSet(); err != nil { - return err - } + if o.client, err = o.factory.KubernetesClientSet(); err != nil { + return err + } + if o.ClusterName != "" { clusterGetter := cluster.ObjectsGetter{ Client: o.client, Dynamic: o.dynamic, @@ -154,7 +155,8 @@ func (o *TpchOptions) Validate() error { } } if !supported { - return fmt.Errorf("driver %s is not supported", o.Driver) + return fmt.Errorf("tpch now only supports drivers in [%s], current cluster driver is %s", + strings.Join(tpchSupportedDrivers, ", "), o.Driver) } if o.User == "" { diff --git a/pkg/cli/cmd/bench/ycsb.go b/pkg/cli/cmd/bench/ycsb.go index 03001f74fc7..13a71a138c4 100644 --- a/pkg/cli/cmd/bench/ycsb.go +++ b/pkg/cli/cmd/bench/ycsb.go @@ -22,6 +22,7 @@ package bench import ( "context" "fmt" + "strings" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -32,7 +33,6 @@ import ( "k8s.io/kubectl/pkg/util/templates" "github.com/apecloud/kubebench/api/v1alpha1" - "github.com/apecloud/kubeblocks/pkg/cli/cluster" "github.com/apecloud/kubeblocks/pkg/cli/types" ) @@ -44,6 +44,7 @@ var ( "postgresql": "postgresql", "redis": "redis", } + ycsbSupportedDrivers = []string{"mongodb", "mysql", "postgresql", "redis"} ) var ycsbExample = templates.Examples(` @@ -124,21 +125,21 @@ func (o *YcsbOptions) Complete(args []string) error { return err } - o.Step, o.name = parseStepAndName(args, "ycsb") - if o.ClusterName != "" { - o.namespace, _, err = o.factory.ToRawKubeConfigLoader().Namespace() - if err != nil { - return err - } + o.namespace, _, err = o.factory.ToRawKubeConfigLoader().Namespace() + if err != nil { + return err + } - if o.dynamic, err = o.factory.DynamicClient(); err != nil { - return err - } + if o.dynamic, err = o.factory.DynamicClient(); err != nil { + return err + } - if o.client, err = o.factory.KubernetesClientSet(); err != nil { - return err - } + if o.client, err = o.factory.KubernetesClientSet(); err != nil { + return err + } + o.Step, o.name = parseStepAndName(args, "ycsb") + if o.ClusterName != "" { clusterGetter := cluster.ObjectsGetter{ Client: o.client, Dynamic: o.dynamic, @@ -190,7 +191,7 @@ func (o *YcsbOptions) Validate() error { } } if !supported { - return fmt.Errorf("driver %s is not supported", o.Driver) + return fmt.Errorf("ycsb now only supports drivers in [%s], current cluster driver is %s", strings.Join(ycsbSupportedDrivers, ","), o.Driver) } if o.RecordCount < 0 {