Skip to content

Commit 839d5aa

Browse files
liyinan926JoelSpeed
authored andcommitted
Populate GVK for listed objects
1 parent 8c0b805 commit 839d5aa

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pkg/cache/cache_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,19 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
198198
}
199199
})
200200

201+
It("should be able to list objects with GVK populated", func() {
202+
By("listing pods")
203+
listObj := &kcorev1.PodList{}
204+
Expect(informerCache.List(context.Background(), listObj)).To(Succeed())
205+
206+
By("verifying that the returned pods have GVK populated")
207+
Expect(listObj.Items).NotTo(BeEmpty())
208+
Expect(listObj.Items).Should(HaveLen(3))
209+
for _, p := range listObj.Items {
210+
Expect(p.GroupVersionKind().Empty()).To(BeFalse())
211+
}
212+
})
213+
201214
It("should be able to list objects by namespace", func() {
202215
By("listing pods in test-namespace-1")
203216
listObj := &kcorev1.PodList{}

pkg/cache/internal/cache_reader.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func (c *CacheReader) List(_ context.Context, out runtime.Object, opts ...client
125125
if !isObj {
126126
return fmt.Errorf("cache contained %T, which is not an Object", obj)
127127
}
128+
obj.GetObjectKind().SetGroupVersionKind(c.groupVersionKind)
128129
runtimeObjs = append(runtimeObjs, obj)
129130
}
130131
filteredItems, err := objectutil.FilterWithLabels(runtimeObjs, labelSel)

0 commit comments

Comments
 (0)