Skip to content

Commit

Permalink
Removing more references to v1beta1 from pkg/
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhiljindal committed Apr 24, 2015
1 parent 7505bed commit dcc368c
Show file tree
Hide file tree
Showing 20 changed files with 316 additions and 296 deletions.
2 changes: 1 addition & 1 deletion cluster/gce/util.sh
Expand Up @@ -670,7 +670,7 @@ function kube-up {

until curl --insecure -H "Authorization: Bearer ${KUBE_BEARER_TOKEN}" \
--max-time 5 --fail --output /dev/null --silent \
"https://${KUBE_MASTER_IP}/api/v1beta1/pods"; do
"https://${KUBE_MASTER_IP}/api/v1beta3/pods"; do
printf "."
sleep 2
done
Expand Down
8 changes: 6 additions & 2 deletions pkg/api/testapi/testapi.go
Expand Up @@ -114,8 +114,12 @@ func ResourcePath(resource, namespace, name string) string {
// 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 ResourcePathWithQueryParams(resource, namespace, name string) string {
path := ResourcePath(resource, namespace, name)
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
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/testapi/testapi_test.go
Expand Up @@ -120,7 +120,7 @@ func TestResourcePathForV1Beta1(t *testing.T) {
}
}

func TestResourcePathWithQueryParamsForV1Beta3(t *testing.T) {
func TestResourcePathWithNamespaceQueryForV1Beta3(t *testing.T) {
if Version() != "v1beta3" {
// Skip the test if we are not testing v1beta3.
return
Expand All @@ -138,13 +138,13 @@ func TestResourcePathWithQueryParamsForV1Beta3(t *testing.T) {
{"resource", "", "", "/api/v1beta3/resource"},
}
for _, item := range testCases {
if actual := ResourcePathWithQueryParams(item.resource, item.namespace, item.name); actual != item.expected {
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)
}
}
}

func TestResourcePathWithQueryParamsForV1Beta1(t *testing.T) {
func TestResourcePathWithNamespaceQueryForV1Beta1(t *testing.T) {
if Version() != "v1beta1" {
// Skip the test if we are not testing v1beta1.
return
Expand All @@ -162,7 +162,7 @@ func TestResourcePathWithQueryParamsForV1Beta1(t *testing.T) {
{"resource", "", "", "/api/v1beta1/resource"},
}
for _, item := range testCases {
if actual := ResourcePathWithQueryParams(item.resource, item.namespace, item.name); actual != item.expected {
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)
}
}
Expand Down
41 changes: 28 additions & 13 deletions pkg/apiserver/handlers_test.go
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)

Expand All @@ -48,6 +49,22 @@ func expectHTTP(url string, code int, t *testing.T) {
}
}

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{}
Expand Down Expand Up @@ -168,17 +185,15 @@ func TestGetAPIRequestInfo(t *testing.T) {
{"GET", "/watch/namespaces/other/pods", "watch", "", "other", "pods", "", "Pod", "", []string{"pods"}},

// fully-qualified paths
{"GET", "/api/v1beta1/namespaces/other/pods", "list", "v1beta1", "other", "pods", "", "Pod", "", []string{"pods"}},
{"GET", "/api/v1beta1/namespaces/other/pods/foo", "get", "v1beta1", "other", "pods", "", "Pod", "foo", []string{"pods", "foo"}},
{"GET", "/api/v1beta1/pods", "list", "v1beta1", api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}},
{"POST", "/api/v1beta1/pods", "create", "v1beta1", api.NamespaceDefault, "pods", "", "Pod", "", []string{"pods"}},
{"GET", "/api/v1beta1/pods/foo", "get", "v1beta1", api.NamespaceDefault, "pods", "", "Pod", "foo", []string{"pods", "foo"}},
{"GET", "/api/v1beta1/pods/foo?namespace=other", "get", "v1beta1", "other", "pods", "", "Pod", "foo", []string{"pods", "foo"}},
{"GET", "/api/v1beta1/pods?namespace=other", "list", "v1beta1", "other", "pods", "", "Pod", "", []string{"pods"}},
{"GET", "/api/v1beta1/proxy/pods/foo", "proxy", "v1beta1", api.NamespaceDefault, "pods", "", "Pod", "foo", []string{"pods", "foo"}},
{"GET", "/api/v1beta1/redirect/pods/foo", "redirect", "v1beta1", api.NamespaceDefault, "pods", "", "Pod", "foo", []string{"pods", "foo"}},
{"GET", "/api/v1beta1/watch/pods", "watch", "v1beta1", api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}},
{"GET", "/api/v1beta1/watch/namespaces/other/pods", "watch", "v1beta1", "other", "pods", "", "Pod", "", []string{"pods"}},
{"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", "", ""), "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"}},

