mirror of https://github.com/k3s-io/k3s
Merge pull request #44462 from deads2k/server-21-selflink
Automatic merge from submit-queue (batch tested with PRs 42477, 44462) fix cluster scoped self-link Might fix #37622, definitely fixes the cluster-scoped resource problem. Looks like it was just a typo when compared against https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/endpoints/installer.go#L451 @adohe @DirectXMan12pull/6/head
commit
cd380b580b
|
@ -1271,6 +1271,46 @@ func TestSelfLinkSkipsEmptyName(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRootSelfLink(t *testing.T) {
|
||||||
|
storage := map[string]rest.Storage{}
|
||||||
|
simpleStorage := GetWithOptionsRootRESTStorage{
|
||||||
|
SimpleTypedStorage: &SimpleTypedStorage{
|
||||||
|
baseType: &genericapitesting.SimpleRoot{}, // a root scoped type
|
||||||
|
item: &genericapitesting.SimpleRoot{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
|
||||||
|
Other: "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
takesPath: "atAPath",
|
||||||
|
}
|
||||||
|
storage["simple"] = &simpleStorage
|
||||||
|
handler := handle(storage)
|
||||||
|
server := httptest.NewServer(handler)
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
resp, err := http.Get(server.URL + "/" + prefix + "/" + testGroupVersion.Group + "/" + testGroupVersion.Version + "/simple/foo")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
t.Errorf("Unexpected status: %d, Expected: %d, %#v", resp.StatusCode, http.StatusOK, resp)
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
t.Logf("Data: %s", string(body))
|
||||||
|
}
|
||||||
|
var out genericapitesting.SimpleRoot
|
||||||
|
if _, err := extractBody(resp, &out); err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if out.SelfLink != "/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/simple/foo" {
|
||||||
|
t.Errorf("unexpected self link: %#v", out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestMetadata(t *testing.T) {
|
func TestMetadata(t *testing.T) {
|
||||||
simpleStorage := &MetadataRESTStorage{&SimpleRESTStorage{}, []string{"text/plain"}}
|
simpleStorage := &MetadataRESTStorage{&SimpleRESTStorage{}, []string{"text/plain"}}
|
||||||
h := handle(map[string]rest.Storage{"simple": simpleStorage})
|
h := handle(map[string]rest.Storage{"simple": simpleStorage})
|
||||||
|
|
|
@ -393,7 +393,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
||||||
GetContext: ctxFn,
|
GetContext: ctxFn,
|
||||||
SelfLinker: a.group.Linker,
|
SelfLinker: a.group.Linker,
|
||||||
ClusterScoped: true,
|
ClusterScoped: true,
|
||||||
SelfLinkPathPrefix: gpath.Join(a.prefix, resourcePath, "/"),
|
SelfLinkPathPrefix: gpath.Join(a.prefix, resourcePath) + "/",
|
||||||
SelfLinkPathSuffix: suffix,
|
SelfLinkPathSuffix: suffix,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue