Skip to content

Commit

Permalink
client: Alias downgrade action enum
Browse files Browse the repository at this point in the history
  • Loading branch information
serathius committed Feb 14, 2022
1 parent fdbba53 commit 12d7d86
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
24 changes: 14 additions & 10 deletions client/v3/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ type (
HashKVResponse pb.HashKVResponse
MoveLeaderResponse pb.MoveLeaderResponse
DowngradeResponse pb.DowngradeResponse

DowngradeAction pb.DowngradeRequest_DowngradeAction
)

const (
DowngradeValidate = DowngradeAction(pb.DowngradeRequest_VALIDATE)
DowngradeEnable = DowngradeAction(pb.DowngradeRequest_ENABLE)
DowngradeCancel = DowngradeAction(pb.DowngradeRequest_CANCEL)
)

type Maintenance interface {
Expand Down Expand Up @@ -76,12 +84,8 @@ type Maintenance interface {

// Downgrade requests downgrades, verifies feasibility or cancels downgrade
// on the cluster version.
// action is one of the following:
// VALIDATE = 0;
// ENABLE = 1;
// CANCEL = 2;
// Supported since etcd 3.5.
Downgrade(ctx context.Context, action int32, version string) (*DowngradeResponse, error)
Downgrade(ctx context.Context, action DowngradeAction, version string) (*DowngradeResponse, error)
}

// SnapshotResponse is aggregated response from the snapshot stream.
Expand Down Expand Up @@ -337,14 +341,14 @@ func (m *maintenance) MoveLeader(ctx context.Context, transfereeID uint64) (*Mov
return (*MoveLeaderResponse)(resp), toErr(ctx, err)
}

func (m *maintenance) Downgrade(ctx context.Context, action int32, version string) (*DowngradeResponse, error) {
actionType := pb.DowngradeRequest_VALIDATE
func (m *maintenance) Downgrade(ctx context.Context, action DowngradeAction, version string) (*DowngradeResponse, error) {
var actionType pb.DowngradeRequest_DowngradeAction
switch action {
case 0:
case DowngradeValidate:
actionType = pb.DowngradeRequest_VALIDATE
case 1:
case DowngradeEnable:
actionType = pb.DowngradeRequest_ENABLE
case 2:
case DowngradeCancel:
actionType = pb.DowngradeRequest_CANCEL
default:
return nil, errors.New("etcdclient: unknown downgrade action")
Expand Down
8 changes: 4 additions & 4 deletions etcdctl/ctlv3/command/downgrade_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"errors"

"github.com/spf13/cobra"
pb "go.etcd.io/etcd/api/v3/etcdserverpb"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/pkg/v3/cobrautl"
)

Expand Down Expand Up @@ -86,7 +86,7 @@ func downgradeValidateCommandFunc(cmd *cobra.Command, args []string) {
ctx, cancel := commandCtx(cmd)
cli := mustClientFromCmd(cmd)

resp, err := cli.Downgrade(ctx, int32(pb.DowngradeRequest_VALIDATE), targetVersion)
resp, err := cli.Downgrade(ctx, clientv3.DowngradeValidate, targetVersion)
cancel()
if err != nil {
cobrautl.ExitWithError(cobrautl.ExitError, err)
Expand All @@ -112,7 +112,7 @@ func downgradeEnableCommandFunc(cmd *cobra.Command, args []string) {
ctx, cancel := commandCtx(cmd)
cli := mustClientFromCmd(cmd)

resp, err := cli.Downgrade(ctx, int32(pb.DowngradeRequest_ENABLE), targetVersion)
resp, err := cli.Downgrade(ctx, clientv3.DowngradeEnable, targetVersion)
cancel()
if err != nil {
cobrautl.ExitWithError(cobrautl.ExitError, err)
Expand All @@ -126,7 +126,7 @@ func downgradeCancelCommandFunc(cmd *cobra.Command, args []string) {
ctx, cancel := commandCtx(cmd)
cli := mustClientFromCmd(cmd)

resp, err := cli.Downgrade(ctx, int32(pb.DowngradeRequest_CANCEL), "")
resp, err := cli.Downgrade(ctx, clientv3.DowngradeCancel, "")
cancel()
if err != nil {
cobrautl.ExitWithError(cobrautl.ExitError, err)
Expand Down

0 comments on commit 12d7d86

Please sign in to comment.