support selflink from customresources

This commit is contained in:
deads2k 2017-05-15 08:24:12 -04:00
parent 7341b4ff13
commit ed1ce003ef
2 changed files with 14 additions and 2 deletions

View File

@ -20,6 +20,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"net/http" "net/http"
"path"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -257,6 +258,14 @@ func (r *customResourceDefinitionHandler) getServingInfoFor(customResourceDefini
parameterScheme.AddGeneratedDeepCopyFuncs(metav1.GetGeneratedDeepCopyFuncs()...) parameterScheme.AddGeneratedDeepCopyFuncs(metav1.GetGeneratedDeepCopyFuncs()...)
parameterCodec := runtime.NewParameterCodec(parameterScheme) parameterCodec := runtime.NewParameterCodec(parameterScheme)
selfLinkPrefix := ""
switch customResourceDefinition.Spec.Scope {
case apiextensions.ClusterScoped:
selfLinkPrefix = "/" + path.Join("apis", customResourceDefinition.Spec.Group, customResourceDefinition.Spec.Version) + "/"
case apiextensions.NamespaceScoped:
selfLinkPrefix = "/" + path.Join("apis", customResourceDefinition.Spec.Group, customResourceDefinition.Spec.Version, "namespaces") + "/"
}
requestScope := handlers.RequestScope{ requestScope := handlers.RequestScope{
Namer: handlers.ContextBasedNaming{ Namer: handlers.ContextBasedNaming{
GetContext: func(req *http.Request) apirequest.Context { GetContext: func(req *http.Request) apirequest.Context {
@ -265,6 +274,7 @@ func (r *customResourceDefinitionHandler) getServingInfoFor(customResourceDefini
}, },
SelfLinker: meta.NewAccessor(), SelfLinker: meta.NewAccessor(),
ClusterScoped: customResourceDefinition.Spec.Scope == apiextensions.ClusterScoped, ClusterScoped: customResourceDefinition.Spec.Scope == apiextensions.ClusterScoped,
SelfLinkPathPrefix: selfLinkPrefix,
}, },
ContextFunc: func(req *http.Request) apirequest.Context { ContextFunc: func(req *http.Request) apirequest.Context {
ret, _ := r.requestContextMapper.Get(req) ret, _ := r.requestContextMapper.Get(req)

View File

@ -197,4 +197,6 @@ func TestSelfLink(t *testing.T) {
t.Errorf("expected %v, got %v", e, a) t.Errorf("expected %v, got %v", e, a)
} }
// TODO add test for cluster scoped self-link when its available
} }