diff --git a/pkg/api/testapi/testapi.go b/pkg/api/testapi/testapi.go index 6801b77abaa..5c8a0b7afb7 100644 --- a/pkg/api/testapi/testapi.go +++ b/pkg/api/testapi/testapi.go @@ -22,7 +22,6 @@ import ( "os" "strings" - "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" @@ -79,20 +78,17 @@ func SelfLink(resource, name string) string { // Returns the appropriate path for the given prefix (watch, proxy, redirect, etc), resource, namespace and name. // For ex, this is of the form: -// /api/v1beta1/watch/pods/pod0 for v1beta1 and -// /api/v1beta3/watch/namespaces/foo/pods/pod0 for v1beta3. +// /api/v1/watch/namespaces/foo/pods/pod0 for v1. func ResourcePathWithPrefix(prefix, resource, namespace, name string) string { path := "/api/" + Version() if prefix != "" { path = path + "/" + prefix } - if !api.PreV1Beta3(Version()) { - if namespace != "" { - path = path + "/namespaces/" + namespace - } - // Resource names in v1beta3 are lower case. - resource = strings.ToLower(resource) + if namespace != "" { + path = path + "/namespaces/" + namespace } + // Resource names are lower case. + resource = strings.ToLower(resource) if resource != "" { path = path + "/" + resource } @@ -109,20 +105,3 @@ func ResourcePathWithPrefix(prefix, resource, namespace, name string) string { func ResourcePath(resource, namespace, name string) string { return ResourcePathWithPrefix("", resource, namespace, name) } - -// Returns the appropriate path along with the query params for the given resource, namespace and name. -// For ex, this is of the form: -// /api/v1beta1/pods/pod0?namespace=foo for v1beta1 and -// /api/v1beta3/namespaces/foo/pods/pod0 for v1beta3. -func ResourcePathWithNamespaceQuery(resource, namespace, name string) string { - return ResourcePathWithPrefixAndNamespaceQuery("", resource, namespace, name) -} - -func ResourcePathWithPrefixAndNamespaceQuery(prefix, resource, namespace, name string) string { - path := ResourcePathWithPrefix(prefix, resource, namespace, name) - // Add namespace as query param for pre v1beta3. - if api.PreV1Beta3(Version()) && namespace != "" { - path = path + "?namespace=" + namespace - } - return path -} diff --git a/pkg/api/testapi/testapi_test.go b/pkg/api/testapi/testapi_test.go index 00b87d43d60..220833a2045 100644 --- a/pkg/api/testapi/testapi_test.go +++ b/pkg/api/testapi/testapi_test.go @@ -59,22 +59,3 @@ func TestResourcePath(t *testing.T) { } } } - -func TestResourcePathWithNamespaceQuery(t *testing.T) { - testCases := []struct { - resource string - namespace string - name string - expected string - }{ - {"resource", "mynamespace", "myresource", "/api/" + Version() + "/namespaces/mynamespace/resource/myresource"}, - {"resource", "", "myresource", "/api/" + Version() + "/resource/myresource"}, - {"resource", "mynamespace", "", "/api/" + Version() + "/namespaces/mynamespace/resource"}, - {"resource", "", "", "/api/" + Version() + "/resource"}, - } - for _, item := range testCases { - if actual := ResourcePathWithNamespaceQuery(item.resource, item.namespace, item.name); actual != item.expected { - t.Errorf("Expected: %s, got: %s for resource: %s, namespace: %s and name: %s", item.expected, actual, item.resource, item.namespace, item.name) - } - } -} diff --git a/pkg/apiserver/handlers_test.go b/pkg/apiserver/handlers_test.go index f017e47b942..994320d76a7 100644 --- a/pkg/apiserver/handlers_test.go +++ b/pkg/apiserver/handlers_test.go @@ -53,18 +53,10 @@ func getPath(resource, namespace, name string) string { return testapi.ResourcePath(resource, namespace, name) } -func pathWithNamespaceQuery(resource, namespace, name string) string { - return testapi.ResourcePathWithNamespaceQuery(resource, namespace, name) -} - func pathWithPrefix(prefix, resource, namespace, name string) string { return testapi.ResourcePathWithPrefix(prefix, resource, namespace, name) } -func pathWithPrefixAndNamespaceQuery(prefix, resource, namespace, name string) string { - return testapi.ResourcePathWithPrefixAndNamespaceQuery(prefix, resource, namespace, name) -} - func TestMaxInFlight(t *testing.T) { const Iterations = 3 block := sync.WaitGroup{} @@ -185,15 +177,15 @@ func TestGetAPIRequestInfo(t *testing.T) { {"GET", "/watch/namespaces/other/pods", "watch", "", "other", "pods", "", "Pod", "", []string{"pods"}}, // fully-qualified paths - {"GET", pathWithNamespaceQuery("pods", "other", ""), "list", testapi.Version(), "other", "pods", "", "Pod", "", []string{"pods"}}, - {"GET", pathWithNamespaceQuery("pods", "other", "foo"), "get", testapi.Version(), "other", "pods", "", "Pod", "foo", []string{"pods", "foo"}}, + {"GET", getPath("pods", "other", ""), "list", testapi.Version(), "other", "pods", "", "Pod", "", []string{"pods"}}, + {"GET", getPath("pods", "other", "foo"), "get", testapi.Version(), "other", "pods", "", "Pod", "foo", []string{"pods", "foo"}}, {"GET", getPath("pods", "", ""), "list", testapi.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}}, {"POST", getPath("pods", "", ""), "create", testapi.Version(), api.NamespaceDefault, "pods", "", "Pod", "", []string{"pods"}}, {"GET", getPath("pods", "", "foo"), "get", testapi.Version(), api.NamespaceDefault, "pods", "", "Pod", "foo", []string{"pods", "foo"}}, {"GET", pathWithPrefix("proxy", "pods", "", "foo"), "proxy", testapi.Version(), api.NamespaceDefault, "pods", "", "Pod", "foo", []string{"pods", "foo"}}, {"GET", pathWithPrefix("watch", "pods", "", ""), "watch", testapi.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}}, - {"GET", pathWithPrefixAndNamespaceQuery("redirect", "pods", "", ""), "redirect", testapi.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}}, - {"GET", pathWithPrefixAndNamespaceQuery("watch", "pods", "other", ""), "watch", testapi.Version(), "other", "pods", "", "Pod", "", []string{"pods"}}, + {"GET", pathWithPrefix("redirect", "pods", "", ""), "redirect", testapi.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}}, + {"GET", pathWithPrefix("watch", "pods", "other", ""), "watch", testapi.Version(), "other", "pods", "", "Pod", "", []string{"pods"}}, // subresource identification {"GET", "/namespaces/other/pods/foo/status", "get", "", "other", "pods", "status", "Pod", "foo", []string{"pods", "foo", "status"}}, diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 61de62876de..6f5cf5aa44b 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -67,8 +67,8 @@ func TestCreateObjects(t *testing.T) { typer, mapper := getTyperAndMapper() client, s := getFakeClient(t, []string{ - testapi.ResourcePathWithNamespaceQuery("pods", api.NamespaceDefault, ""), - testapi.ResourcePathWithNamespaceQuery("services", api.NamespaceDefault, ""), + testapi.ResourcePath("pods", api.NamespaceDefault, ""), + testapi.ResourcePath("services", api.NamespaceDefault, ""), }) errs := CreateObjects(typer, mapper, client, items) diff --git a/pkg/controller/replication_controller_test.go b/pkg/controller/replication_controller_test.go index bdc0f9af144..f6af8f8dbdd 100644 --- a/pkg/controller/replication_controller_test.go +++ b/pkg/controller/replication_controller_test.go @@ -328,7 +328,7 @@ func TestCreateReplica(t *testing.T) { }, Spec: controllerSpec.Spec.Template.Spec, } - fakeHandler.ValidateRequest(t, testapi.ResourcePathWithNamespaceQuery("pods", api.NamespaceDefault, ""), "POST", nil) + fakeHandler.ValidateRequest(t, testapi.ResourcePath("pods", api.NamespaceDefault, ""), "POST", nil) actualPod, err := client.Codec.Decode([]byte(fakeHandler.RequestBody)) if err != nil { t.Errorf("Unexpected error: %#v", err) @@ -397,7 +397,7 @@ func TestControllerUpdateReplicas(t *testing.T) { rc.Status = api.ReplicationControllerStatus{Replicas: 4} decRc := runtime.EncodeOrDie(testapi.Codec(), rc) - fakeHandler.ValidateRequest(t, testapi.ResourcePathWithNamespaceQuery(replicationControllerResourceName(), rc.Namespace, rc.Name), "PUT", &decRc) + fakeHandler.ValidateRequest(t, testapi.ResourcePath(replicationControllerResourceName(), rc.Namespace, rc.Name), "PUT", &decRc) validateSyncReplication(t, &fakePodControl, 1, 0) } diff --git a/pkg/service/endpoints_controller_test.go b/pkg/service/endpoints_controller_test.go index d2add23e058..c34a79abba5 100644 --- a/pkg/service/endpoints_controller_test.go +++ b/pkg/service/endpoints_controller_test.go @@ -318,7 +318,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) { Ports: []api.EndpointPort{{Port: 8080, Protocol: "TCP"}}, }}, }) - endpointsHandler.ValidateRequest(t, testapi.ResourcePathWithNamespaceQuery("endpoints", ns, "foo"), "PUT", &data) + endpointsHandler.ValidateRequest(t, testapi.ResourcePath("endpoints", ns, "foo"), "PUT", &data) } func TestSyncEndpointsItemsPreexisting(t *testing.T) { @@ -358,7 +358,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) { Ports: []api.EndpointPort{{Port: 8080, Protocol: "TCP"}}, }}, }) - endpointsHandler.ValidateRequest(t, testapi.ResourcePathWithNamespaceQuery("endpoints", ns, "foo"), "PUT", &data) + endpointsHandler.ValidateRequest(t, testapi.ResourcePath("endpoints", ns, "foo"), "PUT", &data) } func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) { @@ -387,7 +387,7 @@ func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) { }, }) endpoints.syncService(ns + "/foo") - endpointsHandler.ValidateRequest(t, testapi.ResourcePathWithNamespaceQuery("endpoints", api.NamespaceDefault, "foo"), "GET", nil) + endpointsHandler.ValidateRequest(t, testapi.ResourcePath("endpoints", api.NamespaceDefault, "foo"), "GET", nil) } func TestSyncEndpointsItems(t *testing.T) { @@ -429,7 +429,7 @@ func TestSyncEndpointsItems(t *testing.T) { }) // endpointsHandler should get 2 requests - one for "GET" and the next for "POST". endpointsHandler.ValidateRequestCount(t, 2) - endpointsHandler.ValidateRequest(t, testapi.ResourcePathWithNamespaceQuery("endpoints", ns, ""), "POST", &data) + endpointsHandler.ValidateRequest(t, testapi.ResourcePath("endpoints", ns, ""), "POST", &data) } func TestSyncEndpointsItemsWithLabels(t *testing.T) { @@ -476,7 +476,7 @@ func TestSyncEndpointsItemsWithLabels(t *testing.T) { }) // endpointsHandler should get 2 requests - one for "GET" and the next for "POST". endpointsHandler.ValidateRequestCount(t, 2) - endpointsHandler.ValidateRequest(t, testapi.ResourcePathWithNamespaceQuery("endpoints", ns, ""), "POST", &data) + endpointsHandler.ValidateRequest(t, testapi.ResourcePath("endpoints", ns, ""), "POST", &data) } func TestSyncEndpointsItemsPreexistingLabelsChange(t *testing.T) { @@ -525,5 +525,5 @@ func TestSyncEndpointsItemsPreexistingLabelsChange(t *testing.T) { Ports: []api.EndpointPort{{Port: 8080, Protocol: "TCP"}}, }}, }) - endpointsHandler.ValidateRequest(t, testapi.ResourcePathWithNamespaceQuery("endpoints", ns, "foo"), "PUT", &data) + endpointsHandler.ValidateRequest(t, testapi.ResourcePath("endpoints", ns, "foo"), "PUT", &data) } diff --git a/plugin/pkg/scheduler/factory/factory_test.go b/plugin/pkg/scheduler/factory/factory_test.go index c1b37ad8e41..154c9bf854b 100644 --- a/plugin/pkg/scheduler/factory/factory_test.go +++ b/plugin/pkg/scheduler/factory/factory_test.go @@ -170,7 +170,7 @@ func TestDefaultErrorFunc(t *testing.T) { if !exists { continue } - handler.ValidateRequest(t, testapi.ResourcePathWithNamespaceQuery("pods", "bar", "foo"), "GET", nil) + handler.ValidateRequest(t, testapi.ResourcePath("pods", "bar", "foo"), "GET", nil) if e, a := testPod, got; !reflect.DeepEqual(e, a) { t.Errorf("Expected %v, got %v", e, a) } @@ -241,7 +241,7 @@ func TestBind(t *testing.T) { continue } expectedBody := runtime.EncodeOrDie(testapi.Codec(), item.binding) - handler.ValidateRequest(t, testapi.ResourcePathWithNamespaceQuery("bindings", api.NamespaceDefault, ""), "POST", &expectedBody) + handler.ValidateRequest(t, testapi.ResourcePath("bindings", api.NamespaceDefault, ""), "POST", &expectedBody) } } diff --git a/test/integration/auth_test.go b/test/integration/auth_test.go index ada2c441df7..6e4dcb31096 100644 --- a/test/integration/auth_test.go +++ b/test/integration/auth_test.go @@ -78,10 +78,6 @@ func path(resource, namespace, name string) string { return testapi.ResourcePath(resource, namespace, name) } -func pathWithNamespaceQuery(resource, namespace, name string) string { - return testapi.ResourcePathWithNamespaceQuery(resource, namespace, name) -} - func pathWithPrefix(prefix, resource, namespace, name string) string { return testapi.ResourcePathWithPrefix(prefix, resource, namespace, name) } @@ -90,10 +86,6 @@ func timeoutPath(resource, namespace, name string) string { return addTimeoutFlag(testapi.ResourcePath(resource, namespace, name)) } -func timeoutPathWithNamespaceQuery(resource, namespace, name string) string { - return addTimeoutFlag(testapi.ResourcePathWithNamespaceQuery(resource, namespace, name)) -} - // Bodies for requests used in subsequent tests. var aPod string = ` { @@ -846,15 +838,15 @@ func TestNamespaceAuthorization(t *testing.T) { statusCodes map[int]bool // allowed status codes. }{ - {"POST", timeoutPathWithNamespaceQuery("pods", "foo", ""), "foo", aPod, code201}, - {"GET", pathWithNamespaceQuery("pods", "foo", ""), "foo", "", code200}, - {"GET", pathWithNamespaceQuery("pods", "foo", "a"), "foo", "", code200}, - {"DELETE", timeoutPathWithNamespaceQuery("pods", "foo", "a"), "foo", "", code200}, + {"POST", timeoutPath("pods", "foo", ""), "foo", aPod, code201}, + {"GET", path("pods", "foo", ""), "foo", "", code200}, + {"GET", path("pods", "foo", "a"), "foo", "", code200}, + {"DELETE", timeoutPath("pods", "foo", "a"), "foo", "", code200}, {"POST", timeoutPath("pods", "bar", ""), "bar", aPod, code403}, - {"GET", pathWithNamespaceQuery("pods", "bar", ""), "bar", "", code403}, - {"GET", pathWithNamespaceQuery("pods", "bar", "a"), "bar", "", code403}, - {"DELETE", timeoutPathWithNamespaceQuery("pods", "bar", "a"), "bar", "", code403}, + {"GET", path("pods", "bar", ""), "bar", "", code403}, + {"GET", path("pods", "bar", "a"), "bar", "", code403}, + {"DELETE", timeoutPath("pods", "bar", "a"), "bar", "", code403}, {"POST", timeoutPath("pods", api.NamespaceDefault, ""), "", aPod, code403}, {"GET", path("pods", "", ""), "", "", code403},