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 @DirectXMan12
pull/6/head
Kubernetes Submit Queue 2017-04-25 10:25:46 -07:00 committed by GitHub
commit cd380b580b
2 changed files with 41 additions and 1 deletions

View File

@ -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) {
simpleStorage := &MetadataRESTStorage{&SimpleRESTStorage{}, []string{"text/plain"}}
h := handle(map[string]rest.Storage{"simple": simpleStorage})

View File

@ -393,7 +393,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
GetContext: ctxFn,
SelfLinker: a.group.Linker,
ClusterScoped: true,
SelfLinkPathPrefix: gpath.Join(a.prefix, resourcePath, "/"),
SelfLinkPathPrefix: gpath.Join(a.prefix, resourcePath) + "/",
SelfLinkPathSuffix: suffix,
}