@@ -25,7 +25,7 @@ import (
25
25
"strings"
26
26
"time"
27
27
28
- "k8s.io/api/core/v1"
28
+ v1 "k8s.io/api/core/v1"
29
29
policyv1beta1 "k8s.io/api/policy/v1beta1"
30
30
"k8s.io/apimachinery/pkg/api/errors"
31
31
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -109,6 +109,14 @@ type ServiceTestJig struct {
109
109
Labels map [string ]string
110
110
}
111
111
112
+ // PodNode is a pod-node pair indicating which node a given pod is running on
113
+ type PodNode struct {
114
+ // Pod represents pod name
115
+ Pod string
116
+ // Node represents node name
117
+ Node string
118
+ }
119
+
112
120
// NewServiceTestJig allocates and inits a new ServiceTestJig.
113
121
func NewServiceTestJig (client clientset.Interface , name string ) * ServiceTestJig {
114
122
j := & ServiceTestJig {}
@@ -348,6 +356,25 @@ func PickNodeIP(c clientset.Interface) string {
348
356
return ip
349
357
}
350
358
359
+ // PodNodePairs return PodNode pairs for all pods in a namespace
360
+ func PodNodePairs (c clientset.Interface , ns string ) ([]PodNode , error ) {
361
+ var result []PodNode
362
+
363
+ podList , err := c .CoreV1 ().Pods (ns ).List (metav1.ListOptions {})
364
+ if err != nil {
365
+ return result , err
366
+ }
367
+
368
+ for _ , pod := range podList .Items {
369
+ result = append (result , PodNode {
370
+ Pod : pod .Name ,
371
+ Node : pod .Spec .NodeName ,
372
+ })
373
+ }
374
+
375
+ return result , nil
376
+ }
377
+
351
378
// GetEndpointNodes returns a map of nodenames:external-ip on which the
352
379
// endpoints of the given Service are running.
353
380
func (j * ServiceTestJig ) GetEndpointNodes (svc * v1.Service ) map [string ][]string {
0 commit comments