Skip to content

Commit 6309127

Browse files
authored
Merge pull request kubernetes#127239 from xuzhenglun/cohabitating-resources
API emulation versioning honors cohabitating resources
2 parents 60cbbdf + cd5b273 commit 6309127

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

staging/src/k8s.io/apiserver/pkg/server/storage/resource_encoding_config.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,24 @@ func emulatedStorageVersion(binaryVersionOfResource schema.GroupVersion, example
130130
gvks, _, err := scheme.ObjectKinds(example)
131131
if err != nil {
132132
return schema.GroupVersion{}, err
133-
} else if len(gvks) == 0 {
134-
// Probably shouldn't happen if err is non-nil
133+
}
134+
135+
var gvk schema.GroupVersionKind
136+
for _, item := range gvks {
137+
if item.Group != binaryVersionOfResource.Group {
138+
continue
139+
}
140+
141+
gvk = item
142+
break
143+
}
144+
145+
if len(gvk.Kind) == 0 {
135146
return schema.GroupVersion{}, fmt.Errorf("object %T has no GVKs registered in scheme", example)
136147
}
137148

138149
// VersionsForGroupKind returns versions in priority order
139-
versions := scheme.VersionsForGroupKind(schema.GroupKind{Group: gvks[0].Group, Kind: gvks[0].Kind})
150+
versions := scheme.VersionsForGroupKind(schema.GroupKind{Group: gvk.Group, Kind: gvk.Kind})
140151

141152
compatibilityVersion := effectiveVersion.MinCompatibilityVersion()
142153

@@ -148,7 +159,7 @@ func emulatedStorageVersion(binaryVersionOfResource schema.GroupVersion, example
148159
gvk := schema.GroupVersionKind{
149160
Group: gv.Group,
150161
Version: gv.Version,
151-
Kind: gvks[0].Kind,
162+
Kind: gvk.Kind,
152163
}
153164

154165
exampleOfGVK, err := scheme.New(gvk)

staging/src/k8s.io/apiserver/pkg/server/storage/storage_factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (s *DefaultStorageFactory) NewConfig(groupResource schema.GroupResource, ex
245245

246246
var err error
247247
if backwardCompatibleInterface, ok := s.ResourceEncodingConfig.(CompatibilityResourceEncodingConfig); ok {
248-
codecConfig.StorageVersion, err = backwardCompatibleInterface.BackwardCompatibileStorageEncodingFor(groupResource, example)
248+
codecConfig.StorageVersion, err = backwardCompatibleInterface.BackwardCompatibileStorageEncodingFor(chosenStorageResource, example)
249249
if err != nil {
250250
return nil, err
251251
}

0 commit comments

Comments
 (0)