mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
support selflink from customresources
This commit is contained in:
parent
7341b4ff13
commit
ed1ce003ef
@ -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)
|
||||||
|
@ -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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user