Merge pull request #46396 from xiangpengzhao/fix-selflink

Automatic merge from submit-queue (batch tested with PRs 46432, 46701, 46326, 40848, 46396)

Fix selfLinks of pods started from manifests

**What this PR does / why we need it**:
When running `curl http://localhost:10255/pods` the selfLink for pods started from manifests were incorrect. This PR fixes it.

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #46357

**Special notes for your reviewer**:

@number101010

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue
2017-06-02 11:47:14 -07:00
committed by GitHub
2 changed files with 29 additions and 1 deletions

View File

@@ -93,7 +93,7 @@ func getSelfLink(name, namespace string) string {
if len(namespace) == 0 {
namespace = metav1.NamespaceDefault
}
selfLink = fmt.Sprintf("/api/"+api.Registry.GroupOrDie(api.GroupName).GroupVersion.Version+"/pods/namespaces/%s/%s", name, namespace)
selfLink = fmt.Sprintf("/api/"+api.Registry.GroupOrDie(api.GroupName).GroupVersion.Version+"/namespaces/%s/pods/%s", namespace, name)
return selfLink
}

View File

@@ -160,3 +160,31 @@ func TestDecodePodList(t *testing.T) {
}
}
}
func TestGetSelfLink(t *testing.T) {
var testCases = []struct {
desc string
name string
namespace string
expectedSelfLink string
}{
{
desc: "No namespace specified",
name: "foo",
namespace: "",
expectedSelfLink: "/api/v1/namespaces/default/pods/foo",
},
{
desc: "Namespace specified",
name: "foo",
namespace: "bar",
expectedSelfLink: "/api/v1/namespaces/bar/pods/foo",
},
}
for _, testCase := range testCases {
selfLink := getSelfLink(testCase.name, testCase.namespace)
if testCase.expectedSelfLink != selfLink {
t.Errorf("%s: getSelfLink error, expected: %s, got: %s", testCase.desc, testCase.expectedSelfLink, selfLink)
}
}
}