// subresource identification
{"GET", "/namespaces/other/pods/foo/status", "get", "", "other", "pods", "status", "Pod", "foo", []string{"pods", "foo", "status"}},
Expand Down Expand Up @@ -222,8 +237,8 @@ func TestGetAPIRequestInfo(t *testing.T) {

errorCases := map[string]string{
"no resource path": "/",
"just apiversion": "/api/v1beta1/",
"apiversion with no resource": "/api/v1beta1/",
"just apiversion": "/api/version/",
"apiversion with no resource": "/api/version/",
}
for k, v := range errorCases {
req, err := http.NewRequest("GET", v, nil)
Expand Down
58 changes: 33 additions & 25 deletions pkg/client/request_test.go
Expand Up @@ -36,8 +36,6 @@ import (
apierrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
Expand Down Expand Up @@ -712,15 +710,15 @@ func TestDoRequestNewWay(t *testing.T) {
Port: 12345,
TargetPort: util.NewIntOrStringFromInt(12345),
}}}}
expectedBody, _ := v1beta2.Codec.Encode(expectedObj)
expectedBody, _ := testapi.Codec().Encode(expectedObj)
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
T: t,
}
testServer := httptest.NewServer(&fakeHandler)
defer testServer.Close()
c := NewOrDie(&Config{Host: testServer.URL, Version: "v1beta2", Username: "user", Password: "pass"})
c := NewOrDie(&Config{Host: testServer.URL, Version: testapi.Version(), Username: "user", Password: "pass"})
obj, err := c.Verb("POST").
Prefix("foo", "bar").
Suffix("baz").
Expand All @@ -736,7 +734,9 @@ func TestDoRequestNewWay(t *testing.T) {
} else if !api.Semantic.DeepDerivative(expectedObj, obj) {
t.Errorf("Expected: %#v, got %#v", expectedObj, obj)
}
fakeHandler.ValidateRequest(t, "/api/v1beta2/foo/bar/baz?timeout=1s", "POST", &reqBody)
requestURL := testapi.ResourcePathWithPrefix("foo/bar", "", "", "baz")
requestURL += "?timeout=1s"
fakeHandler.ValidateRequest(t, requestURL, "POST", &reqBody)
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived)
}
Expand All @@ -758,7 +758,7 @@ func TestCheckRetryClosesBody(t *testing.T) {
}))
defer testServer.Close()

c := NewOrDie(&Config{Host: testServer.URL, Version: "v1beta2", Username: "user", Password: "pass"})
c := NewOrDie(&Config{Host: testServer.URL, Version: testapi.Version(), Username: "user", Password: "pass"})
_, err := c.Verb("POST").
Prefix("foo", "bar").
Suffix("baz").
Expand Down Expand Up @@ -787,7 +787,7 @@ func BenchmarkCheckRetryClosesBody(t *testing.B) {
}))
defer testServer.Close()

c := NewOrDie(&Config{Host: testServer.URL, Version: "v1beta2", Username: "user", Password: "pass"})
c := NewOrDie(&Config{Host: testServer.URL, Version: testapi.Version(), Username: "user", Password: "pass"})
r := c.Verb("POST").
Prefix("foo", "bar").
Suffix("baz").
Expand All @@ -802,20 +802,20 @@ func BenchmarkCheckRetryClosesBody(t *testing.B) {
}
func TestDoRequestNewWayReader(t *testing.T) {
reqObj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
reqBodyExpected, _ := v1beta1.Codec.Encode(reqObj)
reqBodyExpected, _ := testapi.Codec().Encode(reqObj)
expectedObj := &api.Service{Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Protocol: "TCP",
Port: 12345,
TargetPort: util.NewIntOrStringFromInt(12345),
}}}}
expectedBody, _ := v1beta1.Codec.Encode(expectedObj)
expectedBody, _ := testapi.Codec().Encode(expectedObj)
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
T: t,
}
testServer := httptest.NewServer(&fakeHandler)
c := NewOrDie(&Config{Host: testServer.URL, Version: "v1beta1", Username: "user", Password: "pass"})
c := NewOrDie(&Config{Host: testServer.URL, Version: testapi.Version(), Username: "user", Password: "pass"})
obj, err := c.Verb("POST").
Resource("bar").
Name("baz").
Expand All @@ -834,28 +834,30 @@ func TestDoRequestNewWayReader(t *testing.T) {
t.Errorf("Expected: %#v, got %#v", expectedObj, obj)
}
tmpStr := string(reqBodyExpected)
fakeHandler.ValidateRequest(t, "/api/v1beta1/foo/bar/baz?labels=name%3Dfoo&timeout=1s", "POST", &tmpStr)
requestURL := testapi.ResourcePathWithPrefix("foo", "bar", "", "baz")
requestURL += "?" + api.LabelSelectorQueryParam(testapi.Version()) + "=name%3Dfoo&timeout=1s"
fakeHandler.ValidateRequest(t, requestURL, "POST", &tmpStr)
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived)
}
}

