Skip to content

Commit

Permalink
UPSTREAM: <carry>: allow specific, skewed group/versions
Browse files Browse the repository at this point in the history
:100644 100644 2328ffc... a876a74... M	pkg/apiserver/api_installer.go
:100644 100644 471bcd5... 2c8c2f9... M	pkg/apiserver/apiserver.go
  • Loading branch information
liggitt authored and pweil- committed Feb 12, 2016
1 parent cd80cb6 commit 1101efb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/apiserver/api_installer.go
Expand Up @@ -142,6 +142,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
for _, fqKind := range fqKinds {
if fqKind.Group == a.group.GroupVersion.Group {
fqKindToRegister = fqKind
fqKindToRegister.Version = a.group.GroupVersion.Version
break
}

Expand All @@ -153,19 +154,24 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
}
}

// Allow overriding the group/version/kind for a given path
if nonDefaultGroupVersionKind, exists := a.group.NonDefaultGroupVersionKinds[path]; exists {
fqKindToRegister = nonDefaultGroupVersionKind
}

kind := fqKindToRegister.Kind

if fqKindToRegister.IsEmpty() {
return nil, fmt.Errorf("unable to locate fully qualified kind for %v: found %v when registering for %v", reflect.TypeOf(object), fqKinds, a.group.GroupVersion)
}

versionedPtr, err := a.group.Creater.New(a.group.GroupVersion.WithKind(kind))
versionedPtr, err := a.group.Creater.New(fqKindToRegister)
if err != nil {
return nil, err
}
versionedObject := indirectArbitraryPointer(versionedPtr)

mapping, err := a.group.Mapper.RESTMapping(fqKindToRegister.GroupKind(), a.group.GroupVersion.Version)
mapping, err := a.group.Mapper.RESTMapping(fqKindToRegister.GroupKind(), fqKindToRegister.Version)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -454,7 +460,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag

Resource: a.group.GroupVersion.WithResource(resource),
Subresource: subresource,
Kind: a.group.GroupVersion.WithKind(kind),
Kind: fqKindToRegister,
}
for _, action := range actions {
reqScope.Namer = action.Namer
Expand Down
5 changes: 5 additions & 0 deletions pkg/apiserver/apiserver.go
Expand Up @@ -67,6 +67,11 @@ type Mux interface {
type APIGroupVersion struct {
Storage map[string]rest.Storage

// NonDefaultGroupVersionKinds is a map of resource[/subresource] to the group/version/kind to use for serialization of the rest.Storage kind.
// Missing entries simply preserve existing behavior (uses .GroupVersion + rest.Storage kind).
// This allows a single rest.Storage to be registered in multiple APIGroupVersions with different serializations in each one.
NonDefaultGroupVersionKinds map[string]unversioned.GroupVersionKind

Root string

// GroupVersion is the external group version
Expand Down

0 comments on commit 1101efb

Please sign in to comment.