@@ -109,6 +109,7 @@ var _ = Describe("Informer Cache", func() {
109
109
})
110
110
111
111
Describe ("as a Reader" , func () {
112
+
112
113
It ("should be able to list objects that haven't been watched previously" , func () {
113
114
By ("listing all services in the cluster" )
114
115
listObj := & kcorev1.ServiceList {}
@@ -138,9 +139,9 @@ var _ = Describe("Informer Cache", func() {
138
139
Expect (svc .Namespace ).To (Equal ("default" ))
139
140
})
140
141
141
- It ("should support filtering by labels" , func () {
142
+ It ("should support filtering by labels in a single namespace " , func () {
142
143
By ("listing pods with a particular label" )
143
- // NB: each pod has a "test-label" equal to the pod name
144
+ // NB: each pod has a "test-label": < pod- name>
144
145
out := kcorev1.PodList {}
145
146
Expect (informerCache .List (context .Background (), client .InNamespace (testNamespaceTwo ).
146
147
MatchingLabels (map [string ]string {"test-label" : "test-pod-2" }), & out )).To (Succeed ())
@@ -152,6 +153,27 @@ var _ = Describe("Informer Cache", func() {
152
153
Expect (actual .Labels ["test-label" ]).To (Equal ("test-pod-2" ))
153
154
})
154
155
156
+ It ("should support filtering by labels from multiple namespaces" , func () {
157
+ By ("creating another pod with the same label but different namespace" )
158
+ anotherPod := createPod ("test-pod-2" , testNamespaceOne , kcorev1 .RestartPolicyAlways )
159
+
160
+ By ("listing pods with a particular label" )
161
+ // NB: each pod has a "test-label": <pod-name>
162
+ out := kcorev1.PodList {}
163
+ labels := map [string ]string {"test-label" : "test-pod-2" }
164
+ Expect (informerCache .List (context .Background (),
165
+ client .MatchingLabels (labels ), & out )).To (Succeed ())
166
+
167
+ By ("verifying multiple pods with the same label in different namespaces are returned" )
168
+ Expect (out .Items ).NotTo (BeEmpty ())
169
+ Expect (out .Items ).Should (HaveLen (2 ))
170
+ for _ , actual := range out .Items {
171
+ Expect (actual .Labels ["test-label" ]).To (Equal ("test-pod-2" ))
172
+ }
173
+
174
+ deletePod (anotherPod )
175
+ })
176
+
155
177
It ("should be able to list objects by namespace" , func () {
156
178
By ("listing pods in test-namespace-1" )
157
179
listObj := & kcorev1.PodList {}
@@ -195,6 +217,7 @@ var _ = Describe("Informer Cache", func() {
195
217
})
196
218
197
219
Describe ("as an Informer" , func () {
220
+
198
221
It ("should be able to get informer for the object" , func (done Done ) {
199
222
By ("getting a shared index informer for a pod" )
200
223
pod := & kcorev1.Pod {
0 commit comments