func TestDoRequestNewWayObj(t *testing.T) {
reqObj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
reqBodyExpected, _ := v1beta2.Codec.Encode(reqObj)
reqBodyExpected, _ := testapi.Codec().Encode(reqObj)
expectedObj := &api.Service{Spec: api.ServiceSpec{Ports: []api.ServicePort{{
Protocol: "TCP",
Port: 12345,
TargetPort: util.NewIntOrStringFromInt(12345),
}}}}
expectedBody, _ := v1beta2.Codec.Encode(expectedObj)
expectedBody, _ := testapi.Codec().Encode(expectedObj)
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
T: t,
}
testServer := httptest.NewServer(&fakeHandler)
c := NewOrDie(&Config{Host: testServer.URL, Version: "v1beta2", Username: "user", Password: "pass"})
c := NewOrDie(&Config{Host: testServer.URL, Version: testapi.Version(), Username: "user", Password: "pass"})
obj, err := c.Verb("POST").
Suffix("baz").
Name("bar").
Expand All @@ -874,15 +876,17 @@ func TestDoRequestNewWayObj(t *testing.T) {
t.Errorf("Expected: %#v, got %#v", expectedObj, obj)
}
tmpStr := string(reqBodyExpected)
fakeHandler.ValidateRequest(t, "/api/v1beta2/foo/bar/baz?labels=name%3Dfoo&timeout=1s", "POST", &tmpStr)
requestURL := testapi.ResourcePath("foo", "", "bar/baz")
requestURL += "?" + api.LabelSelectorQueryParam(testapi.Version()) + "=name%3Dfoo&timeout=1s"
fakeHandler.ValidateRequest(t, requestURL, "POST", &tmpStr)
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived)
}
}

func TestDoRequestNewWayFile(t *testing.T) {
reqObj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
reqBodyExpected, err := v1beta1.Codec.Encode(reqObj)
reqBodyExpected, err := testapi.Codec().Encode(reqObj)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand All @@ -902,14 +906,14 @@ func TestDoRequestNewWayFile(t *testing.T) {
Port: 12345,
TargetPort: util.NewIntOrStringFromInt(12345),
}}}}
expectedBody, _ := v1beta1.Codec.Encode(expectedObj)
expectedBody, _ := testapi.Codec().Encode(expectedObj)
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
T: t,
}
testServer := httptest.NewServer(&fakeHandler)
c := NewOrDie(&Config{Host: testServer.URL, Version: "v1beta1", Username: "user", Password: "pass"})
c := NewOrDie(&Config{Host: testServer.URL, Version: testapi.Version(), Username: "user", Password: "pass"})
wasCreated := true
obj, err := c.Verb("POST").
Prefix("foo/bar", "baz").
Expand All @@ -929,15 +933,17 @@ func TestDoRequestNewWayFile(t *testing.T) {
t.Errorf("expected object was not created")
}
tmpStr := string(reqBodyExpected)
fakeHandler.ValidateRequest(t, "/api/v1beta1/foo/bar/baz?timeout=1s", "POST", &tmpStr)
requestURL := testapi.ResourcePathWithPrefix("foo/bar/baz", "", "", "")
requestURL += "?timeout=1s"
fakeHandler.ValidateRequest(t, requestURL, "POST", &tmpStr)
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived)
}
}

func TestWasCreated(t *testing.T) {
reqObj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
reqBodyExpected, err := v1beta1.Codec.Encode(reqObj)
reqBodyExpected, err := testapi.Codec().Encode(reqObj)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand All @@ -947,14 +953,14 @@ func TestWasCreated(t *testing.T) {
Port: 12345,
TargetPort: util.NewIntOrStringFromInt(12345),
}}}}
expectedBody, _ := v1beta1.Codec.Encode(expectedObj)
expectedBody, _ := testapi.Codec().Encode(expectedObj)
fakeHandler := util.FakeHandler{
StatusCode: 201,
ResponseBody: string(expectedBody),
T: t,
}
testServer := httptest.NewServer(&fakeHandler)
c := NewOrDie(&Config{Host: testServer.URL, Version: "v1beta1", Username: "user", Password: "pass"})
c := NewOrDie(&Config{Host: testServer.URL, Version: testapi.Version(), Username: "user", Password: "pass"})
wasCreated := false
obj, err := c.Verb("PUT").
Prefix("foo/bar", "baz").
Expand All @@ -975,7 +981,9 @@ func TestWasCreated(t *testing.T) {
}

tmpStr := string(reqBodyExpected)
fakeHandler.ValidateRequest(t, "/api/v1beta1/foo/bar/baz?timeout=1s", "PUT", &tmpStr)
requestURL := testapi.ResourcePathWithPrefix("foo/bar/baz", "", "", "")
requestURL += "?timeout=1s"
fakeHandler.ValidateRequest(t, requestURL, "PUT", &tmpStr)
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived)
}
Expand Down Expand Up @@ -1142,7 +1150,7 @@ func TestWatch(t *testing.T) {

s, err := New(&Config{
Host: testServer.URL,
Version: "v1beta1",
Version: testapi.Version(),
Username: "user",
Password: "pass",
})
Expand Down Expand Up @@ -1192,7 +1200,7 @@ func TestStream(t *testing.T) {

s, err := New(&Config{
Host: testServer.URL,
Version: "v1beta1",
Version: testapi.Version(),
Username: "user",
Password: "pass",
})
Expand Down

0 comments on commit dcc368c

Please sign in to comment.