mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
List in NodesInterface takes label selector
This commit is contained in:
parent
24b478dd0a
commit
d04cc5ced4
@ -32,7 +32,7 @@ type NodesInterface interface {
|
||||
type NodeInterface interface {
|
||||
Get(name string) (result *api.Node, err error)
|
||||
Create(node *api.Node) (*api.Node, error)
|
||||
List() (*api.NodeList, error)
|
||||
List(selector labels.Selector) (*api.NodeList, error)
|
||||
Delete(name string) error
|
||||
Update(*api.Node) (*api.Node, error)
|
||||
Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error)
|
||||
@ -64,10 +64,10 @@ func (c *nodes) Create(node *api.Node) (*api.Node, error) {
|
||||
return result, err
|
||||
}
|
||||
|
||||
// List lists all the nodes in the cluster.
|
||||
func (c *nodes) List() (*api.NodeList, error) {
|
||||
// List takes a selector, and returns the list of nodes that match that selector in the cluster.
|
||||
func (c *nodes) List(selector labels.Selector) (*api.NodeList, error) {
|
||||
result := &api.NodeList{}
|
||||
err := c.r.Get().Resource(c.resourceName()).Do().Into(result)
|
||||
err := c.r.Get().Resource(c.resourceName()).LabelsSelectorParam(selector).Do().Into(result)
|
||||
return result, err
|
||||
}
|
||||
|
||||
|
@ -17,11 +17,13 @@ limitations under the License.
|
||||
package client
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
)
|
||||
|
||||
func getNodesResourceName() string {
|
||||
@ -30,6 +32,7 @@ func getNodesResourceName() string {
|
||||
}
|
||||
return "nodes"
|
||||
}
|
||||
|
||||
func TestListMinions(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
@ -38,10 +41,41 @@ func TestListMinions(t *testing.T) {
|
||||
},
|
||||
Response: Response{StatusCode: 200, Body: &api.NodeList{ListMeta: api.ListMeta{ResourceVersion: "1"}}},
|
||||
}
|
||||
response, err := c.Setup().Nodes().List()
|
||||
response, err := c.Setup().Nodes().List(labels.Everything())
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
func TestListMinionsLabels(t *testing.T) {
|
||||
ns := api.NamespaceNone
|
||||
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Version())
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
Method: "GET",
|
||||
Path: testapi.ResourcePath(getNodesResourceName(), "", ""),
|
||||
Query: buildQueryValues(ns, url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: &api.NodeList{
|
||||
Items: []api.Node{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
c.Setup()
|
||||
c.QueryValidator[labelSelectorQueryParamName] = validateLabels
|
||||
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
|
||||
receivedNodeList, err := c.Nodes().List(selector)
|
||||
c.Validate(t, receivedNodeList, err)
|
||||
}
|
||||
|
||||
func TestGetMinion(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
@ -56,12 +90,12 @@ func TestGetMinion(t *testing.T) {
|
||||
|
||||
func TestGetMinionWithNoName(t *testing.T) {
|
||||
c := &testClient{Error: true}
|
||||
receivedPod, err := c.Setup().Nodes().Get("")
|
||||
receivedNode, err := c.Setup().Nodes().Get("")
|
||||
if (err != nil) && (err.Error() != nameRequiredError) {
|
||||
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
|
||||
}
|
||||
|
||||
c.Validate(t, receivedPod, err)
|
||||
c.Validate(t, receivedNode, err)
|
||||
}
|
||||
|
||||
func TestCreateMinion(t *testing.T) {
|
||||
|
@ -34,7 +34,7 @@ func (c *FakeNodes) Get(name string) (*api.Node, error) {
|
||||
return obj.(*api.Node), err
|
||||
}
|
||||
|
||||
func (c *FakeNodes) List() (*api.NodeList, error) {
|
||||
func (c *FakeNodes) List(selector labels.Selector) (*api.NodeList, error) {
|
||||
obj, err := c.Fake.Invokes(FakeAction{Action: "list-nodes"}, &api.NodeList{})
|
||||
return obj.(*api.NodeList), err
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ func (nc *NodeController) SyncCloudNodes() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nodes, err := nc.kubeClient.Nodes().List()
|
||||
nodes, err := nc.kubeClient.Nodes().List(labels.Everything())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -434,7 +434,7 @@ func (nc *NodeController) tryUpdateNodeStatus(node *api.Node) (time.Duration, ap
|
||||
// post "NodeReady==ConditionUnknown". It also evicts all pods if node is not ready or
|
||||
// not reachable for a long period of time.
|
||||
func (nc *NodeController) MonitorNodeStatus() error {
|
||||
nodes, err := nc.kubeClient.Nodes().List()
|
||||
nodes, err := nc.kubeClient.Nodes().List(labels.Everything())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ func (m *FakeNodeHandler) Get(name string) (*api.Node, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *FakeNodeHandler) List() (*api.NodeList, error) {
|
||||
func (m *FakeNodeHandler) List(selector labels.Selector) (*api.NodeList, error) {
|
||||
defer func() { m.RequestCount++ }()
|
||||
var nodes []*api.Node
|
||||
for i := 0; i < len(m.UpdatedNodes); i++ {
|
||||
|
@ -172,7 +172,7 @@ func NewMainKubelet(
|
||||
listWatch := &cache.ListWatch{
|
||||
ListFunc: func() (runtime.Object, error) {
|
||||
// TODO: Use List() with fieldSelector when it is supported.
|
||||
return kubeClient.Nodes().List()
|
||||
return kubeClient.Nodes().List(labels.Everything())
|
||||
},
|
||||
WatchFunc: func(resourceVersion string) (watch.Interface, error) {
|
||||
return kubeClient.Nodes().Watch(labels.Everything(), fieldSelector, resourceVersion)
|
||||
|
@ -27,6 +27,7 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
algorithm "github.com/GoogleCloudPlatform/kubernetes/pkg/scheduler"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler"
|
||||
@ -233,7 +234,7 @@ func (factory *ConfigFactory) createMinionLW() *cache.ListWatch {
|
||||
// Lists all minions and filter out unhealthy ones, then returns
|
||||
// an enumerator for cache.Poller.
|
||||
func (factory *ConfigFactory) pollMinions() (cache.Enumerator, error) {
|
||||
allNodes, err := factory.Client.Nodes().List()
|
||||
allNodes, err := factory.Client.Nodes().List(labels.Everything())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
)
|
||||
@ -47,7 +48,7 @@ var _ = Describe("Cadvisor", func() {
|
||||
|
||||
func CheckCadvisorHealthOnAllNodes(c *client.Client, timeout time.Duration) {
|
||||
By("getting list of nodes")
|
||||
nodeList, err := c.Nodes().List()
|
||||
nodeList, err := c.Nodes().List(labels.Everything())
|
||||
expectNoError(err)
|
||||
var errors []error
|
||||
retries := maxRetries
|
||||
|
@ -189,7 +189,7 @@ var _ = Describe("Density", func() {
|
||||
var err error
|
||||
c, err = loadClient()
|
||||
expectNoError(err)
|
||||
minions, err := c.Nodes().List()
|
||||
minions, err := c.Nodes().List(labels.Everything())
|
||||
expectNoError(err)
|
||||
minionCount = len(minions.Items)
|
||||
Expect(minionCount).NotTo(BeZero())
|
||||
|
@ -163,7 +163,7 @@ func ClusterLevelLoggingWithElasticsearch(c *client.Client) {
|
||||
}
|
||||
|
||||
// Obtain a list of nodes so we can place one synthetic logger on each node.
|
||||
nodes, err := c.Nodes().List()
|
||||
nodes, err := c.Nodes().List(labels.Everything())
|
||||
if err != nil {
|
||||
Failf("Failed to list nodes: %v", err)
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ func expectedServicesExist(c *client.Client) error {
|
||||
}
|
||||
|
||||
func getAllNodesInCluster(c *client.Client) ([]string, error) {
|
||||
nodeList, err := c.Nodes().List()
|
||||
nodeList, err := c.Nodes().List(labels.Everything())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
@ -159,7 +160,7 @@ var _ = Describe("Networking", func() {
|
||||
|
||||
By("Creating a webserver (pending) pod on each node")
|
||||
|
||||
nodes, err := c.Nodes().List()
|
||||
nodes, err := c.Nodes().List(labels.Everything())
|
||||
if err != nil {
|
||||
Failf("Failed to list nodes: %v", err)
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
@ -45,7 +46,7 @@ var _ = Describe("PD", func() {
|
||||
|
||||
podClient = c.Pods(api.NamespaceDefault)
|
||||
|
||||
nodes, err := c.Nodes().List()
|
||||
nodes, err := c.Nodes().List(labels.Everything())
|
||||
expectNoError(err, "Failed to list nodes for e2e cluster.")
|
||||
Expect(len(nodes.Items) >= 2).To(BeTrue())
|
||||
|
||||
|
@ -35,6 +35,7 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
@ -87,7 +88,7 @@ func main() {
|
||||
|
||||
var nodes *api.NodeList
|
||||
for start := time.Now(); time.Since(start) < nodeListTimeout; time.Sleep(2 * time.Second) {
|
||||
nodes, err = c.Nodes().List()
|
||||
nodes, err = c.Nodes().List(labels.Everything())
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user