Skip to content

Commit

Permalink
chore: fix connect func to public (#168)
Browse files Browse the repository at this point in the history
Co-authored-by: 1aal <[email protected]>
  • Loading branch information
1aal and 1aal authored Dec 28, 2023
1 parent 7da1c54 commit fb4963d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/user_docs/cli/kbcli_cluster_create_redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ kbcli cluster create redis NAME [flags]
-h, --help help for redis
--host-network-accessible Specify whether the cluster can be accessed from within the VPC.
--memory float Memory, the unit is Gi. Value range [0.5, 1000]. (default 0.5)
--mode string Cluster topology mode. Legal values [standalone, replication]. (default "standalone")
--mode string Cluster topology mode. Legal values [standalone, replication]. (default "replication")
--monitoring-interval int The monitoring interval of cluster, 0 is disabled, the unit is second. Value range [0, 60].
--node-port-enabled Whether NodePort service is enabled, default is true
--publicly-accessible Specify whether the cluster can be accessed from the public internet.
Expand Down
Binary file modified pkg/cluster/charts/redis-cluster.tgz
Binary file not shown.
14 changes: 7 additions & 7 deletions pkg/cmd/cluster/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ func NewConnectCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra
Example: connectExample,
ValidArgsFunction: util.ResourceNameCompletionFunc(f, types.ClusterGVR()),
Run: func(cmd *cobra.Command, args []string) {
util.CheckErr(o.validate(args))
util.CheckErr(o.complete())
util.CheckErr(o.Validate(args))
util.CheckErr(o.Complete())
if o.showExample {
util.CheckErr(o.runShowExample())
} else {
util.CheckErr(o.connect())
util.CheckErr(o.Connect())
}
},
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func (o *ConnectOptions) runShowExample() error {
return nil
}

func (o *ConnectOptions) validate(args []string) error {
func (o *ConnectOptions) Validate(args []string) error {
if len(args) > 1 {
return fmt.Errorf("only support to connect one cluster")
}
Expand Down Expand Up @@ -200,7 +200,7 @@ func (o *ConnectOptions) validate(args []string) error {
return nil
}

func (o *ConnectOptions) complete() error {
func (o *ConnectOptions) Complete() error {
var err error
if err = o.ExecOptions.Complete(); err != nil {
return err
Expand Down Expand Up @@ -255,8 +255,8 @@ func (o *ConnectOptions) complete() error {
return nil
}

// connect creates connection string and connects to cluster
func (o *ConnectOptions) connect() error {
// Connect creates connection string and connects to cluster
func (o *ConnectOptions) Connect() error {
var err error

if o.engine, err = register.NewClusterCommands(o.characterType); err != nil {
Expand Down
30 changes: 15 additions & 15 deletions pkg/cmd/cluster/connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,46 +91,46 @@ var _ = Describe("connection", func() {
o := &ConnectOptions{ExecOptions: action.NewExecOptions(tf, streams)}

By("specified more than one cluster")
Expect(o.validate([]string{"c1", "c2"})).Should(HaveOccurred())
Expect(o.Validate([]string{"c1", "c2"})).Should(HaveOccurred())

By("without cluster name")
Expect(o.validate(nil)).Should(HaveOccurred())
Expect(o.Validate(nil)).Should(HaveOccurred())

Expect(o.validate([]string{clusterName})).Should(Succeed())
Expect(o.Validate([]string{clusterName})).Should(Succeed())

// set instance name and cluster name, should fail
o.PodName = "test-pod-0"
Expect(o.validate([]string{clusterName})).Should(HaveOccurred())
Expect(o.Validate([]string{clusterName})).Should(HaveOccurred())
o.componentName = "test-component"
Expect(o.validate([]string{})).Should(HaveOccurred())
Expect(o.Validate([]string{})).Should(HaveOccurred())

// unset pod name
o.PodName = ""
Expect(o.validate([]string{clusterName})).Should(Succeed())
Expect(o.Validate([]string{clusterName})).Should(Succeed())
// unset component name
o.componentName = ""
Expect(o.validate([]string{clusterName})).Should(Succeed())
Expect(o.Validate([]string{clusterName})).Should(Succeed())
})

It("complete by cluster name", func() {
o := &ConnectOptions{ExecOptions: action.NewExecOptions(tf, streams)}
Expect(o.validate([]string{clusterName})).Should(Succeed())
Expect(o.complete()).Should(Succeed())
Expect(o.Validate([]string{clusterName})).Should(Succeed())
Expect(o.Complete()).Should(Succeed())
Expect(o.Pod).ShouldNot(BeNil())
})

It("complete by pod name", func() {
o := &ConnectOptions{ExecOptions: action.NewExecOptions(tf, streams)}
o.PodName = "test-pod-0"
Expect(o.validate([]string{})).Should(Succeed())
Expect(o.complete()).Should(Succeed())
Expect(o.Validate([]string{})).Should(Succeed())
Expect(o.Complete()).Should(Succeed())
Expect(o.Pod).ShouldNot(BeNil())
})

It("show example", func() {
o := &ConnectOptions{ExecOptions: action.NewExecOptions(tf, streams)}
Expect(o.validate([]string{clusterName})).Should(Succeed())
Expect(o.complete()).Should(Succeed())
Expect(o.Validate([]string{clusterName})).Should(Succeed())
Expect(o.Complete()).Should(Succeed())

By("specify one cluster")
Expect(o.runShowExample()).Should(Succeed())
Expand Down Expand Up @@ -158,8 +158,8 @@ var _ = Describe("connection", func() {

It("--show-password", func() {
o := &ConnectOptions{ExecOptions: action.NewExecOptions(tf, streams)}
Expect(o.validate([]string{clusterName})).Should(Succeed())
Expect(o.complete()).Should(Succeed())
Expect(o.Validate([]string{clusterName})).Should(Succeed())
Expect(o.Complete()).Should(Succeed())
info, err := o.getConnectionInfo()
Expect(err).Should(Succeed())
Expect(info.Password).Should(Equal(passwordMask))
Expand Down

0 comments on commit fb4963d

Please sign in to comment.