Skip to content

Commit

Permalink
fix: failed create bench wihtout cluster name (#5495)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengluodb authored Oct 20, 2023
1 parent 85af4e0 commit d6a5266
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 102 deletions.
69 changes: 33 additions & 36 deletions pkg/cli/cmd/bench/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})

Expand All @@ -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())
})

Expand All @@ -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())
})

Expand Down
25 changes: 12 additions & 13 deletions pkg/cli/cmd/bench/pgbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
28 changes: 15 additions & 13 deletions pkg/cli/cmd/bench/sysbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package bench
import (
"context"
"fmt"
"strings"

"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -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"
)
Expand All @@ -42,6 +42,7 @@ var (
"mysql": "mysql",
"postgresql": "pgsql",
}
sysbenchSupportedDrivers = []string{"mysql", "pgsql"}
)

var sysbenchExample = templates.Examples(`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 == "" {
Expand Down
28 changes: 15 additions & 13 deletions pkg/cli/cmd/bench/tpcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package bench
import (
"context"
"fmt"
"strings"

"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -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"
)
Expand All @@ -42,6 +42,7 @@ var (
"mysql": "mysql",
"postgresql": "postgres",
}
tpccSupportedDrivers = []string{"mysql", "postgres"}
)

var tpccExample = templates.Examples(`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 == "" {
Expand Down
28 changes: 15 additions & 13 deletions pkg/cli/cmd/bench/tpch.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package bench
import (
"context"
"fmt"
"strings"

"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -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"
)
Expand All @@ -41,6 +41,7 @@ var (
tpchDriverMap = map[string]string{
"mysql": "mysql",
}
tpchSupportedDrivers = []string{"mysql"}
)

var tpchExample = templates.Examples(`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 == "" {
Expand Down
Loading

0 comments on commit d6a5266

Please sign in to comment.