Skip to content

Commit

Permalink
Merge pull request #99951 from deads2k/fix-decodableversions
Browse files Browse the repository at this point in the history
provide directly decodable versions for storageversion API

Kubernetes-commit: 08b11727f5b27ad1d123e3a23e769e170ed99a5a
  • Loading branch information
k8s-publishing-bot committed Mar 10, 2021
2 parents 98d3ae9 + a13af10 commit 1f1bc58
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pkg/runtime/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,32 @@ func (s *Scheme) KnownTypes(gv schema.GroupVersion) map[string]reflect.Type {
return types
}

// VersionsForGroupKind returns the versions that a particular GroupKind can be converted to within the given group.
// A GroupKind might be converted to a different group. That information is available in EquivalentResourceMapper.
func (s *Scheme) VersionsForGroupKind(gk schema.GroupKind) []schema.GroupVersion {
availableVersions := []schema.GroupVersion{}
for gvk := range s.gvkToType {
if gk != gvk.GroupKind() {
continue
}

availableVersions = append(availableVersions, gvk.GroupVersion())
}

// order the return for stability
ret := []schema.GroupVersion{}
for _, version := range s.PrioritizedVersionsForGroup(gk.Group) {
for _, availableVersion := range availableVersions {
if version != availableVersion {
continue
}
ret = append(ret, availableVersion)
}
}

return ret
}

// AllKnownTypes returns the all known types.
func (s *Scheme) AllKnownTypes() map[schema.GroupVersionKind]reflect.Type {
return s.gvkToType
Expand Down

0 comments on commit 1f1bc58

Please sign in to comment.