mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-17 15:13:08 +00:00
Rename client Minions->Nodes, select the correct path for v1beta3
Replaces the client public interface but leaves old references to "minions" for a later refactor. Selects the path "nodes" for v1beta3 and "minions" for older versions.
This commit is contained in:
@@ -32,7 +32,7 @@ type Interface interface {
|
||||
ServicesNamespacer
|
||||
EndpointsNamespacer
|
||||
VersionInterface
|
||||
MinionsInterface
|
||||
NodesInterface
|
||||
EventNamespacer
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ func (c *Client) ReplicationControllers(namespace string) ReplicationControllerI
|
||||
return newReplicationControllers(c, namespace)
|
||||
}
|
||||
|
||||
func (c *Client) Minions() MinionInterface {
|
||||
return newMinions(c)
|
||||
func (c *Client) Nodes() NodeInterface {
|
||||
return newNodes(c, c.preV1Beta3)
|
||||
}
|
||||
|
||||
func (c *Client) Events(namespace string) EventInterface {
|
||||
@@ -75,6 +75,9 @@ type APIStatus interface {
|
||||
// Client is the implementation of a Kubernetes client.
|
||||
type Client struct {
|
||||
*RESTClient
|
||||
|
||||
// preV1Beta3 is true for v1beta1 and v1beta2
|
||||
preV1Beta3 bool
|
||||
}
|
||||
|
||||
// ServerVersion retrieves and parses the server's version.
|
||||
|
@@ -28,6 +28,7 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/resources"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
@@ -59,6 +60,7 @@ type testClient struct {
|
||||
Response Response
|
||||
Error bool
|
||||
Created bool
|
||||
Version string
|
||||
server *httptest.Server
|
||||
handler *util.FakeHandler
|
||||
// For query args, an optional function to validate the contents
|
||||
@@ -77,9 +79,13 @@ func (c *testClient) Setup() *testClient {
|
||||
}
|
||||
c.server = httptest.NewServer(c.handler)
|
||||
if c.Client == nil {
|
||||
version := c.Version
|
||||
if len(version) == 0 {
|
||||
version = testapi.Version()
|
||||
}
|
||||
c.Client = NewOrDie(&Config{
|
||||
Host: c.server.URL,
|
||||
Version: "v1beta1",
|
||||
Version: version,
|
||||
})
|
||||
}
|
||||
c.QueryValidator = map[string]func(string, string) bool{}
|
||||
@@ -606,7 +612,7 @@ func TestListMinions(t *testing.T) {
|
||||
Request: testRequest{Method: "GET", Path: "/minions"},
|
||||
Response: Response{StatusCode: 200, Body: &api.NodeList{ListMeta: api.ListMeta{ResourceVersion: "1"}}},
|
||||
}
|
||||
response, err := c.Setup().Minions().List()
|
||||
response, err := c.Setup().Nodes().List()
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
@@ -615,7 +621,7 @@ func TestGetMinion(t *testing.T) {
|
||||
Request: testRequest{Method: "GET", Path: "/minions/1"},
|
||||
Response: Response{StatusCode: 200, Body: &api.Node{ObjectMeta: api.ObjectMeta{Name: "minion-1"}}},
|
||||
}
|
||||
response, err := c.Setup().Minions().Get("1")
|
||||
response, err := c.Setup().Nodes().Get("1")
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
@@ -641,7 +647,7 @@ func TestCreateMinion(t *testing.T) {
|
||||
Body: requestMinion,
|
||||
},
|
||||
}
|
||||
receivedMinion, err := c.Setup().Minions().Create(requestMinion)
|
||||
receivedMinion, err := c.Setup().Nodes().Create(requestMinion)
|
||||
c.Validate(t, receivedMinion, err)
|
||||
}
|
||||
|
||||
@@ -650,6 +656,17 @@ func TestDeleteMinion(t *testing.T) {
|
||||
Request: testRequest{Method: "DELETE", Path: "/minions/foo"},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
err := c.Setup().Minions().Delete("foo")
|
||||
err := c.Setup().Nodes().Delete("foo")
|
||||
c.Validate(t, nil, err)
|
||||
}
|
||||
|
||||
func TestNewMinionPath(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "DELETE", Path: "/nodes/foo"},
|
||||
Response: Response{StatusCode: 200},
|
||||
}
|
||||
cl := c.Setup()
|
||||
cl.preV1Beta3 = false
|
||||
err := cl.Nodes().Delete("foo")
|
||||
c.Validate(t, nil, err)
|
||||
}
|
||||
|
@@ -49,8 +49,8 @@ func (c *Fake) ReplicationControllers(namespace string) ReplicationControllerInt
|
||||
return &FakeReplicationControllers{Fake: c, Namespace: namespace}
|
||||
}
|
||||
|
||||
func (c *Fake) Minions() MinionInterface {
|
||||
return &FakeMinions{Fake: c}
|
||||
func (c *Fake) Nodes() NodeInterface {
|
||||
return &FakeNodes{Fake: c}
|
||||
}
|
||||
|
||||
func (c *Fake) Events(namespace string) EventInterface {
|
||||
|
@@ -18,30 +18,36 @@ package client
|
||||
|
||||
import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
)
|
||||
|
||||
// FakeMinions implements MinionInterface. Meant to be embedded into a struct to get a default
|
||||
// FakeNodes implements MinionInterface. Meant to be embedded into a struct to get a default
|
||||
// implementation. This makes faking out just the method you want to test easier.
|
||||
type FakeMinions struct {
|
||||
type FakeNodes struct {
|
||||
Fake *Fake
|
||||
}
|
||||
|
||||
func (c *FakeMinions) Get(name string) (*api.Node, error) {
|
||||
func (c *FakeNodes) Get(name string) (*api.Node, error) {
|
||||
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "get-minion", Value: name})
|
||||
return &api.Node{}, nil
|
||||
for i := range c.Fake.MinionsList.Items {
|
||||
if c.Fake.MinionsList.Items[i].Name == name {
|
||||
return &c.Fake.MinionsList.Items[i], nil
|
||||
}
|
||||
}
|
||||
return nil, errors.NewNotFound("Minions", name)
|
||||
}
|
||||
|
||||
func (c *FakeMinions) List() (*api.NodeList, error) {
|
||||
func (c *FakeNodes) List() (*api.NodeList, error) {
|
||||
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "list-minions", Value: nil})
|
||||
return &c.Fake.MinionsList, nil
|
||||
}
|
||||
|
||||
func (c *FakeMinions) Create(minion *api.Node) (*api.Node, error) {
|
||||
func (c *FakeNodes) Create(minion *api.Node) (*api.Node, error) {
|
||||
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "create-minion", Value: minion})
|
||||
return &api.Node{}, nil
|
||||
}
|
||||
|
||||
func (c *FakeMinions) Delete(id string) error {
|
||||
func (c *FakeNodes) Delete(id string) error {
|
||||
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "delete-minion", Value: id})
|
||||
return nil
|
||||
}
|
||||
|
@@ -87,7 +87,9 @@ func New(c *Config) (*Client, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Client{client}, nil
|
||||
version := defaultVersionFor(&config)
|
||||
isPreV1Beta3 := (version == "v1beta1" || version == "v1beta2")
|
||||
return &Client{client, isPreV1Beta3}, nil
|
||||
}
|
||||
|
||||
// NewOrDie creates a Kubernetes client and panics if the provided API version is not recognized.
|
||||
|
@@ -18,49 +18,58 @@ package client
|
||||
|
||||
import "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
|
||||
type MinionsInterface interface {
|
||||
Minions() MinionInterface
|
||||
type NodesInterface interface {
|
||||
Nodes() NodeInterface
|
||||
}
|
||||
|
||||
type MinionInterface interface {
|
||||
type NodeInterface interface {
|
||||
Get(id string) (result *api.Node, err error)
|
||||
Create(minion *api.Node) (*api.Node, error)
|
||||
List() (*api.NodeList, error)
|
||||
Delete(id string) error
|
||||
}
|
||||
|
||||
// minions implements Minions interface
|
||||
type minions struct {
|
||||
r *Client
|
||||
// nodes implements NodesInterface
|
||||
type nodes struct {
|
||||
r *Client
|
||||
preV1Beta3 bool
|
||||
}
|
||||
|
||||
// newMinions returns a minions
|
||||
func newMinions(c *Client) *minions {
|
||||
return &minions{c}
|
||||
// newNodes returns a nodes object. Uses "minions" as the
|
||||
// URL resource name for v1beta1 and v1beta2.
|
||||
func newNodes(c *Client, isPreV1Beta3 bool) *nodes {
|
||||
return &nodes{c, isPreV1Beta3}
|
||||
}
|
||||
|
||||
func (c *nodes) resourceName() string {
|
||||
if c.preV1Beta3 {
|
||||
return "minions"
|
||||
}
|
||||
return "nodes"
|
||||
}
|
||||
|
||||
// Create creates a new minion.
|
||||
func (c *minions) Create(minion *api.Node) (*api.Node, error) {
|
||||
func (c *nodes) Create(minion *api.Node) (*api.Node, error) {
|
||||
result := &api.Node{}
|
||||
err := c.r.Post().Path("minions").Body(minion).Do().Into(result)
|
||||
err := c.r.Post().Path(c.resourceName()).Body(minion).Do().Into(result)
|
||||
return result, err
|
||||
}
|
||||
|
||||
// List lists all the minions in the cluster.
|
||||
func (c *minions) List() (*api.NodeList, error) {
|
||||
// List lists all the nodes in the cluster.
|
||||
func (c *nodes) List() (*api.NodeList, error) {
|
||||
result := &api.NodeList{}
|
||||
err := c.r.Get().Path("minions").Do().Into(result)
|
||||
err := c.r.Get().Path(c.resourceName()).Do().Into(result)
|
||||
return result, err
|
||||
}
|
||||
|
||||
// Get gets an existing minion
|
||||
func (c *minions) Get(id string) (*api.Node, error) {
|
||||
func (c *nodes) Get(id string) (*api.Node, error) {
|
||||
result := &api.Node{}
|
||||
err := c.r.Get().Path("minions").Path(id).Do().Into(result)
|
||||
err := c.r.Get().Path(c.resourceName()).Path(id).Do().Into(result)
|
||||
return result, err
|
||||
}
|
||||
|
||||
// Delete deletes an existing minion.
|
||||
func (c *minions) Delete(id string) error {
|
||||
return c.r.Delete().Path("minions").Path(id).Do().Error()
|
||||
func (c *nodes) Delete(id string) error {
|
||||
return c.r.Delete().Path(c.resourceName()).Path(id).Do().Error()
|
||||
}
|
||||
|
Reference in New Issue
Block a user