Skip to content

Commit

Permalink
add remove config-etcd cmd (#168)
Browse files Browse the repository at this point in the history
Signed-off-by: Enwei Jiao <[email protected]>
  • Loading branch information
jiaoew1991 authored Jul 17, 2023
1 parent 83f9854 commit 6aa3d0f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
2 changes: 1 addition & 1 deletion states/backup_mock_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *embedEtcdMockState) SetupCommands() {

// remove [subcommand] options...
// used for testing
etcd.RemoveCommand(s.client, rootPath),
etcd.RemoveCommand(s.client, s.instanceName, rootPath),
// download-pk
getDownloadPKCmd(s.client, rootPath),
// inspect-pk
Expand Down
4 changes: 3 additions & 1 deletion states/etcd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func SetCommand(cli clientv3.KV, instanceName string, metaPath string) *cobra.Co

// RemoveCommand returns etcd remove commands.
// WARNING this command shall be used with EXTRA CARE!
func RemoveCommand(cli clientv3.KV, basePath string) *cobra.Command {
func RemoveCommand(cli clientv3.KV, instanceName, basePath string) *cobra.Command {
removeCmd := &cobra.Command{
Use: "remove",
}
Expand All @@ -88,6 +88,8 @@ func RemoveCommand(cli clientv3.KV, basePath string) *cobra.Command {
remove.CollectionDropCommand(cli, basePath),
// remove sgements with collection dropped
remove.SegmentCollectionDroppedCommand(cli, basePath),
// remove etcd-config
remove.EtcdConfigCommand(cli, instanceName),
)

return removeCmd
Expand Down
8 changes: 6 additions & 2 deletions states/etcd/common/config_etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package common

import (
"context"
"fmt"
"path"

clientv3 "go.etcd.io/etcd/client/v3"
Expand Down Expand Up @@ -30,7 +29,12 @@ func listEtcdConfigsByPrefix(ctx context.Context, cli clientv3.KV, prefix string

func SetEtcdConfig(ctx context.Context, cli clientv3.KV, basePath string, key, value string) error {
prefix := path.Join(basePath, "config")
fmt.Println(path.Join(prefix, key), value)
_, err := cli.Put(ctx, path.Join(prefix, key), value)
return err
}

func RemoveEtcdConfig(ctx context.Context, cli clientv3.KV, basePath string, key string) error {
prefix := path.Join(basePath, "config")
_, err := cli.Delete(ctx, path.Join(prefix, key))
return err
}
44 changes: 44 additions & 0 deletions states/etcd/remove/etcd_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package remove

import (
"context"
"fmt"

"github.com/milvus-io/birdwatcher/states/etcd/common"
"github.com/spf13/cobra"

clientv3 "go.etcd.io/etcd/client/v3"
)

// EtcdConfigCommand returns set etcd-config command.
func EtcdConfigCommand(cli clientv3.KV, basePath string) *cobra.Command {
cmd := &cobra.Command{
Use: "config-etcd",
Short: "remove configuations",
Run: func(cmd *cobra.Command, args []string) {
key, err := cmd.Flags().GetString("key")
if err != nil {
fmt.Println(err.Error())
return
}
if key == "" {
fmt.Println("key & value cannot be empty")
return
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

err = common.RemoveEtcdConfig(ctx, cli, basePath, key)
if err != nil {
fmt.Println("failed to remove etcd config item,", err.Error())
return
}

fmt.Println("etcd config remove.")
},
}

cmd.Flags().String("key", "", "etcd config key")
return cmd
}
2 changes: 1 addition & 1 deletion states/etcd/set/etcd_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func EtcdConfigCommand(cli clientv3.KV, basePath string) *cobra.Command {
cmd := &cobra.Command{
Use: "config-etcd",
Short: "list configuations set by etcd source",
Short: "set configuations",
Run: func(cmd *cobra.Command, args []string) {
key, err := cmd.Flags().GetString("key")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion states/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *instanceState) SetupCommands() {
// repair [subcommand] options...
etcd.RepairCommand(cli, basePath),
// remove [subcommand] options...
etcd.RemoveCommand(cli, basePath),
etcd.RemoveCommand(cli, instanceName, basePath),
// set [subcommand] options...
etcd.SetCommand(cli, instanceName, metaPath),
// restore [subcommand] options...
Expand Down

0 comments on commit 6aa3d0f

Please sign in to comment.