Skip to content

Commit

Permalink
fix group mapping and encoding order
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Feb 15, 2016
1 parent a49c363 commit f89bd83
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
26 changes: 14 additions & 12 deletions pkg/apimachinery/registered/registered.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,24 @@ func IsEnabledVersion(v unversioned.GroupVersion) bool {
return found
}

// EnabledVersions returns all enabled versions.
func EnabledVersions() (ret []unversioned.GroupVersion) {
for v := range enabledVersions {
ret = append(ret, v)
// EnabledVersions returns all enabled versions. Groups are randomly ordered, but versions within groups
// are priority order from best to worst
func EnabledVersions() []unversioned.GroupVersion {
ret := []unversioned.GroupVersion{}
for _, groupMeta := range groupMetaMap {
ret = append(ret, groupMeta.GroupVersions...)
}
return
return ret
}

// EnabledVersionsForGroup returns all enabled versions for a group.
func EnabledVersionsForGroup(group string) (ret []unversioned.GroupVersion) {
for v := range enabledVersions {
if v.Group == group {
ret = append(ret, v)
}
// EnabledVersionsForGroup returns all enabled versions for a group in order of best to worst
func EnabledVersionsForGroup(group string) []unversioned.GroupVersion {
groupMeta, ok := groupMetaMap[group]
if !ok {
return []unversioned.GroupVersion{}
}
return

return append([]unversioned.GroupVersion{}, groupMeta.GroupVersions...)
}

// Group returns the metadata of a group if the gruop is registered, otherwise
Expand Down
8 changes: 8 additions & 0 deletions pkg/runtime/serializer/versioning/versioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,20 @@ func NewCodec(
if encodeVersion != nil {
internal.encodeVersion = make(map[string]unversioned.GroupVersion)
for _, v := range encodeVersion {
// first one for a group wins. This is consistent with best to worst order throughout the codebase
if _, ok := internal.encodeVersion[v.Group]; ok {
continue
}
internal.encodeVersion[v.Group] = v
}
}
if decodeVersion != nil {
internal.decodeVersion = make(map[string]unversioned.GroupVersion)
for _, v := range decodeVersion {
// first one for a group wins. This is consistent with best to worst order throughout the codebase
if _, ok := internal.decodeVersion[v.Group]; ok {
continue
}
internal.decodeVersion[v.Group] = v
}
}
Expand Down

0 comments on commit f89bd83

Please sign in to comment.