Skip to content

Commit

Permalink
API emulation versioning honors cohabitating resources
Browse files Browse the repository at this point in the history
Kubernetes-commit: 880e026a07ce18372a462ba45e386d147cae0120
  • Loading branch information
xuzhenglun authored and k8s-publishing-bot committed Sep 9, 2024
1 parent 1d6f7ca commit 3178497
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions pkg/server/storage/resource_encoding_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/storage/storage_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 3178497

Please sign in to comment.