Commit 83f91587 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

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 ```
parents 97a5d378 4ec3fc4e
...@@ -93,7 +93,7 @@ func getSelfLink(name, namespace string) string { ...@@ -93,7 +93,7 @@ func getSelfLink(name, namespace string) string {
if len(namespace) == 0 { if len(namespace) == 0 {
namespace = metav1.NamespaceDefault 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 return selfLink
} }
......
...@@ -160,3 +160,31 @@ func TestDecodePodList(t *testing.T) { ...@@ -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)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment