mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
add node update method to client interface
This commit is contained in:
parent
3c370d0b1b
commit
e71227388e
@ -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"},
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user