Don't pick versions that have a replacement as storage version

This commit is contained in:
Joe Betz 2024-10-30 11:47:43 -04:00
parent d001d5684e
commit af811be190

View File

@ -117,6 +117,10 @@ type introducedInterface interface {
APILifecycleIntroduced() (major, minor int)
}
type replacementInterface interface {
APILifecycleReplacement() schema.GroupVersionKind
}
func emulatedStorageVersion(binaryVersionOfResource schema.GroupVersion, example runtime.Object, effectiveVersion version.EffectiveVersion, scheme *runtime.Scheme) (schema.GroupVersion, error) {
if example == nil || effectiveVersion == nil {
return binaryVersionOfResource, nil
@ -170,6 +174,14 @@ func emulatedStorageVersion(binaryVersionOfResource schema.GroupVersion, example
// If it was introduced after current compatibility version, don't use it
// skip the introduced check for test when currentVersion is 0.0 to test all apis
if introduced, hasIntroduced := exampleOfGVK.(introducedInterface); hasIntroduced && (compatibilityVersion.Major() > 0 || compatibilityVersion.Minor() > 0) {
// Skip versions that have a replacement.
// This can be used to override this storage version selection by
// marking a storage version has having a replacement and preventing a
// that storage version from being selected.
if _, hasReplacement := exampleOfGVK.(replacementInterface); hasReplacement {
continue
}
// API resource lifecycles should be relative to k8s api version
majorIntroduced, minorIntroduced := introduced.APILifecycleIntroduced()
introducedVer := apimachineryversion.MajorMinor(uint(majorIntroduced), uint(minorIntroduced))