mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-13 21:25:09 +00:00
Merge pull request #7067 from ravigadde/master
Added field selector for listing pods
This commit is contained in:
@@ -35,14 +35,14 @@ import (
|
||||
)
|
||||
|
||||
// Convenient wrapper around listing pods supporting retries.
|
||||
func listPods(c *client.Client, namespace string, label labels.Selector) (*api.PodList, error) {
|
||||
func listPods(c *client.Client, namespace string, label labels.Selector, field fields.Selector) (*api.PodList, error) {
|
||||
maxRetries := 4
|
||||
pods, err := c.Pods(namespace).List(label)
|
||||
pods, err := c.Pods(namespace).List(label, field)
|
||||
for i := 0; i < maxRetries; i++ {
|
||||
if err == nil {
|
||||
return pods, nil
|
||||
}
|
||||
pods, err = c.Pods(namespace).List(label)
|
||||
pods, err = c.Pods(namespace).List(label, field)
|
||||
}
|
||||
return pods, err
|
||||
}
|
||||
@@ -127,7 +127,7 @@ func RunRC(c *client.Client, name string, ns, image string, replicas int) {
|
||||
|
||||
By(fmt.Sprintf("Making sure all %d replicas exist", replicas))
|
||||
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": name}))
|
||||
pods, err := listPods(c, ns, label)
|
||||
pods, err := listPods(c, ns, label, fields.Everything())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
current = len(pods.Items)
|
||||
failCount := 5
|
||||
@@ -147,7 +147,7 @@ func RunRC(c *client.Client, name string, ns, image string, replicas int) {
|
||||
|
||||
last = current
|
||||
time.Sleep(5 * time.Second)
|
||||
pods, err = listPods(c, ns, label)
|
||||
pods, err = listPods(c, ns, label, fields.Everything())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
current = len(pods.Items)
|
||||
}
|
||||
@@ -166,7 +166,7 @@ func RunRC(c *client.Client, name string, ns, image string, replicas int) {
|
||||
unknown := 0
|
||||
time.Sleep(10 * time.Second)
|
||||
|
||||
currentPods, listErr := listPods(c, ns, label)
|
||||
currentPods, listErr := listPods(c, ns, label, fields.Everything())
|
||||
Expect(listErr).NotTo(HaveOccurred())
|
||||
if len(currentPods.Items) != len(pods.Items) {
|
||||
Failf("Number of reported pods changed: %d vs %d", len(currentPods.Items), len(pods.Items))
|
||||
|
@@ -83,7 +83,7 @@ func ClusterLevelLoggingWithElasticsearch(c *client.Client) {
|
||||
// Wait for the Elasticsearch pods to enter the running state.
|
||||
By("Checking to make sure the Elasticsearch pods are running")
|
||||
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": "elasticsearch-logging"}))
|
||||
pods, err := c.Pods(api.NamespaceDefault).List(label)
|
||||
pods, err := c.Pods(api.NamespaceDefault).List(label, fields.Everything())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
for _, pod := range pods.Items {
|
||||
err = waitForPodRunning(c, pod.Name)
|
||||
|
@@ -78,7 +78,7 @@ var _ = Describe("Events", func() {
|
||||
expectNoError(waitForPodRunning(c, pod.Name))
|
||||
|
||||
By("verifying the pod is in kubernetes")
|
||||
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
|
||||
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})), fields.Everything())
|
||||
Expect(len(pods.Items)).To(Equal(1))
|
||||
|
||||
By("retrieving the pod")
|
||||
|
@@ -86,7 +86,7 @@ func verifyExpectedRcsExistAndGetExpectedPods(c *client.Client) ([]string, error
|
||||
return nil, fmt.Errorf("expected to find only one replica for rc %q, found %d", rc.Name, rc.Status.Replicas)
|
||||
}
|
||||
expectedRcs[rc.Name] = true
|
||||
podList, err := c.Pods(api.NamespaceDefault).List(labels.Set(rc.Spec.Selector).AsSelector())
|
||||
podList, err := c.Pods(api.NamespaceDefault).List(labels.Set(rc.Spec.Selector).AsSelector(), fields.Everything())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -174,7 +174,7 @@ var _ = Describe("Pods", func() {
|
||||
}
|
||||
|
||||
By("setting up watch")
|
||||
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
|
||||
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})), fields.Everything())
|
||||
if err != nil {
|
||||
Fail(fmt.Sprintf("Failed to query for pods: %v", err))
|
||||
}
|
||||
@@ -196,7 +196,7 @@ var _ = Describe("Pods", func() {
|
||||
}
|
||||
|
||||
By("verifying the pod is in kubernetes")
|
||||
pods, err = podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
|
||||
pods, err = podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})), fields.Everything())
|
||||
if err != nil {
|
||||
Fail(fmt.Sprintf("Failed to query for pods: %v", err))
|
||||
}
|
||||
@@ -214,7 +214,7 @@ var _ = Describe("Pods", func() {
|
||||
|
||||
By("deleting the pod")
|
||||
podClient.Delete(pod.Name)
|
||||
pods, err = podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
|
||||
pods, err = podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})), fields.Everything())
|
||||
if err != nil {
|
||||
Fail(fmt.Sprintf("Failed to delete pod: %v", err))
|
||||
}
|
||||
@@ -286,7 +286,7 @@ var _ = Describe("Pods", func() {
|
||||
expectNoError(waitForPodRunning(c, pod.Name))
|
||||
|
||||
By("verifying the pod is in kubernetes")
|
||||
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
|
||||
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})), fields.Everything())
|
||||
Expect(len(pods.Items)).To(Equal(1))
|
||||
|
||||
By("retrieving the pod")
|
||||
@@ -309,7 +309,7 @@ var _ = Describe("Pods", func() {
|
||||
expectNoError(waitForPodRunning(c, pod.Name))
|
||||
|
||||
By("verifying the updated pod is in kubernetes")
|
||||
pods, err = podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
|
||||
pods, err = podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})), fields.Everything())
|
||||
Expect(len(pods.Items)).To(Equal(1))
|
||||
fmt.Println("pod update OK")
|
||||
})
|
||||
|
@@ -22,6 +22,7 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||
@@ -110,7 +111,7 @@ func ServeImageOrFail(c *client.Client, test string, image string) {
|
||||
// List the pods, making sure we observe all the replicas.
|
||||
listTimeout := time.Minute
|
||||
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": name}))
|
||||
pods, err := c.Pods(ns).List(label)
|
||||
pods, err := c.Pods(ns).List(label, fields.Everything())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
t := time.Now()
|
||||
for {
|
||||
@@ -123,7 +124,7 @@ func ServeImageOrFail(c *client.Client, test string, image string) {
|
||||
name, replicas, len(pods.Items), time.Since(t).Seconds())
|
||||
}
|
||||
time.Sleep(5 * time.Second)
|
||||
pods, err = c.Pods(ns).List(label)
|
||||
pods, err = c.Pods(ns).List(label, fields.Everything())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
@@ -165,7 +166,7 @@ type responseChecker struct {
|
||||
|
||||
func (r responseChecker) checkAllResponses() (done bool, err error) {
|
||||
successes := 0
|
||||
currentPods, err := r.c.Pods(r.ns).List(r.label)
|
||||
currentPods, err := r.c.Pods(r.ns).List(r.label, fields.Everything())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
for i, pod := range r.pods.Items {
|
||||
// Check that the replica list remains unchanged, otherwise we have problems.
|
||||
|
@@ -56,7 +56,7 @@ func TestClient(t *testing.T) {
|
||||
t.Errorf("expected %#v, got %#v", e, a)
|
||||
}
|
||||
|
||||
pods, err := client.Pods(ns).List(labels.Everything())
|
||||
pods, err := client.Pods(ns).List(labels.Everything(), fields.Everything())
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -94,7 +94,7 @@ func TestClient(t *testing.T) {
|
||||
}
|
||||
|
||||
// pod is shown, but not scheduled
|
||||
pods, err = client.Pods(ns).List(labels.Everything())
|
||||
pods, err = client.Pods(ns).List(labels.Everything(), fields.Everything())
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
@@ -28,6 +28,7 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/golang/glog"
|
||||
"github.com/golang/protobuf/proto"
|
||||
@@ -111,7 +112,7 @@ func TestApiserverMetrics(t *testing.T) {
|
||||
// Make a request to the apiserver to ensure there's at least one data point
|
||||
// for the metrics we're expecting -- otherwise, they won't be exported.
|
||||
client := client.NewOrDie(&client.Config{Host: s.URL, Version: testapi.Version()})
|
||||
if _, err := client.Pods(api.NamespaceDefault).List(labels.Everything()); err != nil {
|
||||
if _, err := client.Pods(api.NamespaceDefault).List(labels.Everything(), fields.Everything()); err != nil {
|
||||
t.Fatalf("unexpected error getting pods: %v", err)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user