Merge pull request #3591 from ddysher/node-client-update

Add node update method to client interface
This commit is contained in:
Clayton Coleman 2015-01-26 15:47:18 -05:00
commit 6410f37a32
4 changed files with 51 additions and 6 deletions

View File

@ -759,6 +759,27 @@ func TestDeleteMinion(t *testing.T) {
c.Validate(t, nil, err) 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) { func TestNewMinionPath(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{Method: "DELETE", Path: "/nodes/foo"}, Request: testRequest{Method: "DELETE", Path: "/nodes/foo"},

View File

@ -51,3 +51,8 @@ func (c *FakeNodes) Delete(id string) error {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "delete-minion", Value: id}) c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "delete-minion", Value: id})
return nil 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
}

View File

@ -18,6 +18,7 @@ package client
import ( import (
"errors" "errors"
"fmt"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
) )
@ -31,6 +32,7 @@ type NodeInterface interface {
Create(minion *api.Node) (*api.Node, error) Create(minion *api.Node) (*api.Node, error)
List() (*api.NodeList, error) List() (*api.NodeList, error)
Delete(name string) error Delete(name string) error
Update(*api.Node) (*api.Node, error)
} }
// nodes implements NodesInterface // nodes implements NodesInterface
@ -44,6 +46,7 @@ func newNodes(c *Client) *nodes {
return &nodes{c} return &nodes{c}
} }
// resourceName returns node's URL resource name based on resource version.
func (c *nodes) resourceName() string { func (c *nodes) resourceName() string {
if preV1Beta3(c.r.APIVersion()) { if preV1Beta3(c.r.APIVersion()) {
return "minions" return "minions"
@ -51,7 +54,7 @@ func (c *nodes) resourceName() string {
return "nodes" return "nodes"
} }
// Create creates a new minion. // Create creates a new node.
func (c *nodes) Create(minion *api.Node) (*api.Node, error) { func (c *nodes) Create(minion *api.Node) (*api.Node, error) {
result := &api.Node{} result := &api.Node{}
err := c.r.Post().Resource(c.resourceName()).Body(minion).Do().Into(result) 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 return result, err
} }
// Get gets an existing minion // Get gets an existing node.
func (c *nodes) Get(name string) (*api.Node, error) { func (c *nodes) Get(name string) (*api.Node, error) {
if len(name) == 0 { if len(name) == 0 {
return nil, errors.New("name is required parameter to Get") 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 return result, err
} }
// Delete deletes an existing minion. // Delete deletes an existing node.
func (c *nodes) Delete(name string) error { func (c *nodes) Delete(name string) error {
return c.r.Delete().Resource(c.resourceName()).Name(name).Do().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
}

View File

@ -48,7 +48,7 @@ func (n *nodeAdaptor) Nodes() client.NodeInterface {
return n return n
} }
// Create creates a new minion. // Create creates a new node.
func (n *nodeAdaptor) Create(minion *api.Node) (*api.Node, error) { func (n *nodeAdaptor) Create(minion *api.Node) (*api.Node, error) {
return nil, errors.New("direct creation not implemented") return nil, errors.New("direct creation not implemented")
// TODO: apiserver should expose newOperation to make this easier. // 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 return obj.(*api.NodeList), nil
} }
// Get gets an existing minion // Get gets an existing node.
func (n *nodeAdaptor) Get(name string) (*api.Node, error) { func (n *nodeAdaptor) Get(name string) (*api.Node, error) {
ctx := api.NewContext() ctx := api.NewContext()
obj, err := n.storage.(apiserver.RESTGetter).Get(ctx, name) 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 return obj.(*api.Node), nil
} }
// Delete deletes an existing minion. // Delete deletes an existing node.
// TODO: implement // TODO: implement
func (n *nodeAdaptor) Delete(name string) error { func (n *nodeAdaptor) Delete(name string) error {
return errors.New("direct deletion not implemented") 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")
}