From af9bf7b41e08984cee83d5c4e3054156d8e4e27c Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Thu, 17 Aug 2023 09:33:22 -0400 Subject: [PATCH] Prefer non-alpha storage versions when available --- .../etcd/etcd_storage_path_test.go | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/test/integration/etcd/etcd_storage_path_test.go b/test/integration/etcd/etcd_storage_path_test.go index 53c24eb37c6..34858b03cab 100644 --- a/test/integration/etcd/etcd_storage_path_test.go +++ b/test/integration/etcd/etcd_storage_path_test.go @@ -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") { - previousNonAlphaVersions.Insert(version) + 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,