client: Alias downgrade action enum

dependabot/go_modules/go.uber.org/atomic-1.10.0
Marek Siarkowicz 2022-02-14 14:51:58 +01:00
parent 22ee50e005
commit d0c1c3a1fd
2 changed files with 18 additions and 14 deletions

View File

@ -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 {
@ -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.
@ -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")

View File

@ -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"
)
@ -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)
@ -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)
@ -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)