Skip to content

Commit

Permalink
Merge pull request #389 from pusher/list-gvk
Browse files Browse the repository at this point in the history
🐛 Populate GVK for listed objects
  • Loading branch information
k8s-ci-robot authored May 15, 2019
2 parents 87136d9 + fc22506 commit 9d37aab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,19 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
}
})

It("should be able to list objects with GVK populated", func() {
By("listing pods")
out := &kcorev1.PodList{}
Expect(informerCache.List(context.Background(), out)).To(Succeed())

By("verifying that the returned pods have GVK populated")
Expect(out.Items).NotTo(BeEmpty())
Expect(out.Items).Should(SatisfyAny(HaveLen(3), HaveLen(4)))
for _, p := range out.Items {
Expect(p.GroupVersionKind()).To(Equal(kcorev1.SchemeGroupVersion.WithKind("Pod")))
}
})

It("should be able to list objects by namespace", func() {
By("listing pods in test-namespace-1")
listObj := &kcorev1.PodList{}
Expand Down
4 changes: 3 additions & 1 deletion pkg/cache/internal/cache_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ func (c *CacheReader) List(_ context.Context, out runtime.Object, opts ...client
if !isObj {
return fmt.Errorf("cache contained %T, which is not an Object", obj)
}
runtimeObjs = append(runtimeObjs, obj)
outObj := obj.DeepCopyObject()
outObj.GetObjectKind().SetGroupVersionKind(c.groupVersionKind)
runtimeObjs = append(runtimeObjs, outObj)
}
filteredItems, err := objectutil.FilterWithLabels(runtimeObjs, labelSel)
if err != nil {
Expand Down

0 comments on commit 9d37aab

Please sign in to comment.