diff --git a/cmd/e2e/e2e.go b/cmd/e2e/e2e.go index f987fd8ab38c1..2543f6b5a722d 100644 --- a/cmd/e2e/e2e.go +++ b/cmd/e2e/e2e.go @@ -332,7 +332,7 @@ func TestNetwork(c *client.Client) bool { const maxAttempts = 60 for i := 0; i < maxAttempts; i++ { time.Sleep(time.Second) - body, err := c.Get().Path("proxy").Path("services").Path(svc.Name).Path("status").Do().Raw() + body, err := c.Get().Prefix("proxy").Resource("services").Name(svc.Name).Suffix("status").Do().Raw() if err != nil { glog.Infof("Attempt %v/%v: service/pod still starting. (error: '%v')", i, maxAttempts, err) continue @@ -344,7 +344,7 @@ func TestNetwork(c *client.Client) bool { case "running": glog.Infof("Attempt %v/%v: test still running", i, maxAttempts) case "fail": - if body, err := c.Get().Path("proxy").Path("services").Path(svc.Name).Path("read").Do().Raw(); err != nil { + if body, err := c.Get().Prefix("proxy").Resource("services").Name(svc.Name).Suffix("read").Do().Raw(); err != nil { glog.Infof("Failed on attempt %v. Cleaning up. Error reading details: %v", i, err) } else { glog.Infof("Failed on attempt %v. Cleaning up. Details:\n%v", i, string(body)) @@ -353,7 +353,7 @@ func TestNetwork(c *client.Client) bool { } } - if body, err := c.Get().Path("proxy").Path("services").Path(svc.Name).Path("read").Do().Raw(); err != nil { + if body, err := c.Get().Prefix("proxy").Resource("services").Name(svc.Name).Suffix("read").Do().Raw(); err != nil { glog.Infof("Timed out. Cleaning up. Error reading details: %v", err) } else { glog.Infof("Timed out. Cleaning up. Details:\n%v", string(body)) @@ -472,12 +472,11 @@ func TestClusterDNS(c *client.Client) bool { failed = []string{} for _, name := range namesToResolve { _, err := c.Get(). - Path("proxy"). + Prefix("proxy"). + Resource("pods"). Namespace("default"). - Path("pods"). - Path(pod.Name). - Path("results"). - Path(name). + Name(pod.Name). + Suffix("results", name). Do().Raw() if err != nil { failed = append(failed, name) diff --git a/cmd/integration/integration.go b/cmd/integration/integration.go index 39744e3dd17c1..8579ee157a3a7 100644 --- a/cmd/integration/integration.go +++ b/cmd/integration/integration.go @@ -279,7 +279,7 @@ func runAPIVersionsTest(c *client.Client) { func runSelfLinkTest(c *client.Client) { var svc api.Service - err := c.Post().Path("services").Body( + err := c.Post().Resource("services").Body( &api.Service{ ObjectMeta: api.ObjectMeta{ Name: "selflinktest", @@ -305,7 +305,7 @@ func runSelfLinkTest(c *client.Client) { } var svcList api.ServiceList - err = c.Get().Path("services").Do().Into(&svcList) + err = c.Get().Resource("services").Do().Into(&svcList) if err != nil { glog.Fatalf("Failed listing services: %v", err) } @@ -338,7 +338,7 @@ func runSelfLinkTest(c *client.Client) { func runAtomicPutTest(c *client.Client) { var svc api.Service - err := c.Post().Path("services").Body( + err := c.Post().Resource("services").Body( &api.Service{ TypeMeta: api.TypeMeta{ APIVersion: latest.Version, @@ -377,8 +377,8 @@ func runAtomicPutTest(c *client.Client) { glog.Infof("Starting to update (%s, %s)", l, v) var tmpSvc api.Service err := c.Get(). - Path("services"). - Path(svc.Name). + Resource("services"). + Name(svc.Name). Do(). Into(&tmpSvc) if err != nil { @@ -391,7 +391,7 @@ func runAtomicPutTest(c *client.Client) { tmpSvc.Spec.Selector[l] = v } glog.Infof("Posting update (%s, %s)", l, v) - err = c.Put().Path("services").Path(svc.Name).Body(&tmpSvc).Do().Error() + err = c.Put().Resource("services").Name(svc.Name).Body(&tmpSvc).Do().Error() if err != nil { if errors.IsConflict(err) { glog.Infof("Conflict: (%s, %s)", l, v) @@ -408,7 +408,7 @@ func runAtomicPutTest(c *client.Client) { }(label, value) } wg.Wait() - if err := c.Get().Path("services").Path(svc.Name).Do().Into(&svc); err != nil { + if err := c.Get().Resource("services").Name(svc.Name).Do().Into(&svc); err != nil { glog.Fatalf("Failed getting atomicService after writers are complete: %v", err) } if !reflect.DeepEqual(testLabels, labels.Set(svc.Spec.Selector)) { @@ -422,7 +422,7 @@ func runMasterServiceTest(client *client.Client) { var svcList api.ServiceList err := client.Get(). Namespace("default"). - Path("services"). + Resource("services"). Do(). Into(&svcList) if err != nil { @@ -443,8 +443,8 @@ func runMasterServiceTest(client *client.Client) { var ep api.Endpoints err := client.Get(). Namespace("default"). - Path("endpoints"). - Path("kubernetes"). + Resource("endpoints"). + Name("kubernetes"). Do(). Into(&ep) if err != nil { @@ -460,8 +460,8 @@ func runMasterServiceTest(client *client.Client) { var ep api.Endpoints err := client.Get(). Namespace("default"). - Path("endpoints"). - Path("kubernetes-ro"). + Resource("endpoints"). + Name("kubernetes-ro"). Do(). Into(&ep) if err != nil { diff --git a/cmd/kubecfg/kubecfg.go b/cmd/kubecfg/kubecfg.go index 1a4a15ae564ec..13f88f14e8f91 100644 --- a/cmd/kubecfg/kubecfg.go +++ b/cmd/kubecfg/kubecfg.go @@ -378,7 +378,7 @@ func executeAPIRequest(ctx api.Context, method string, c *client.Client) bool { glog.Fatalf("usage: kubecfg [OPTIONS] %s <%s>", method, prettyWireStorage()) } case "update": - obj, err := c.Verb("GET").Namespace(api.Namespace(ctx)).Path(path).Do().Get() + obj, err := c.Verb("GET").Namespace(api.Namespace(ctx)).Suffix(path).Do().Get() if err != nil { glog.Fatalf("error obtaining resource version for update: %v", err) } @@ -404,7 +404,7 @@ func executeAPIRequest(ctx api.Context, method string, c *client.Client) bool { return false } - r := c.Verb(verb).Namespace(api.Namespace(ctx)).Path(path) + r := c.Verb(verb).Namespace(api.Namespace(ctx)).Suffix(path) if len(*selector) > 0 { r.ParseSelectorParam("labels", *selector) } diff --git a/pkg/client/endpoints.go b/pkg/client/endpoints.go index 85e38a1bb2a8a..9a83389971d79 100644 --- a/pkg/client/endpoints.go +++ b/pkg/client/endpoints.go @@ -53,14 +53,14 @@ func newEndpoints(c *Client, namespace string) *endpoints { // Create creates a new endpoint. func (c *endpoints) Create(endpoints *api.Endpoints) (*api.Endpoints, error) { result := &api.Endpoints{} - err := c.r.Post().Namespace(c.ns).Path("endpoints").Body(endpoints).Do().Into(result) + err := c.r.Post().Namespace(c.ns).Resource("endpoints").Body(endpoints).Do().Into(result) return result, err } // List takes a selector, and returns the list of endpoints that match that selector func (c *endpoints) List(selector labels.Selector) (result *api.EndpointsList, err error) { result = &api.EndpointsList{} - err = c.r.Get().Namespace(c.ns).Path("endpoints").SelectorParam("labels", selector).Do().Into(result) + err = c.r.Get().Namespace(c.ns).Resource("endpoints").SelectorParam("labels", selector).Do().Into(result) return } @@ -71,16 +71,16 @@ func (c *endpoints) Get(name string) (result *api.Endpoints, err error) { } result = &api.Endpoints{} - err = c.r.Get().Namespace(c.ns).Path("endpoints").Path(name).Do().Into(result) + err = c.r.Get().Namespace(c.ns).Resource("endpoints").Name(name).Do().Into(result) return } // Watch returns a watch.Interface that watches the requested endpoints for a service. func (c *endpoints) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) { return c.r.Get(). - Path("watch"). + Prefix("watch"). Namespace(c.ns). - Path("endpoints"). + Resource("endpoints"). Param("resourceVersion", resourceVersion). SelectorParam("labels", label). SelectorParam("fields", field). @@ -94,8 +94,8 @@ func (c *endpoints) Update(endpoints *api.Endpoints) (*api.Endpoints, error) { } err := c.r.Put(). Namespace(c.ns). - Path("endpoints"). - Path(endpoints.Name). + Resource("endpoints"). + Name(endpoints.Name). Body(endpoints). Do(). Into(result) diff --git a/pkg/client/events.go b/pkg/client/events.go index e938d6b451f30..11464056adf6b 100644 --- a/pkg/client/events.go +++ b/pkg/client/events.go @@ -66,7 +66,7 @@ func (e *events) Create(event *api.Event) (*api.Event, error) { result := &api.Event{} err := e.client.Post(). Namespace(event.Namespace). - Path("events"). + Resource("events"). Body(event). Do(). Into(result) @@ -78,7 +78,7 @@ func (e *events) List(label, field labels.Selector) (*api.EventList, error) { result := &api.EventList{} err := e.client.Get(). Namespace(e.namespace). - Path("events"). + Resource("events"). SelectorParam("labels", label). SelectorParam("fields", field). Do(). @@ -95,8 +95,8 @@ func (e *events) Get(name string) (*api.Event, error) { result := &api.Event{} err := e.client.Get(). Namespace(e.namespace). - Path("events"). - Path(name). + Resource("events"). + Name(name). Do(). Into(result) return result, err @@ -105,9 +105,9 @@ func (e *events) Get(name string) (*api.Event, error) { // Watch starts watching for events matching the given selectors. func (e *events) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) { return e.client.Get(). - Path("watch"). + Prefix("watch"). Namespace(e.namespace). - Path("events"). + Resource("events"). Param("resourceVersion", resourceVersion). SelectorParam("labels", label). SelectorParam("fields", field). diff --git a/pkg/client/minions.go b/pkg/client/minions.go index 07ec4dc664ae1..e4f88edac5920 100644 --- a/pkg/client/minions.go +++ b/pkg/client/minions.go @@ -55,14 +55,14 @@ func (c *nodes) resourceName() string { // Create creates a new minion. func (c *nodes) Create(minion *api.Node) (*api.Node, error) { result := &api.Node{} - err := c.r.Post().Path(c.resourceName()).Body(minion).Do().Into(result) + err := c.r.Post().Resource(c.resourceName()).Body(minion).Do().Into(result) return result, err } // List lists all the nodes in the cluster. func (c *nodes) List() (*api.NodeList, error) { result := &api.NodeList{} - err := c.r.Get().Path(c.resourceName()).Do().Into(result) + err := c.r.Get().Resource(c.resourceName()).Do().Into(result) return result, err } @@ -73,11 +73,11 @@ func (c *nodes) Get(name string) (*api.Node, error) { } result := &api.Node{} - err := c.r.Get().Path(c.resourceName()).Path(name).Do().Into(result) + err := c.r.Get().Resource(c.resourceName()).Name(name).Do().Into(result) return result, err } // Delete deletes an existing minion. func (c *nodes) Delete(name string) error { - return c.r.Delete().Path(c.resourceName()).Path(name).Do().Error() + return c.r.Delete().Resource(c.resourceName()).Name(name).Do().Error() } diff --git a/pkg/client/pods.go b/pkg/client/pods.go index 2250e13c1541f..0e98ce4f6f798 100644 --- a/pkg/client/pods.go +++ b/pkg/client/pods.go @@ -55,7 +55,7 @@ func newPods(c *Client, namespace string) *pods { // ListPods takes a selector, and returns the list of pods that match that selector. func (c *pods) List(selector labels.Selector) (result *api.PodList, err error) { result = &api.PodList{} - err = c.r.Get().Namespace(c.ns).Path("pods").SelectorParam("labels", selector).Do().Into(result) + err = c.r.Get().Namespace(c.ns).Resource("pods").SelectorParam("labels", selector).Do().Into(result) return } @@ -66,19 +66,19 @@ func (c *pods) Get(name string) (result *api.Pod, err error) { } result = &api.Pod{} - err = c.r.Get().Namespace(c.ns).Path("pods").Path(name).Do().Into(result) + err = c.r.Get().Namespace(c.ns).Resource("pods").Name(name).Do().Into(result) return } // DeletePod takes the name of the pod, and returns an error if one occurs func (c *pods) Delete(name string) error { - return c.r.Delete().Namespace(c.ns).Path("pods").Path(name).Do().Error() + return c.r.Delete().Namespace(c.ns).Resource("pods").Name(name).Do().Error() } // CreatePod takes the representation of a pod. Returns the server's representation of the pod, and an error, if it occurs. func (c *pods) Create(pod *api.Pod) (result *api.Pod, err error) { result = &api.Pod{} - err = c.r.Post().Namespace(c.ns).Path("pods").Body(pod).Do().Into(result) + err = c.r.Post().Namespace(c.ns).Resource("pods").Body(pod).Do().Into(result) return } @@ -89,6 +89,6 @@ func (c *pods) Update(pod *api.Pod) (result *api.Pod, err error) { err = fmt.Errorf("invalid update object, missing resource version: %v", pod) return } - err = c.r.Put().Namespace(c.ns).Path("pods").Path(pod.Name).Body(pod).Do().Into(result) + err = c.r.Put().Namespace(c.ns).Resource("pods").Name(pod.Name).Body(pod).Do().Into(result) return } diff --git a/pkg/client/replication_controllers.go b/pkg/client/replication_controllers.go index fcde561f36780..10f902e6d9c66 100644 --- a/pkg/client/replication_controllers.go +++ b/pkg/client/replication_controllers.go @@ -54,7 +54,7 @@ func newReplicationControllers(c *Client, namespace string) *replicationControll // List takes a selector, and returns the list of replication controllers that match that selector. func (c *replicationControllers) List(selector labels.Selector) (result *api.ReplicationControllerList, err error) { result = &api.ReplicationControllerList{} - err = c.r.Get().Namespace(c.ns).Path("replicationControllers").SelectorParam("labels", selector).Do().Into(result) + err = c.r.Get().Namespace(c.ns).Resource("replicationControllers").SelectorParam("labels", selector).Do().Into(result) return } @@ -65,14 +65,14 @@ func (c *replicationControllers) Get(name string) (result *api.ReplicationContro } result = &api.ReplicationController{} - err = c.r.Get().Namespace(c.ns).Path("replicationControllers").Path(name).Do().Into(result) + err = c.r.Get().Namespace(c.ns).Resource("replicationControllers").Name(name).Do().Into(result) return } // Create creates a new replication controller. func (c *replicationControllers) Create(controller *api.ReplicationController) (result *api.ReplicationController, err error) { result = &api.ReplicationController{} - err = c.r.Post().Namespace(c.ns).Path("replicationControllers").Body(controller).Do().Into(result) + err = c.r.Post().Namespace(c.ns).Resource("replicationControllers").Body(controller).Do().Into(result) return } @@ -83,21 +83,21 @@ func (c *replicationControllers) Update(controller *api.ReplicationController) ( err = fmt.Errorf("invalid update object, missing resource version: %v", controller) return } - err = c.r.Put().Namespace(c.ns).Path("replicationControllers").Path(controller.Name).Body(controller).Do().Into(result) + err = c.r.Put().Namespace(c.ns).Resource("replicationControllers").Name(controller.Name).Body(controller).Do().Into(result) return } // Delete deletes an existing replication controller. func (c *replicationControllers) Delete(name string) error { - return c.r.Delete().Namespace(c.ns).Path("replicationControllers").Path(name).Do().Error() + return c.r.Delete().Namespace(c.ns).Resource("replicationControllers").Name(name).Do().Error() } // Watch returns a watch.Interface that watches the requested controllers. func (c *replicationControllers) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) { return c.r.Get(). - Path("watch"). + Prefix("watch"). Namespace(c.ns). - Path("replicationControllers"). + Resource("replicationControllers"). Param("resourceVersion", resourceVersion). SelectorParam("labels", label). SelectorParam("fields", field). diff --git a/pkg/client/request_test.go b/pkg/client/request_test.go index ef04e9362d8d7..f8d25072d4e1b 100644 --- a/pkg/client/request_test.go +++ b/pkg/client/request_test.go @@ -32,6 +32,7 @@ import ( "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" + 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" @@ -54,9 +55,12 @@ func TestRequestWithErrorWontChange(t *testing.T) { SelectorParam("labels", labels.Set{"a": "b"}.AsSelector()). UintParam("uint", 1). AbsPath("/abs"). - Path("test"). + Prefix("test"). + Suffix("testing"). ParseSelectorParam("foo", "a=b"). Namespace("new"). + Resource("foos"). + Name("bars"). NoPoll(). Body("foo"). Poller(skipPolling). @@ -70,6 +74,74 @@ func TestRequestWithErrorWontChange(t *testing.T) { } } +func TestRequestPreservesBaseTrailingSlash(t *testing.T) { + r := &Request{baseURL: &url.URL{}, path: "/path/"} + if s := r.finalURL(); s != "/path/" { + t.Errorf("trailing slash should be preserved: %s", s) + } +} + +func TestRequestAbsPathPreservesTrailingSlash(t *testing.T) { + r := (&Request{baseURL: &url.URL{}}).AbsPath("/foo/") + if s := r.finalURL(); s != "/foo/" { + t.Errorf("trailing slash should be preserved: %s", s) + } +} + +func TestRequestAbsPathJoins(t *testing.T) { + r := (&Request{baseURL: &url.URL{}}).AbsPath("foo/bar", "baz") + if s := r.finalURL(); s != "foo/bar/baz" { + t.Errorf("trailing slash should be preserved: %s", s) + } +} + +func TestRequestSetsNamespace(t *testing.T) { + r := (&Request{ + baseURL: &url.URL{ + Path: "/", + }, + }).Namespace("foo") + if r.namespace == "" { + t.Errorf("namespace should be set: %#v", r) + } + if s := r.finalURL(); s != "?namespace=foo" { + t.Errorf("namespace should be in params: %s", s) + } + + r = (&Request{ + baseURL: &url.URL{ + Path: "/", + }, + namespaceInPath: true, + }).Namespace("foo") + if s := r.finalURL(); s != "ns/foo" { + t.Errorf("namespace should be in path: %s", s) + } +} + +func TestRequestOrdersNamespaceInPath(t *testing.T) { + r := (&Request{ + baseURL: &url.URL{}, + path: "/test/", + namespaceInPath: true, + }).Name("bar").Resource("baz").Namespace("foo") + if s := r.finalURL(); s != "/test/ns/foo/baz/bar" { + t.Errorf("namespace should be in order in path: %s", s) + } +} + +func TestRequestSetTwiceError(t *testing.T) { + if (&Request{}).Name("bar").Name("baz").err == nil { + t.Errorf("setting name twice should result in error") + } + if (&Request{}).Namespace("bar").Namespace("baz").err == nil { + t.Errorf("setting namespace twice should result in error") + } + if (&Request{}).Resource("bar").Resource("baz").err == nil { + t.Errorf("setting resource twice should result in error") + } +} + func TestRequestParseSelectorParam(t *testing.T) { r := (&Request{}).ParseSelectorParam("foo", "a") if r.err == nil || r.params != nil { @@ -133,6 +205,9 @@ func TestTransformResponse(t *testing.T) { {Response: &http.Response{StatusCode: 201}, Data: []byte{}, Created: true}, {Response: &http.Response{StatusCode: 199}, Error: true}, {Response: &http.Response{StatusCode: 500}, Error: true}, + {Response: &http.Response{StatusCode: 422}, Error: true}, + {Response: &http.Response{StatusCode: 409}, Error: true}, + {Response: &http.Response{StatusCode: 404}, Error: true}, {Response: &http.Response{StatusCode: 200, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid}, {Response: &http.Response{StatusCode: 200, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid}, } @@ -155,6 +230,80 @@ func TestTransformResponse(t *testing.T) { } } +func TestTransformUnstructuredError(t *testing.T) { + testCases := []struct { + Req *http.Request + Res *http.Response + + Resource string + Name string + + ErrFn func(error) bool + }{ + { + Resource: "foo", + Name: "bar", + Req: &http.Request{ + Method: "POST", + }, + Res: &http.Response{ + StatusCode: http.StatusConflict, + Body: ioutil.NopCloser(bytes.NewReader(nil)), + }, + ErrFn: apierrors.IsAlreadyExists, + }, + { + Resource: "foo", + Name: "bar", + Req: &http.Request{ + Method: "PUT", + }, + Res: &http.Response{ + StatusCode: http.StatusConflict, + Body: ioutil.NopCloser(bytes.NewReader(nil)), + }, + ErrFn: apierrors.IsConflict, + }, + { + Resource: "foo", + Name: "bar", + Req: &http.Request{}, + Res: &http.Response{ + StatusCode: http.StatusNotFound, + Body: ioutil.NopCloser(bytes.NewReader(nil)), + }, + ErrFn: apierrors.IsNotFound, + }, + { + Req: &http.Request{}, + Res: &http.Response{ + StatusCode: http.StatusBadRequest, + Body: ioutil.NopCloser(bytes.NewReader(nil)), + }, + ErrFn: apierrors.IsBadRequest, + }, + } + + for _, testCase := range testCases { + r := &Request{ + codec: latest.Codec, + resourceName: testCase.Name, + resource: testCase.Resource, + } + _, _, err := r.transformResponse(testCase.Res, testCase.Req) + if !testCase.ErrFn(err) { + t.Errorf("unexpected error: %v", err) + continue + } + if len(testCase.Name) != 0 && !strings.Contains(err.Error(), testCase.Name) { + t.Errorf("unexpected error string: %s", err) + } + if len(testCase.Resource) != 0 && !strings.Contains(err.Error(), testCase.Resource) { + t.Errorf("unexpected error string: %s", err) + } + } +} + type clientFunc func(req *http.Request) (*http.Response, error) func (f clientFunc) Do(req *http.Request) (*http.Response, error) { @@ -333,8 +482,8 @@ func TestDoRequestNewWay(t *testing.T) { defer testServer.Close() c := NewOrDie(&Config{Host: testServer.URL, Version: "v1beta2", Username: "user", Password: "pass"}) obj, err := c.Verb("POST"). - Path("foo/bar"). - Path("baz"). + Prefix("foo", "bar"). + Suffix("baz"). ParseSelectorParam("labels", "name=foo"). Timeout(time.Second). Body([]byte(reqBody)). @@ -367,8 +516,9 @@ func TestDoRequestNewWayReader(t *testing.T) { testServer := httptest.NewServer(&fakeHandler) c := NewOrDie(&Config{Host: testServer.URL, Version: "v1beta1", Username: "user", Password: "pass"}) obj, err := c.Verb("POST"). - Path("foo/bar"). - Path("baz"). + Resource("bar"). + Name("baz"). + Prefix("foo"). SelectorParam("labels", labels.Set{"name": "foo"}.AsSelector()). Sync(true). Timeout(time.Second). @@ -403,8 +553,9 @@ func TestDoRequestNewWayObj(t *testing.T) { testServer := httptest.NewServer(&fakeHandler) c := NewOrDie(&Config{Host: testServer.URL, Version: "v1beta2", Username: "user", Password: "pass"}) obj, err := c.Verb("POST"). - Path("foo/bar"). - Path("baz"). + Suffix("baz"). + Name("bar"). + Resource("foo"). SelectorParam("labels", labels.Set{"name": "foo"}.AsSelector()). Timeout(time.Second). Body(reqObj). @@ -453,8 +604,7 @@ func TestDoRequestNewWayFile(t *testing.T) { c := NewOrDie(&Config{Host: testServer.URL, Version: "v1beta1", Username: "user", Password: "pass"}) wasCreated := true obj, err := c.Verb("POST"). - Path("foo/bar"). - Path("baz"). + Prefix("foo/bar", "baz"). ParseSelectorParam("labels", "name=foo"). Timeout(time.Second). Body(file.Name()). @@ -496,8 +646,7 @@ func TestWasCreated(t *testing.T) { c := NewOrDie(&Config{Host: testServer.URL, Version: "v1beta1", Username: "user", Password: "pass"}) wasCreated := false obj, err := c.Verb("PUT"). - Path("foo/bar"). - Path("baz"). + Prefix("foo/bar", "baz"). ParseSelectorParam("labels", "name=foo"). Timeout(time.Second). Body(reqBodyExpected). @@ -541,7 +690,7 @@ func TestVerbs(t *testing.T) { func TestAbsPath(t *testing.T) { expectedPath := "/bar/foo" c := NewOrDie(&Config{}) - r := c.Post().Path("/foo").AbsPath(expectedPath) + r := c.Post().Prefix("/foo").AbsPath(expectedPath) if r.path != expectedPath { t.Errorf("unexpected path: %s, expected %s", r.path, expectedPath) } @@ -792,7 +941,7 @@ func TestWatch(t *testing.T) { t.Fatalf("unexpected error: %v", err) } - watching, err := s.Get().Path("path/to/watch/thing").Watch() + watching, err := s.Get().Prefix("path/to/watch/thing").Watch() if err != nil { t.Fatalf("Unexpected error") } @@ -841,7 +990,7 @@ func TestStream(t *testing.T) { if err != nil { t.Fatalf("unexpected error: %v", err) } - readCloser, err := s.Get().Path("path/to/stream/thing").Stream() + readCloser, err := s.Get().Prefix("path/to/stream/thing").Stream() if err != nil { t.Fatalf("unexpected error: %v", err) } diff --git a/pkg/client/restclient.go b/pkg/client/restclient.go index 926e43b1d64c8..581a75bbfc1ab 100644 --- a/pkg/client/restclient.go +++ b/pkg/client/restclient.go @@ -59,7 +59,9 @@ type RESTClient struct { // NewRESTClient creates a new RESTClient. This client performs generic REST functions // such as Get, Put, Post, and Delete on specified paths. Codec controls encoding and -// decoding of responses from the server. +// decoding of responses from the server. If the namespace should be specified as part +// of the path (after the resource), set namespaceInPath to true, otherwise it will be +// passed as "namespace" in the query string. func NewRESTClient(baseURL *url.URL, c runtime.Codec, namespaceInPath bool) *RESTClient { base := *baseURL if !strings.HasSuffix(base.Path, "/") { @@ -129,7 +131,7 @@ func (c *RESTClient) Delete() *Request { // PollFor makes a request to do a single poll of the completion of the given operation. func (c *RESTClient) Operation(name string) *Request { - return c.Get().Path("operations").Path(name).Sync(false).NoPoll() + return c.Get().Resource("operations").Name(name).Sync(false).NoPoll() } func (c *RESTClient) DefaultPoll(name string) (*Request, bool) { diff --git a/pkg/client/restclient_test.go b/pkg/client/restclient_test.go index 41d3f8d60dae3..b859aced0010f 100644 --- a/pkg/client/restclient_test.go +++ b/pkg/client/restclient_test.go @@ -137,7 +137,7 @@ func TestDoRequestAccepted(t *testing.T) { if err != nil { t.Fatalf("unexpected error: %v", err) } - body, err := c.Get().Path("test").Do().Raw() + body, err := c.Get().Prefix("test").Do().Raw() if err == nil { t.Fatalf("Unexpected non-error") } @@ -171,7 +171,7 @@ func TestDoRequestAcceptedSuccess(t *testing.T) { if err != nil { t.Fatalf("unexpected error: %v", err) } - body, err := c.Get().Path("test").Do().Raw() + body, err := c.Get().Prefix("test").Do().Raw() if err != nil { t.Fatalf("unexpected error: %v", err) } @@ -231,7 +231,7 @@ func TestDoRequestCreated(t *testing.T) { t.Fatalf("unexpected error: %v", err) } created := false - body, err := c.Get().Path("test").Do().WasCreated(&created).Raw() + body, err := c.Get().Prefix("test").Do().WasCreated(&created).Raw() if err != nil { t.Errorf("Unexpected error %#v", err) } diff --git a/pkg/client/services.go b/pkg/client/services.go index 1a73a726f8d80..15c39fa9ce48b 100644 --- a/pkg/client/services.go +++ b/pkg/client/services.go @@ -54,7 +54,7 @@ func newServices(c *Client, namespace string) *services { // List takes a selector, and returns the list of services that match that selector func (c *services) List(selector labels.Selector) (result *api.ServiceList, err error) { result = &api.ServiceList{} - err = c.r.Get().Namespace(c.ns).Path("services").SelectorParam("labels", selector).Do().Into(result) + err = c.r.Get().Namespace(c.ns).Resource("services").SelectorParam("labels", selector).Do().Into(result) return } @@ -65,14 +65,14 @@ func (c *services) Get(name string) (result *api.Service, err error) { } result = &api.Service{} - err = c.r.Get().Namespace(c.ns).Path("services").Path(name).Do().Into(result) + err = c.r.Get().Namespace(c.ns).Resource("services").Name(name).Do().Into(result) return } // Create creates a new service. func (c *services) Create(svc *api.Service) (result *api.Service, err error) { result = &api.Service{} - err = c.r.Post().Namespace(c.ns).Path("services").Body(svc).Do().Into(result) + err = c.r.Post().Namespace(c.ns).Resource("services").Body(svc).Do().Into(result) return } @@ -83,21 +83,21 @@ func (c *services) Update(svc *api.Service) (result *api.Service, err error) { err = fmt.Errorf("invalid update object, missing resource version: %v", svc) return } - err = c.r.Put().Namespace(c.ns).Path("services").Path(svc.Name).Body(svc).Do().Into(result) + err = c.r.Put().Namespace(c.ns).Resource("services").Name(svc.Name).Body(svc).Do().Into(result) return } // Delete deletes an existing service. func (c *services) Delete(name string) error { - return c.r.Delete().Namespace(c.ns).Path("services").Path(name).Do().Error() + return c.r.Delete().Namespace(c.ns).Resource("services").Name(name).Do().Error() } // Watch returns a watch.Interface that watches the requested services. func (c *services) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) { return c.r.Get(). - Path("watch"). + Prefix("watch"). Namespace(c.ns). - Path("services"). + Resource("services"). Param("resourceVersion", resourceVersion). SelectorParam("labels", label). SelectorParam("fields", field). diff --git a/pkg/config/config.go b/pkg/config/config.go index 3a66498f02b17..0b764beedd8ee 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -80,7 +80,7 @@ func CreateObject(client RESTClientPoster, mapping *meta.RESTMapping, obj runtim } // TODO: This should be using RESTHelper - err = client.Post().Path(mapping.Resource).Namespace(namespace).Body(obj).Do().Error() + err = client.Post().Resource(mapping.Resource).Namespace(namespace).Body(obj).Do().Error() if err != nil { return errs.NewFieldInvalid(name, obj, err.Error()) } diff --git a/pkg/kubecfg/validate.go b/pkg/kubecfg/validate.go index b13175f03390a..aa6d2535a3887 100644 --- a/pkg/kubecfg/validate.go +++ b/pkg/kubecfg/validate.go @@ -37,7 +37,7 @@ func ValidateObject(data []byte, c *client.Client) error { schemaData, err := c.RESTClient.Get(). AbsPath("/swaggerapi/api"). - Path(apiVersion.(string)). + Prefix(apiVersion.(string)). Do(). Raw() if err != nil { diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go index 50ce9b710f665..6547ae56e6688 100644 --- a/pkg/kubectl/cmd/cmd.go +++ b/pkg/kubectl/cmd/cmd.go @@ -183,8 +183,7 @@ func (c *clientSwaggerSchema) ValidateBytes(data []byte) error { return err } schemaData, err := c.c.RESTClient.Get(). - AbsPath("/swaggerapi/api"). - Path(version). + AbsPath("/swaggerapi/api", version). Do(). Raw() if err != nil { diff --git a/pkg/kubectl/cmd/log.go b/pkg/kubectl/cmd/log.go index fed160cc78427..91e5b79f48f3d 100644 --- a/pkg/kubectl/cmd/log.go +++ b/pkg/kubectl/cmd/log.go @@ -70,12 +70,10 @@ Examples: } readCloser, err := client.RESTClient.Get(). - Path("proxy/minions"). - Path(pod.Status.Host). - Path("containerLogs"). - Path(namespace). - Path(podID). - Path(container). + Prefix("proxy"). + Resource("minions"). + Name(pod.Status.Host). + Suffix("containerLogs", namespace, podID, container). Param("follow", strconv.FormatBool(follow)). Stream() checkErr(err) diff --git a/pkg/kubectl/resthelper.go b/pkg/kubectl/resthelper.go index f7e7580faa4f0..defe294be0dec 100644 --- a/pkg/kubectl/resthelper.go +++ b/pkg/kubectl/resthelper.go @@ -47,18 +47,18 @@ func NewRESTHelper(client RESTClient, mapping *meta.RESTMapping) *RESTHelper { } func (m *RESTHelper) Get(namespace, name string, selector labels.Selector) (runtime.Object, error) { - return m.RESTClient.Get().Namespace(namespace).Path(m.Resource).Path(name).SelectorParam("labels", selector).Do().Get() + return m.RESTClient.Get().Resource(m.Resource).Namespace(namespace).Name(name).SelectorParam("labels", selector).Do().Get() } func (m *RESTHelper) List(namespace string, selector labels.Selector) (runtime.Object, error) { - return m.RESTClient.Get().Path(m.Resource).Namespace(namespace).Path("").SelectorParam("labels", selector).Do().Get() + return m.RESTClient.Get().Resource(m.Resource).Namespace(namespace).SelectorParam("labels", selector).Do().Get() } func (m *RESTHelper) Watch(namespace, resourceVersion string, labelSelector, fieldSelector labels.Selector) (watch.Interface, error) { return m.RESTClient.Get(). - Path("watch"). + Prefix("watch"). Namespace(namespace). - Path(m.Resource). + Resource(m.Resource). Param("resourceVersion", resourceVersion). SelectorParam("labels", labelSelector). SelectorParam("fields", fieldSelector). @@ -66,7 +66,7 @@ func (m *RESTHelper) Watch(namespace, resourceVersion string, labelSelector, fie } func (m *RESTHelper) Delete(namespace, name string) error { - return m.RESTClient.Delete().Namespace(namespace).Path(m.Resource).Path(name).Do().Error() + return m.RESTClient.Delete().Namespace(namespace).Resource(m.Resource).Name(name).Do().Error() } func (m *RESTHelper) Create(namespace string, modify bool, data []byte) error { @@ -98,8 +98,8 @@ func (m *RESTHelper) Create(namespace string, modify bool, data []byte) error { return createResource(m.RESTClient, m.Resource, namespace, data) } -func createResource(c RESTClient, resourcePath, namespace string, data []byte) error { - return c.Post().Namespace(namespace).Path(resourcePath).Body(data).Do().Error() +func createResource(c RESTClient, resource, namespace string, data []byte) error { + return c.Post().Namespace(namespace).Resource(resource).Body(data).Do().Error() } func (m *RESTHelper) Update(namespace, name string, overwrite bool, data []byte) error { @@ -119,7 +119,7 @@ func (m *RESTHelper) Update(namespace, name string, overwrite bool, data []byte) } if version == "" && overwrite { // Retrieve the current version of the object to overwrite the server object - serverObj, err := c.Get().Path(m.Resource).Path(name).Do().Get() + serverObj, err := c.Get().Resource(m.Resource).Name(name).Do().Get() if err != nil { // The object does not exist, but we want it to be created return updateResource(c, m.Resource, namespace, name, data) @@ -141,6 +141,6 @@ func (m *RESTHelper) Update(namespace, name string, overwrite bool, data []byte) return updateResource(c, m.Resource, namespace, name, data) } -func updateResource(c RESTClient, resourcePath, namespace, name string, data []byte) error { - return c.Put().Namespace(namespace).Path(resourcePath).Path(name).Body(data).Do().Error() +func updateResource(c RESTClient, resource, namespace, name string, data []byte) error { + return c.Put().Namespace(namespace).Resource(resource).Name(name).Body(data).Do().Error() } diff --git a/pkg/kubectl/resthelper_test.go b/pkg/kubectl/resthelper_test.go index 25e942c037c00..5aa25ab25b965 100644 --- a/pkg/kubectl/resthelper_test.go +++ b/pkg/kubectl/resthelper_test.go @@ -287,7 +287,7 @@ func TestRESTHelperUpdate(t *testing.T) { } parts := splitPath(req.URL.Path) if parts[1] != "bar" { - t.Errorf("url doesn't contain namespace: %#v", req) + t.Errorf("url doesn't contain namespace: %#v", req.URL) return false } if parts[2] != "foo" { diff --git a/pkg/ui/datafile.go b/pkg/ui/datafile.go index 8a15b3a338c6b..2101491f756a0 100644 --- a/pkg/ui/datafile.go +++ b/pkg/ui/datafile.go @@ -11797,7 +11797,7 @@ var Docs = { }, toggleEndpointListForResource: function(resource) { - var elem = $('li#resource_' + Docs.escapeResourceName(resource) + ' ul.endpoints'); + var elem = $('li#resource_' + Docs.escapeName(resource) + ' ul.endpoints'); if (elem.is(':visible')) { Docs.collapseEndpointListForResource(resource); } else { @@ -11807,7 +11807,7 @@ var Docs = { // Expand resource expandEndpointListForResource: function(resource) { - var resource = Docs.escapeResourceName(resource); + var resource = Docs.escapeName(resource); if (resource == '') { $('.resource ul.endpoints').slideDown(); return; @@ -11821,7 +11821,7 @@ var Docs = { // Collapse resource and mark as explicitly closed collapseEndpointListForResource: function(resource) { - var resource = Docs.escapeResourceName(resource); + var resource = Docs.escapeName(resource); $('li#resource_' + resource).removeClass('active'); var elem = $('li#resource_' + resource + ' ul.endpoints'); @@ -11837,7 +11837,7 @@ var Docs = { return; } - $('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() { + $('li#resource_' + Docs.escapeName(resource) + ' li.operation div.content').each(function() { Docs.expandOperation($(this)); }); }, @@ -11846,7 +11846,7 @@ var Docs = { // Make sure the resource container is open.. Docs.expandEndpointListForResource(resource); - $('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() { + $('li#resource_' + Docs.escapeName(resource) + ' li.operation div.content').each(function() { Docs.collapseOperation($(this)); }); }, @@ -13966,7 +13966,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; OperationView.prototype.toggleOperationContent = function() { var elem; - elem = $('#' + Docs.escapeResourceName(this.model.parentId + "_" + this.model.nickname + "_content")); + elem = $('#' + Docs.escapeName(this.model.parentId + "_" + this.model.nickname + "_content")); if (elem.is(':visible')) { return Docs.collapseOperation(elem); } else { @@ -14391,7 +14391,7 @@ func www_swagger_ui_swagger_ui_js() (*asset, error) { return a, nil } -var _www_swagger_ui_swagger_ui_min_js = []byte(`$(function(){$.fn.vAlign=function(){return this.each(function(c){var a=$(this).height();var d=$(this).parent().height();var b=(d-a)/2;$(this).css("margin-top",b)})};$.fn.stretchFormtasticInputWidthToParent=function(){return this.each(function(b){var d=$(this).closest("form").innerWidth();var c=parseInt($(this).closest("form").css("padding-left"),10)+parseInt($(this).closest("form").css("padding-right"),10);var a=parseInt($(this).css("padding-left"),10)+parseInt($(this).css("padding-right"),10);$(this).css("width",d-c-a)})};$("form.formtastic li.string input, form.formtastic textarea").stretchFormtasticInputWidthToParent();$("ul.downplayed li div.content p").vAlign();$("form.sandbox").submit(function(){var a=true;$(this).find("input.required").each(function(){$(this).removeClass("error");if($(this).val()==""){$(this).addClass("error");$(this).wiggle();a=false}});return a})});function clippyCopiedCallback(b){$("#api_key_copied").fadeIn().delay(1000).fadeOut()}log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){console.log(Array.prototype.slice.call(arguments)[0])}};if(Function.prototype.bind&&console&&typeof console.log=="object"){["log","info","warn","error","assert","dir","clear","profile","profileEnd"].forEach(function(a){console[a]=this.bind(console[a],console)},Function.prototype.call)}var Docs={shebang:function(){var b=$.param.fragment().split("/");b.shift();switch(b.length){case 1:var d="resource_"+b[0];Docs.expandEndpointListForResource(b[0]);$("#"+d).slideto({highlight:false});break;case 2:Docs.expandEndpointListForResource(b[0]);$("#"+d).slideto({highlight:false});var c=b.join("_");var a=c+"_content";Docs.expandOperation($("#"+a));$("#"+c).slideto({highlight:false});break}},toggleEndpointListForResource:function(b){var a=$("li#resource_"+Docs.escapeResourceName(b)+" ul.endpoints");if(a.is(":visible")){Docs.collapseEndpointListForResource(b)}else{Docs.expandEndpointListForResource(b)}},expandEndpointListForResource:function(b){var b=Docs.escapeResourceName(b);if(b==""){$(".resource ul.endpoints").slideDown();return}$("li#resource_"+b).addClass("active");var a=$("li#resource_"+b+" ul.endpoints");a.slideDown()},collapseEndpointListForResource:function(b){var b=Docs.escapeResourceName(b);$("li#resource_"+b).removeClass("active");var a=$("li#resource_"+b+" ul.endpoints");a.slideUp()},expandOperationsForResource:function(a){Docs.expandEndpointListForResource(a);if(a==""){$(".resource ul.endpoints li.operation div.content").slideDown();return}$("li#resource_"+Docs.escapeResourceName(a)+" li.operation div.content").each(function(){Docs.expandOperation($(this))})},collapseOperationsForResource:function(a){Docs.expandEndpointListForResource(a);$("li#resource_"+Docs.escapeResourceName(a)+" li.operation div.content").each(function(){Docs.collapseOperation($(this))})},escapeResourceName:function(a){return a.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^` + "`" + `{|}~]/g,"\\$&")},expandOperation:function(a){a.slideDown()},collapseOperation:function(a){a.slideUp()}};(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.apikey_button_view=b(function(e,k,d,j,i){this.compilerInfo=[4,">= 1.0.0"];d=this.merge(d,e.helpers);i=i||{};var g="",c,f="function",h=this.escapeExpression;g+="
\n";if(C=s.description){C=C.call(E,{hash:{},data:D})}else{C=E.description;C=typeof C===e?C.apply(E):C}if(C||C===0){B+=C}B+="
\n ";return B}function m(C,B){return'\n\n
Parameter | \nValue | \nDescription | \nParameter Type | \nData Type | \n
---|
HTTP Status Code | \nReason | \nResponse Model | \n
---|
';if(c=d.sampleJSON){c=c.call(k,{hash:{},data:i})}else{c=k.sampleJSON;c=typeof c===f?c.apply(k):c}g+=h(c)+'
\n \n
").text(Q);I=$('').append(G)}else{if(P==="application/xml"||/\+xml$/.test(P)){G=$("
").text(this.formatXml(N));I=$('').append(G)}else{if(P==="text/html"){G=$("
").html(_.escape(N));I=$('').append(G)}else{if(/^image\//.test(P)){I=$("").attr("src",F)}else{G=$("
").text(N);I=$('').append(G)}}}}}L=I;$(".request_url",$(this.el)).html("");$(".request_url pre",$(this.el)).text(F);$(".response_code",$(this.el)).html(""+J.status+"");$(".response_body",$(this.el)).html(L);$(".response_headers",$(this.el)).html("
"+_.escape(JSON.stringify(J.headers,null," ")).replace(/\n/g,"");$(".response",$(this.el)).slideDown();$(".response_hider",$(this.el)).show();$(".response_throbber",$(this.el)).hide();K=$(".response_body",$(this.el))[0];E=this.options.swaggerOptions;if(E.highlightSizeThreshold&&J.data.length>E.highlightSizeThreshold){return K}else{return hljs.highlightBlock(K)}};C.prototype.toggleOperationContent=function(){var E;E=$("#"+Docs.escapeResourceName(this.model.parentId+"_"+this.model.nickname+"_content"));if(E.is(":visible")){return Docs.collapseOperation(E)}else{return Docs.expandOperation(E)}};return C})(Backbone.View);r=(function(D){y(C,D);function C(){e=C.__super__.constructor.apply(this,arguments);return e}C.prototype.initialize=function(){};C.prototype.render=function(){var F,E,G;G=this.template();$(this.el).html(G(this.model));if(swaggerUi.api.models.hasOwnProperty(this.model.responseModel)){F={sampleJSON:JSON.stringify(swaggerUi.api.models[this.model.responseModel].createJSONSample(),null,2),isParam:false,signature:swaggerUi.api.models[this.model.responseModel].getMockSignature()};E=new j({model:F,tagName:"div"});$(".model-signature",this.$el).append(E.render().el)}else{$(".model-signature",this.$el).html("")}return this};C.prototype.template=function(){return Handlebars.templates.status_code};return C})(Backbone.View);m=(function(D){y(C,D);function C(){c=C.__super__.constructor.apply(this,arguments);return c}C.prototype.initialize=function(){return Handlebars.registerHelper("isArray",function(F,E){if(F.type.toLowerCase()==="array"||F.allowMultiple){return E.fn(this)}else{return E.inverse(this)}})};C.prototype.render=function(){var E,F,I,G,J,H,M,N,L,K;K=this.model.type||this.model.dataType;if(typeof K==="undefined"){H=this.model.schema;if(H&&H["$ref"]){G=H["$ref"];if(G.indexOf("#/definitions/")===0){K=G.substring("#/definitions/".length)}else{K=G}}}this.model.type=K;this.model.paramType=this.model["in"]||this.model.paramType;if(this.model.paramType==="body"){this.model.isBody=true}if(K&&K.toLowerCase()==="file"){this.model.isFile=true}this.model["default"]=this.model["default"]||this.model.defaultValue;if(this.model.allowableValues){this.model.isList=true}L=this.template();$(this.el).html(L(this.model));M={sampleJSON:this.model.sampleJSON,isParam:true,signature:this.model.signature};if(this.model.sampleJSON){N=new j({model:M,tagName:"div"});$(".model-signature",$(this.el)).append(N.render().el)}else{$(".model-signature",$(this.el)).html(this.model.signature)}F=false;if(this.model.isBody){F=true}E={isParam:F};E.consumes=this.model.consumes;if(F){I=new n({model:E});$(".parameter-content-type",$(this.el)).append(I.render().el)}else{J=new o({model:E});$(".response-content-type",$(this.el)).append(J.render().el)}return this};C.prototype.template=function(){if(this.model.isList){return Handlebars.templates.param_list}else{if(this.options.readOnly){if(this.model.required){return Handlebars.templates.param_readonly_required}else{return Handlebars.templates.param_readonly}}else{if(this.model.required){return Handlebars.templates.param_required}else{return Handlebars.templates.param}}}};return C})(Backbone.View);j=(function(D){y(C,D);function C(){a=C.__super__.constructor.apply(this,arguments);return a}C.prototype.events={"click a.description-link":"switchToDescription","click a.snippet-link":"switchToSnippet","mousedown .snippet":"snippetToTextArea"};C.prototype.initialize=function(){};C.prototype.render=function(){var E;E=this.template();$(this.el).html(E(this.model));this.switchToSnippet();this.isParam=this.model.isParam;if(this.isParam){$(".notice",$(this.el)).text("Click to set as parameter value")}return this};C.prototype.template=function(){return Handlebars.templates.signature};C.prototype.switchToDescription=function(E){if(E!=null){E.preventDefault()}$(".snippet",$(this.el)).hide();$(".description",$(this.el)).show();$(".description-link",$(this.el)).addClass("selected");return $(".snippet-link",$(this.el)).removeClass("selected")};C.prototype.switchToSnippet=function(E){if(E!=null){E.preventDefault()}$(".description",$(this.el)).hide();$(".snippet",$(this.el)).show();$(".snippet-link",$(this.el)).addClass("selected");return $(".description-link",$(this.el)).removeClass("selected")};C.prototype.snippetToTextArea=function(E){var F;if(this.isParam){if(E!=null){E.preventDefault()}F=$("textarea",$(this.el.parentNode.parentNode.parentNode));if($.trim(F.val())===""){return F.val(this.model.sampleJSON)}}};return C})(Backbone.View);l=(function(C){y(D,C);function D(){A=D.__super__.constructor.apply(this,arguments);return A}D.prototype.initialize=function(){};D.prototype.render=function(){var E;E=this.template();$(this.el).html(E(this.model));$("label[for=contentType]",$(this.el)).text("Response Content Type");return this};D.prototype.template=function(){return Handlebars.templates.content_type};return D})(Backbone.View);o=(function(C){y(D,C);function D(){z=D.__super__.constructor.apply(this,arguments);return z}D.prototype.initialize=function(){};D.prototype.render=function(){var E;E=this.template();$(this.el).html(E(this.model));$("label[for=responseContentType]",$(this.el)).text("Response Content Type");return this};D.prototype.template=function(){return Handlebars.templates.response_content_type};return D})(Backbone.View);n=(function(D){y(C,D);function C(){d=C.__super__.constructor.apply(this,arguments);return d}C.prototype.initialize=function(){};C.prototype.render=function(){var E;E=this.template();$(this.el).html(E(this.model));$("label[for=parameterContentType]",$(this.el)).text("Parameter content type:");return this};C.prototype.template=function(){return Handlebars.templates.parameter_content_type};return C})(Backbone.View);t=(function(D){y(C,D);function C(){b=C.__super__.constructor.apply(this,arguments);return b}C.prototype.initialize=function(){};C.prototype.render=function(){var E;E=this.template();$(this.el).html(E(this.model));return this};C.prototype.events={"click #apikey_button":"toggleApiKeyContainer","click #apply_api_key":"applyApiKey"};C.prototype.applyApiKey=function(){var E;window.authorizations.add(this.model.name,new ApiKeyAuthorization(this.model.name,$("#input_apiKey_entry").val(),this.model["in"]));window.swaggerUi.load();return E=$("#apikey_container").show()};C.prototype.toggleApiKeyContainer=function(){var E;if($("#apikey_container").length>0){E=$("#apikey_container").first();if(E.is(":visible")){return E.hide()}else{$(".auth_container").hide();return E.show()}}};C.prototype.template=function(){return Handlebars.templates.apikey_button_view};return C})(Backbone.View);k=(function(D){y(C,D);function C(){B=C.__super__.constructor.apply(this,arguments);return B}C.prototype.initialize=function(){};C.prototype.render=function(){var E;E=this.template();$(this.el).html(E(this.model));return this};C.prototype.events={"click #basic_auth_button":"togglePasswordContainer","click #apply_basic_auth":"applyPassword"};C.prototype.applyPassword=function(){var F,E,G;console.log("applying password");G=$(".input_username").val();E=$(".input_password").val();window.authorizations.add(this.model.type,new PasswordAuthorization("basic",G,E));window.swaggerUi.load();return F=$("#basic_auth_container").hide()};C.prototype.togglePasswordContainer=function(){var E;if($("#basic_auth_container").length>0){E=$("#basic_auth_container").show();if(E.is(":visible")){return E.slideUp()}else{$(".auth_container").hide();return E.show()}}};C.prototype.template=function(){return Handlebars.templates.basic_auth_button_view};return C})(Backbone.View)}).call(this);`) +var _www_swagger_ui_swagger_ui_min_js = []byte(`$(function(){$.fn.vAlign=function(){return this.each(function(c){var a=$(this).height();var d=$(this).parent().height();var b=(d-a)/2;$(this).css("margin-top",b)})};$.fn.stretchFormtasticInputWidthToParent=function(){return this.each(function(b){var d=$(this).closest("form").innerWidth();var c=parseInt($(this).closest("form").css("padding-left"),10)+parseInt($(this).closest("form").css("padding-right"),10);var a=parseInt($(this).css("padding-left"),10)+parseInt($(this).css("padding-right"),10);$(this).css("width",d-c-a)})};$("form.formtastic li.string input, form.formtastic textarea").stretchFormtasticInputWidthToParent();$("ul.downplayed li div.content p").vAlign();$("form.sandbox").submit(function(){var a=true;$(this).find("input.required").each(function(){$(this).removeClass("error");if($(this).val()==""){$(this).addClass("error");$(this).wiggle();a=false}});return a})});function clippyCopiedCallback(b){$("#api_key_copied").fadeIn().delay(1000).fadeOut()}log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){console.log(Array.prototype.slice.call(arguments)[0])}};if(Function.prototype.bind&&console&&typeof console.log=="object"){["log","info","warn","error","assert","dir","clear","profile","profileEnd"].forEach(function(a){console[a]=this.bind(console[a],console)},Function.prototype.call)}var Docs={shebang:function(){var b=$.param.fragment().split("/");b.shift();switch(b.length){case 1:var d="resource_"+b[0];Docs.expandEndpointListForResource(b[0]);$("#"+d).slideto({highlight:false});break;case 2:Docs.expandEndpointListForResource(b[0]);$("#"+d).slideto({highlight:false});var c=b.join("_");var a=c+"_content";Docs.expandOperation($("#"+a));$("#"+c).slideto({highlight:false});break}},toggleEndpointListForResource:function(b){var a=$("li#resource_"+Docs.escapeName(b)+" ul.endpoints");if(a.is(":visible")){Docs.collapseEndpointListForResource(b)}else{Docs.expandEndpointListForResource(b)}},expandEndpointListForResource:function(b){var b=Docs.escapeName(b);if(b==""){$(".resource ul.endpoints").slideDown();return}$("li#resource_"+b).addClass("active");var a=$("li#resource_"+b+" ul.endpoints");a.slideDown()},collapseEndpointListForResource:function(b){var b=Docs.escapeName(b);$("li#resource_"+b).removeClass("active");var a=$("li#resource_"+b+" ul.endpoints");a.slideUp()},expandOperationsForResource:function(a){Docs.expandEndpointListForResource(a);if(a==""){$(".resource ul.endpoints li.operation div.content").slideDown();return}$("li#resource_"+Docs.escapeName(a)+" li.operation div.content").each(function(){Docs.expandOperation($(this))})},collapseOperationsForResource:function(a){Docs.expandEndpointListForResource(a);$("li#resource_"+Docs.escapeName(a)+" li.operation div.content").each(function(){Docs.collapseOperation($(this))})},escapeResourceName:function(a){return a.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^` + "`" + `{|}~]/g,"\\$&")},expandOperation:function(a){a.slideDown()},collapseOperation:function(a){a.slideUp()}};(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.apikey_button_view=b(function(e,k,d,j,i){this.compilerInfo=[4,">= 1.0.0"];d=this.merge(d,e.helpers);i=i||{};var g="",c,f="function",h=this.escapeExpression;g+="\n
")+"
";if(C=s.description){C=C.call(E,{hash:{},data:D})}else{C=E.description;C=typeof C===e?C.apply(E):C}if(C||C===0){B+=C}B+="
\n ";return B}function m(C,B){return'\n\n
Parameter | \nValue | \nDescription | \nParameter Type | \nData Type | \n
---|
HTTP Status Code | \nReason | \nResponse Model | \n
---|
';if(c=d.sampleJSON){c=c.call(k,{hash:{},data:i})}else{c=k.sampleJSON;c=typeof c===f?c.apply(k):c}g+=h(c)+'
\n \n
").text(Q);I=$('').append(G)}else{if(P==="application/xml"||/\+xml$/.test(P)){G=$("
").text(this.formatXml(N));I=$('').append(G)}else{if(P==="text/html"){G=$("
").html(_.escape(N));I=$('').append(G)}else{if(/^image\//.test(P)){I=$("").attr("src",F)}else{G=$("
").text(N);I=$('').append(G)}}}}}L=I;$(".request_url",$(this.el)).html("");$(".request_url pre",$(this.el)).text(F);$(".response_code",$(this.el)).html(""+J.status+"");$(".response_body",$(this.el)).html(L);$(".response_headers",$(this.el)).html("
"+_.escape(JSON.stringify(J.headers,null," ")).replace(/\n/g,"");$(".response",$(this.el)).slideDown();$(".response_hider",$(this.el)).show();$(".response_throbber",$(this.el)).hide();K=$(".response_body",$(this.el))[0];E=this.options.swaggerOptions;if(E.highlightSizeThreshold&&J.data.length>E.highlightSizeThreshold){return K}else{return hljs.highlightBlock(K)}};C.prototype.toggleOperationContent=function(){var E;E=$("#"+Docs.escapeName(this.model.parentId+"_"+this.model.nickname+"_content"));if(E.is(":visible")){return Docs.collapseOperation(E)}else{return Docs.expandOperation(E)}};return C})(Backbone.View);r=(function(D){y(C,D);function C(){e=C.__super__.constructor.apply(this,arguments);return e}C.prototype.initialize=function(){};C.prototype.render=function(){var F,E,G;G=this.template();$(this.el).html(G(this.model));if(swaggerUi.api.models.hasOwnProperty(this.model.responseModel)){F={sampleJSON:JSON.stringify(swaggerUi.api.models[this.model.responseModel].createJSONSample(),null,2),isParam:false,signature:swaggerUi.api.models[this.model.responseModel].getMockSignature()};E=new j({model:F,tagName:"div"});$(".model-signature",this.$el).append(E.render().el)}else{$(".model-signature",this.$el).html("")}return this};C.prototype.template=function(){return Handlebars.templates.status_code};return C})(Backbone.View);m=(function(D){y(C,D);function C(){c=C.__super__.constructor.apply(this,arguments);return c}C.prototype.initialize=function(){return Handlebars.registerHelper("isArray",function(F,E){if(F.type.toLowerCase()==="array"||F.allowMultiple){return E.fn(this)}else{return E.inverse(this)}})};C.prototype.render=function(){var E,F,I,G,J,H,M,N,L,K;K=this.model.type||this.model.dataType;if(typeof K==="undefined"){H=this.model.schema;if(H&&H["$ref"]){G=H["$ref"];if(G.indexOf("#/definitions/")===0){K=G.substring("#/definitions/".length)}else{K=G}}}this.model.type=K;this.model.paramType=this.model["in"]||this.model.paramType;if(this.model.paramType==="body"){this.model.isBody=true}if(K&&K.toLowerCase()==="file"){this.model.isFile=true}this.model["default"]=this.model["default"]||this.model.defaultValue;if(this.model.allowableValues){this.model.isList=true}L=this.template();$(this.el).html(L(this.model));M={sampleJSON:this.model.sampleJSON,isParam:true,signature:this.model.signature};if(this.model.sampleJSON){N=new j({model:M,tagName:"div"});$(".model-signature",$(this.el)).append(N.render().el)}else{$(".model-signature",$(this.el)).html(this.model.signature)}F=false;if(this.model.isBody){F=true}E={isParam:F};E.consumes=this.model.consumes;if(F){I=new n({model:E});$(".parameter-content-type",$(this.el)).append(I.render().el)}else{J=new o({model:E});$(".response-content-type",$(this.el)).append(J.render().el)}return this};C.prototype.template=function(){if(this.model.isList){return Handlebars.templates.param_list}else{if(this.options.readOnly){if(this.model.required){return Handlebars.templates.param_readonly_required}else{return Handlebars.templates.param_readonly}}else{if(this.model.required){return Handlebars.templates.param_required}else{return Handlebars.templates.param}}}};return C})(Backbone.View);j=(function(D){y(C,D);function C(){a=C.__super__.constructor.apply(this,arguments);return a}C.prototype.events={"click a.description-link":"switchToDescription","click a.snippet-link":"switchToSnippet","mousedown .snippet":"snippetToTextArea"};C.prototype.initialize=function(){};C.prototype.render=function(){var E;E=this.template();$(this.el).html(E(this.model));this.switchToSnippet();this.isParam=this.model.isParam;if(this.isParam){$(".notice",$(this.el)).text("Click to set as parameter value")}return this};C.prototype.template=function(){return Handlebars.templates.signature};C.prototype.switchToDescription=function(E){if(E!=null){E.preventDefault()}$(".snippet",$(this.el)).hide();$(".description",$(this.el)).show();$(".description-link",$(this.el)).addClass("selected");return $(".snippet-link",$(this.el)).removeClass("selected")};C.prototype.switchToSnippet=function(E){if(E!=null){E.preventDefault()}$(".description",$(this.el)).hide();$(".snippet",$(this.el)).show();$(".snippet-link",$(this.el)).addClass("selected");return $(".description-link",$(this.el)).removeClass("selected")};C.prototype.snippetToTextArea=function(E){var F;if(this.isParam){if(E!=null){E.preventDefault()}F=$("textarea",$(this.el.parentNode.parentNode.parentNode));if($.trim(F.val())===""){return F.val(this.model.sampleJSON)}}};return C})(Backbone.View);l=(function(C){y(D,C);function D(){A=D.__super__.constructor.apply(this,arguments);return A}D.prototype.initialize=function(){};D.prototype.render=function(){var E;E=this.template();$(this.el).html(E(this.model));$("label[for=contentType]",$(this.el)).text("Response Content Type");return this};D.prototype.template=function(){return Handlebars.templates.content_type};return D})(Backbone.View);o=(function(C){y(D,C);function D(){z=D.__super__.constructor.apply(this,arguments);return z}D.prototype.initialize=function(){};D.prototype.render=function(){var E;E=this.template();$(this.el).html(E(this.model));$("label[for=responseContentType]",$(this.el)).text("Response Content Type");return this};D.prototype.template=function(){return Handlebars.templates.response_content_type};return D})(Backbone.View);n=(function(D){y(C,D);function C(){d=C.__super__.constructor.apply(this,arguments);return d}C.prototype.initialize=function(){};C.prototype.render=function(){var E;E=this.template();$(this.el).html(E(this.model));$("label[for=parameterContentType]",$(this.el)).text("Parameter content type:");return this};C.prototype.template=function(){return Handlebars.templates.parameter_content_type};return C})(Backbone.View);t=(function(D){y(C,D);function C(){b=C.__super__.constructor.apply(this,arguments);return b}C.prototype.initialize=function(){};C.prototype.render=function(){var E;E=this.template();$(this.el).html(E(this.model));return this};C.prototype.events={"click #apikey_button":"toggleApiKeyContainer","click #apply_api_key":"applyApiKey"};C.prototype.applyApiKey=function(){var E;window.authorizations.add(this.model.name,new ApiKeyAuthorization(this.model.name,$("#input_apiKey_entry").val(),this.model["in"]));window.swaggerUi.load();return E=$("#apikey_container").show()};C.prototype.toggleApiKeyContainer=function(){var E;if($("#apikey_container").length>0){E=$("#apikey_container").first();if(E.is(":visible")){return E.hide()}else{$(".auth_container").hide();return E.show()}}};C.prototype.template=function(){return Handlebars.templates.apikey_button_view};return C})(Backbone.View);k=(function(D){y(C,D);function C(){B=C.__super__.constructor.apply(this,arguments);return B}C.prototype.initialize=function(){};C.prototype.render=function(){var E;E=this.template();$(this.el).html(E(this.model));return this};C.prototype.events={"click #basic_auth_button":"togglePasswordContainer","click #apply_basic_auth":"applyPassword"};C.prototype.applyPassword=function(){var F,E,G;console.log("applying password");G=$(".input_username").val();E=$(".input_password").val();window.authorizations.add(this.model.type,new PasswordAuthorization("basic",G,E));window.swaggerUi.load();return F=$("#basic_auth_container").hide()};C.prototype.togglePasswordContainer=function(){var E;if($("#basic_auth_container").length>0){E=$("#basic_auth_container").show();if(E.is(":visible")){return E.slideUp()}else{$(".auth_container").hide();return E.show()}}};C.prototype.template=function(){return Handlebars.templates.basic_auth_button_view};return C})(Backbone.View)}).call(this);`) func www_swagger_ui_swagger_ui_min_js_bytes() ([]byte, error) { return _www_swagger_ui_swagger_ui_min_js, nil diff --git a/plugin/pkg/scheduler/factory/factory.go b/plugin/pkg/scheduler/factory/factory.go index d87a596e9cfcf..a7c18c9b01ec5 100644 --- a/plugin/pkg/scheduler/factory/factory.go +++ b/plugin/pkg/scheduler/factory/factory.go @@ -139,7 +139,7 @@ type listWatch struct { func (lw *listWatch) List() (runtime.Object, error) { return lw.client. Get(). - Path(lw.resource). + Resource(lw.resource). SelectorParam("fields", lw.fieldSelector). Do(). Get() @@ -148,8 +148,8 @@ func (lw *listWatch) List() (runtime.Object, error) { func (lw *listWatch) Watch(resourceVersion string) (watch.Interface, error) { return lw.client. Get(). - Path("watch"). - Path(lw.resource). + Prefix("watch"). + Resource(lw.resource). SelectorParam("fields", lw.fieldSelector). Param("resourceVersion", resourceVersion). Watch() @@ -195,7 +195,7 @@ func (factory *ConfigFactory) createMinionLW() *listWatch { // pollMinions lists all minions and returns an enumerator for cache.Poller. func (factory *ConfigFactory) pollMinions() (cache.Enumerator, error) { list := &api.NodeList{} - err := factory.Client.Get().Path("minions").Do().Into(list) + err := factory.Client.Get().Resource("minions").Do().Into(list) if err != nil { return nil, err } @@ -215,7 +215,7 @@ func (factory *ConfigFactory) makeDefaultErrorFunc(backoff *podBackoff, podQueue backoff.wait(podID) // Get the pod again; it may have changed/been scheduled already. pod = &api.Pod{} - err := factory.Client.Get().Namespace(podNamespace).Path("pods").Path(podID).Do().Into(pod) + err := factory.Client.Get().Namespace(podNamespace).Resource("pods").Name(podID).Do().Into(pod) if err != nil { glog.Errorf("Error getting pod %v for retry: %v; abandoning", podID, err) return @@ -288,7 +288,7 @@ type binder struct { func (b *binder) Bind(binding *api.Binding) error { glog.V(2).Infof("Attempting to bind %v to %v", binding.PodID, binding.Host) ctx := api.WithNamespace(api.NewContext(), binding.Namespace) - return b.Post().Namespace(api.Namespace(ctx)).Path("bindings").Body(binding).Do().Error() + return b.Post().Namespace(api.Namespace(ctx)).Resource("bindings").Body(binding).Do().Error() } type clock interface {
")+"