Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add node update method to client interface #3591

Merged
merged 1 commit into from
Jan 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
5 changes: 5 additions & 0 deletions pkg/client/fake_minions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
20 changes: 17 additions & 3 deletions pkg/client/minions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package client

import (
"errors"
"fmt"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
Expand All @@ -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
Expand All @@ -44,14 +46,15 @@ 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"
}
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)
Expand All @@ -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")
Expand All @@ -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
}
11 changes: 8 additions & 3 deletions pkg/master/rest_to_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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")
}