Prefer non-alpha storage versions when available

This commit is contained in:
Jordan Liggitt 2023-08-17 09:33:22 -04:00
parent 09fa21ab87
commit af9bf7b41e
No known key found for this signature in database

View File

@ -169,28 +169,37 @@ func TestEtcdStoragePath(t *testing.T) {
fixtureFilenameGroup = "core"
}
// find all versions of this group/kind in all versions of the serialization fixture testdata
previousReleaseGroupKindFiles, err := filepath.Glob("../../../staging/src/k8s.io/api/testdata/*/" + fixtureFilenameGroup + ".*." + expectedGVK.Kind + ".yaml")
releaseGroupKindFiles, err := filepath.Glob("../../../staging/src/k8s.io/api/testdata/*/" + fixtureFilenameGroup + ".*." + expectedGVK.Kind + ".yaml")
if err != nil {
t.Error(err)
}
if len(previousReleaseGroupKindFiles) == 0 && !allowMissingTestdataFixtures[expectedGVK] {
if len(releaseGroupKindFiles) == 0 && !allowMissingTestdataFixtures[expectedGVK] {
// We should at least find the HEAD fixtures
t.Errorf("No testdata serialization files found for %#v, cannot determine if previous releases could read this group/kind. Add this group-version to k8s.io/api/roundtrip_test.go", expectedGVK)
}
// find non-alpha versions of this group/kind understood by previous releases
// find non-alpha versions of this group/kind understood by current and previous releases
currentNonAlphaVersions := sets.NewString()
previousNonAlphaVersions := sets.NewString()
for _, previousReleaseGroupKindFile := range previousReleaseGroupKindFiles {
if serverVersion := filepath.Base(filepath.Dir(previousReleaseGroupKindFile)); serverVersion == "HEAD" {
continue
}
for _, previousReleaseGroupKindFile := range releaseGroupKindFiles {
parts := strings.Split(filepath.Base(previousReleaseGroupKindFile), ".")
version := parts[len(parts)-3]
if !strings.Contains(version, "alpha") {
if serverVersion := filepath.Base(filepath.Dir(previousReleaseGroupKindFile)); serverVersion == "HEAD" {
currentNonAlphaVersions.Insert(version)
} else {
previousNonAlphaVersions.Insert(version)
}
}
if len(previousNonAlphaVersions) > 0 && !previousNonAlphaVersions.Has(expectedGVK.Version) {
t.Errorf("Previous releases understand non-alpha versions %q, but do not understand the expected current storage version %q. "+
}
if len(currentNonAlphaVersions) > 0 && strings.Contains(expectedGVK.Version, "alpha") {
t.Errorf("Non-alpha versions %q exist, but the expected storage version is %q. Prefer beta or GA storage versions over alpha.",
currentNonAlphaVersions.List(),
expectedGVK.Version,
)
}
if !strings.Contains(expectedGVK.Version, "alpha") && len(previousNonAlphaVersions) > 0 && !previousNonAlphaVersions.Has(expectedGVK.Version) {
t.Errorf("Previous releases understand non-alpha versions %q, but do not understand the expected current non-alpha storage version %q. "+
"This means a current server will store data in etcd that is not understood by a previous version.",
previousNonAlphaVersions.List(),
expectedGVK.Version,