Skip to content

Commit

Permalink
Merge pull request #19392 from k8s-infra-cherrypick-robot/cherry-pick…
Browse files Browse the repository at this point in the history
…-19388-to-release-3.6

[release-3.6] Minor refacotr on the e2e test framework
  • Loading branch information
serathius authored Feb 12, 2025
2 parents 5078428 + 06092f8 commit 71cdab4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
55 changes: 32 additions & 23 deletions tests/framework/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,6 @@ func InitEtcdProcessCluster(t testing.TB, cfg *EtcdProcessClusterConfig) (*EtcdP
if cfg.Version == LastVersion && !CouldSetSnapshotCatchupEntries(BinPath.EtcdLastRelease) {
return nil, fmt.Errorf("cannot set SnapshotCatchUpEntries for last etcd version: %s", BinPath.EtcdLastRelease)
}
if cfg.Version != CurrentVersion && UsesExperimentalSnapshotCatchupEntriesFlag(BinPath.EtcdLastRelease) {
cfg.ServerConfig.ExperimentalSnapshotCatchUpEntries = cfg.ServerConfig.SnapshotCatchUpEntries
cfg.ServerConfig.SnapshotCatchUpEntries = etcdserver.DefaultSnapshotCatchUpEntries
}
}

etcdCfgs := cfg.EtcdAllServerProcessConfigs(t)
Expand Down Expand Up @@ -639,26 +635,13 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in
args = append(args, "--discovery="+cfg.Discovery)
}

var execPath string
switch cfg.Version {
case CurrentVersion:
execPath = BinPath.Etcd
case MinorityLastVersion:
if i <= cfg.ClusterSize/2 {
execPath = BinPath.Etcd
} else {
execPath = BinPath.EtcdLastRelease
}
case QuorumLastVersion:
if i <= cfg.ClusterSize/2 {
execPath = BinPath.EtcdLastRelease
} else {
execPath = BinPath.Etcd
execPath := cfg.binaryPath(i)

if cfg.ServerConfig.SnapshotCatchUpEntries != etcdserver.DefaultSnapshotCatchUpEntries {
if !IsSnapshotCatchupEntriesFlagAvailable(execPath) {
cfg.ServerConfig.ExperimentalSnapshotCatchUpEntries = cfg.ServerConfig.SnapshotCatchUpEntries
cfg.ServerConfig.SnapshotCatchUpEntries = etcdserver.DefaultSnapshotCatchUpEntries
}
case LastVersion:
execPath = BinPath.EtcdLastRelease
default:
panic(fmt.Sprintf("Unknown cluster version %v", cfg.Version))
}

defaultValues := values(*embed.NewConfig())
Expand Down Expand Up @@ -702,6 +685,32 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in
}
}

func (cfg *EtcdProcessClusterConfig) binaryPath(i int) string {
var execPath string
switch cfg.Version {
case CurrentVersion:
execPath = BinPath.Etcd
case MinorityLastVersion:
if i <= cfg.ClusterSize/2 {
execPath = BinPath.Etcd
} else {
execPath = BinPath.EtcdLastRelease
}
case QuorumLastVersion:
if i <= cfg.ClusterSize/2 {
execPath = BinPath.EtcdLastRelease
} else {
execPath = BinPath.Etcd
}
case LastVersion:
execPath = BinPath.EtcdLastRelease
default:
panic(fmt.Sprintf("Unknown cluster version %v", cfg.Version))
}

return execPath
}

func values(cfg embed.Config) map[string]string {
fs := flag.NewFlagSet("etcd", flag.ContinueOnError)
cfg.AddFlags(fs)
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/e2e/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestEtcdServerProcessConfig(t *testing.T) {
name: "CatchUpEntries",
config: NewConfig(WithSnapshotCatchUpEntries(100)),
expectArgsContain: []string{
"--snapshot-catchup-entries=100",
"--experimental-snapshot-catchup-entries=100",
},
mockBinaryVersion: &v3_5_14,
},
Expand Down
6 changes: 3 additions & 3 deletions tests/framework/e2e/etcd_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/coreos/go-semver/semver"
"go.uber.org/zap"

"go.etcd.io/etcd/api/v3/version"
"go.etcd.io/etcd/client/pkg/v3/fileutil"
"go.etcd.io/etcd/pkg/v3/expect"
"go.etcd.io/etcd/pkg/v3/proxy"
Expand Down Expand Up @@ -532,11 +533,10 @@ func CouldSetSnapshotCatchupEntries(execPath string) bool {
return v.Compare(v3_5_14) >= 0
}

func UsesExperimentalSnapshotCatchupEntriesFlag(execPath string) bool {
func IsSnapshotCatchupEntriesFlagAvailable(execPath string) bool {
v, err := GetVersionFromBinary(execPath)
if err != nil {
return false
}
v3_6 := semver.Version{Major: 3, Minor: 6}
return v.LessThan(v3_6)
return !v.LessThan(version.V3_6)
}

0 comments on commit 71cdab4

Please sign in to comment.