Merge pull request #127328 from xuzhenglun/automated-cherry-pick-of-#127239-github-release-1.31

Automated cherry pick of #127239: API emulation versioning honors cohabitating resources

Kubernetes-commit: 87bc649cbb3608ed2afbfdfd830326b318564258
This commit is contained in:
Kubernetes Publisher 2024-10-10 13:30:23 +01:00
commit 62d807d9f4
2 changed files with 16 additions and 5 deletions

View File

@ -130,13 +130,24 @@ func emulatedStorageVersion(binaryVersionOfResource schema.GroupVersion, example
gvks, _, err := scheme.ObjectKinds(example)
if err != nil {
return schema.GroupVersion{}, err
} else if len(gvks) == 0 {
// Probably shouldn't happen if err is non-nil
}
var gvk schema.GroupVersionKind
for _, item := range gvks {
if item.Group != binaryVersionOfResource.Group {
continue
}
gvk = item
break
}
if len(gvk.Kind) == 0 {
return schema.GroupVersion{}, fmt.Errorf("object %T has no GVKs registered in scheme", example)
}
// VersionsForGroupKind returns versions in priority order
versions := scheme.VersionsForGroupKind(schema.GroupKind{Group: gvks[0].Group, Kind: gvks[0].Kind})
versions := scheme.VersionsForGroupKind(schema.GroupKind{Group: gvk.Group, Kind: gvk.Kind})
compatibilityVersion := effectiveVersion.MinCompatibilityVersion()
@ -148,7 +159,7 @@ func emulatedStorageVersion(binaryVersionOfResource schema.GroupVersion, example
gvk := schema.GroupVersionKind{
Group: gv.Group,
Version: gv.Version,
Kind: gvks[0].Kind,
Kind: gvk.Kind,
}
exampleOfGVK, err := scheme.New(gvk)

View File

@ -245,7 +245,7 @@ func (s *DefaultStorageFactory) NewConfig(groupResource schema.GroupResource, ex
var err error
if backwardCompatibleInterface, ok := s.ResourceEncodingConfig.(CompatibilityResourceEncodingConfig); ok {
codecConfig.StorageVersion, err = backwardCompatibleInterface.BackwardCompatibileStorageEncodingFor(groupResource, example)
codecConfig.StorageVersion, err = backwardCompatibleInterface.BackwardCompatibileStorageEncodingFor(chosenStorageResource, example)
if err != nil {
return nil, err
}