Skip to content

Commit

Permalink
support version flag with non-equal sign
Browse files Browse the repository at this point in the history
  • Loading branch information
kobzonega committed Sep 30, 2024
1 parent 5f821f8 commit 11e4357
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 10 deletions.
29 changes: 22 additions & 7 deletions pkg/options/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@ type MajorMinorPatchVersion struct {
}

type RawVersion struct {
Raw string
Sign string
Raw string
}

type VersionSpec interface {
Satisfies(otherVersion string) (bool, error)
String() string
}

func (v MajorMinorPatchVersion) String() string {
return fmt.Sprintf("%s%v.%v.%v", v.Sign, v.Major, v.Minor, v.Patch)
}

func compareMajorMinorPatch(sign string, nodeVersion, userVersion [3]int) bool {
res := 0
for i := 0; i < 3; i++ {
Expand All @@ -59,6 +56,16 @@ func compareMajorMinorPatch(sign string, nodeVersion, userVersion [3]int) bool {
return false
}

func compareRaw(sign string, nodeVersion, userVersion string) bool {

Check failure on line 59 in pkg/options/types.go

View workflow job for this annotation

GitHub Actions / golangci-lint

paramTypeCombine: func(sign string, nodeVersion, userVersion string) bool could be replaced with func(sign, nodeVersion, userVersion string) bool (gocritic)
switch sign {
case "==":
return nodeVersion == userVersion
case "!=":
return nodeVersion != userVersion
}
return false
}

func tryParseWith(reString, version string) (int, int, int, bool) {
re := regexp.MustCompile(reString)
matches := re.FindStringSubmatch(version)
Expand Down Expand Up @@ -100,10 +107,18 @@ func (v MajorMinorPatchVersion) Satisfies(otherVersion string) (bool, error) {
), nil
}

func (v MajorMinorPatchVersion) String() string {
return fmt.Sprintf("%s%v.%v.%v", v.Sign, v.Major, v.Minor, v.Patch)
}

func (v RawVersion) Satisfies(otherVersion string) (bool, error) {
return v.Raw == otherVersion, nil
return compareRaw(
v.Sign,
otherVersion,
v.Raw,
), nil
}

func (v RawVersion) String() string {
return v.Raw
return fmt.Sprintf("%s%v", v.Sign, v.Raw)
}
7 changes: 4 additions & 3 deletions pkg/rolling/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
majorMinorPatchPattern = `^(>|<|!=|~=)(\d+|\*)\.(\d+|\*)\.(\d+|\*)$`
majorMinorPatchRegexp = regexp.MustCompile(majorMinorPatchPattern)

rawPattern = `^==(.*)$`
rawPattern = `^(==|!=)(.*)$`
rawRegexp = regexp.MustCompile(rawPattern)
)

Expand Down Expand Up @@ -238,11 +238,12 @@ func parseVersionFlag(versionUnparsedFlag string) (options.VersionSpec, error) {
}

matches = rawRegexp.FindStringSubmatch(versionUnparsedFlag)
if len(matches) == 2 {
if len(matches) == 3 {
// `--version` value is an arbitrary string value, and will
// be compared directly
return &options.RawVersion{
Raw: matches[1],
Sign: matches[1],
Raw: matches[2],
}, nil
}

Expand Down
74 changes: 74 additions & 0 deletions tests/rolling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,80 @@ var _ = Describe("Test Rolling", func() {
},
},
),
Entry("filter nodes by --version flag, !=full_version_string_1234", TestCase{
nodeConfiguration: [][]uint32{
{1, 2, 3},
},
nodeInfoMap: map[uint32]mock.TestNodeInfo{
1: {
Version: "full_version_string_1234",
},
2: {
Version: "full_version_string_1235",
},
3: {
Version: "full_version_string_1236",
},
},
steps: []StepData{
{
ydbopsInvocation: []string{
"--endpoint", "grpcs://localhost:2135",
"--verbose",
"--availability-mode", "strong",
"--user", mock.TestUser,
"--cms-query-interval", "1",
"run",
"--storage",
"--version", "!=full_version_string_1234",
"--payload", filepath.Join(".", "mock", "noop-payload.sh"),
"--ca-file", filepath.Join(".", "test-data", "ssl-data", "ca.crt"),
},
expectedRequests: []proto.Message{
&Ydb_Auth.LoginRequest{
User: mock.TestUser,
Password: mock.TestPassword,
},
&Ydb_Maintenance.ListClusterNodesRequest{},
&Ydb_Cms.ListDatabasesRequest{},
&Ydb_Discovery.WhoAmIRequest{},
&Ydb_Maintenance.ListMaintenanceTasksRequest{
User: &mock.TestUser,
},
&Ydb_Maintenance.CreateMaintenanceTaskRequest{
TaskOptions: &Ydb_Maintenance.MaintenanceTaskOptions{
TaskUid: "task-UUID-1",
Description: "Rolling restart maintenance task",
AvailabilityMode: Ydb_Maintenance.AvailabilityMode_AVAILABILITY_MODE_STRONG,
},
ActionGroups: mock.MakeActionGroupsFromNodeIds(2, 3),
},
&Ydb_Maintenance.CompleteActionRequest{
ActionUids: []*Ydb_Maintenance.ActionUid{
{
TaskUid: "task-UUID-1",
GroupId: "group-UUID-1",
ActionId: "action-UUID-1",
},
},
},
&Ydb_Maintenance.RefreshMaintenanceTaskRequest{
TaskUid: "task-UUID-1",
},
&Ydb_Maintenance.CompleteActionRequest{
ActionUids: []*Ydb_Maintenance.ActionUid{
{
TaskUid: "task-UUID-1",
GroupId: "group-UUID-2",
ActionId: "action-UUID-2",
},
},
},
},
},
},
},
),
Entry("happy path, restart dynnodes by tenant name", TestCase{
nodeConfiguration: [][]uint32{
{1, 2, 3, 4, 5, 6, 7, 8},
Expand Down

0 comments on commit 11e4357

Please sign in to comment.