diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 7bfff9bfade..c9e7d4f713e 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -759,6 +759,27 @@ func TestDeleteMinion(t *testing.T) { c.Validate(t, nil, err) } +func TestUpdateMinion(t *testing.T) { + requestMinion := &api.Node{ + ObjectMeta: api.ObjectMeta{ + Name: "foo", + ResourceVersion: "1", + }, + Spec: api.NodeSpec{ + Capacity: api.ResourceList{ + api.ResourceCPU: resource.MustParse("1000m"), + api.ResourceMemory: resource.MustParse("1Mi"), + }, + }, + } + c := &testClient{ + Request: testRequest{Method: "PUT", Path: "/minions/foo"}, + Response: Response{StatusCode: 200, Body: requestMinion}, + } + response, err := c.Setup().Nodes().Update(requestMinion) + c.Validate(t, response, err) +} + func TestNewMinionPath(t *testing.T) { c := &testClient{ Request: testRequest{Method: "DELETE", Path: "/nodes/foo"}, diff --git a/pkg/client/fake_minions.go b/pkg/client/fake_minions.go index aa1d2c04926..d3e195673d0 100644 --- a/pkg/client/fake_minions.go +++ b/pkg/client/fake_minions.go @@ -51,3 +51,8 @@ func (c *FakeNodes) Delete(id string) error { c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "delete-minion", Value: id}) return nil } + +func (c *FakeNodes) Update(minion *api.Node) (*api.Node, error) { + c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "update-minion", Value: minion}) + return &api.Node{}, nil +} diff --git a/pkg/client/minions.go b/pkg/client/minions.go index 2ed08688723..fb4c20cd998 100644 --- a/pkg/client/minions.go +++ b/pkg/client/minions.go @@ -18,6 +18,7 @@ package client import ( "errors" + "fmt" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" ) @@ -31,6 +32,7 @@ type NodeInterface interface { Create(minion *api.Node) (*api.Node, error) List() (*api.NodeList, error) Delete(name string) error + Update(*api.Node) (*api.Node, error) } // nodes implements NodesInterface @@ -44,6 +46,7 @@ func newNodes(c *Client) *nodes { return &nodes{c} } +// resourceName returns node's URL resource name based on resource version. func (c *nodes) resourceName() string { if preV1Beta3(c.r.APIVersion()) { return "minions" @@ -51,7 +54,7 @@ func (c *nodes) resourceName() string { return "nodes" } -// Create creates a new minion. +// Create creates a new node. func (c *nodes) Create(minion *api.Node) (*api.Node, error) { result := &api.Node{} err := c.r.Post().Resource(c.resourceName()).Body(minion).Do().Into(result) @@ -65,7 +68,7 @@ func (c *nodes) List() (*api.NodeList, error) { return result, err } -// Get gets an existing minion +// Get gets an existing node. func (c *nodes) Get(name string) (*api.Node, error) { if len(name) == 0 { return nil, errors.New("name is required parameter to Get") @@ -76,7 +79,18 @@ func (c *nodes) Get(name string) (*api.Node, error) { return result, err } -// Delete deletes an existing minion. +// Delete deletes an existing node. func (c *nodes) Delete(name string) error { return c.r.Delete().Resource(c.resourceName()).Name(name).Do().Error() } + +// Update updates an existing node. +func (c *nodes) Update(minion *api.Node) (*api.Node, error) { + result := &api.Node{} + if len(minion.ResourceVersion) == 0 { + err := fmt.Errorf("invalid update object, missing resource version: %v", minion) + return nil, err + } + err := c.r.Put().Resource(c.resourceName()).Name(minion.Name).Body(minion).Do().Into(result) + return result, err +} diff --git a/pkg/master/rest_to_nodes.go b/pkg/master/rest_to_nodes.go index e25fc2aba1e..087324749a4 100644 --- a/pkg/master/rest_to_nodes.go +++ b/pkg/master/rest_to_nodes.go @@ -48,7 +48,7 @@ func (n *nodeAdaptor) Nodes() client.NodeInterface { return n } -// Create creates a new minion. +// Create creates a new node. func (n *nodeAdaptor) Create(minion *api.Node) (*api.Node, error) { return nil, errors.New("direct creation not implemented") // TODO: apiserver should expose newOperation to make this easier. @@ -71,7 +71,7 @@ func (n *nodeAdaptor) List() (*api.NodeList, error) { return obj.(*api.NodeList), nil } -// Get gets an existing minion +// Get gets an existing node. func (n *nodeAdaptor) Get(name string) (*api.Node, error) { ctx := api.NewContext() obj, err := n.storage.(apiserver.RESTGetter).Get(ctx, name) @@ -81,8 +81,13 @@ func (n *nodeAdaptor) Get(name string) (*api.Node, error) { return obj.(*api.Node), nil } -// Delete deletes an existing minion. +// Delete deletes an existing node. // TODO: implement func (n *nodeAdaptor) Delete(name string) error { return errors.New("direct deletion not implemented") } + +// Update updates an existing node. +func (n *nodeAdaptor) Update(minion *api.Node) (*api.Node, error) { + return nil, errors.New("direct update not implemented") +}