Skip to content

Commit 9d37aab

Browse files
authored
Merge pull request #389 from pusher/list-gvk
🐛 Populate GVK for listed objects
2 parents 87136d9 + fc22506 commit 9d37aab

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
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+
out := &kcorev1.PodList{}
204+
Expect(informerCache.List(context.Background(), out)).To(Succeed())
205+
206+
By("verifying that the returned pods have GVK populated")
207+
Expect(out.Items).NotTo(BeEmpty())
208+
Expect(out.Items).Should(SatisfyAny(HaveLen(3), HaveLen(4)))
209+
for _, p := range out.Items {
210+
Expect(p.GroupVersionKind()).To(Equal(kcorev1.SchemeGroupVersion.WithKind("Pod")))
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ 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-
runtimeObjs = append(runtimeObjs, obj)
128+
outObj := obj.DeepCopyObject()
129+
outObj.GetObjectKind().SetGroupVersionKind(c.groupVersionKind)
130+
runtimeObjs = append(runtimeObjs, outObj)
129131
}
130132
filteredItems, err := objectutil.FilterWithLabels(runtimeObjs, labelSel)
131133
if err != nil {

0 commit comments

Comments
 (0)