Skip to content

Commit

Permalink
Merge pull request #1286 from vincepri/unstructured-list-bug
Browse files Browse the repository at this point in the history
🐛 client.List should check on UnstructuredList, not Unstructured
  • Loading branch information
k8s-ci-robot authored Dec 3, 2020
2 parents 7d38e25 + 5d44082 commit 8d52513
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (c *client) Get(ctx context.Context, key ObjectKey, obj runtime.Object) err
// List implements client.Client
func (c *client) List(ctx context.Context, obj runtime.Object, opts ...ListOption) error {
switch obj.(type) {
case *unstructured.Unstructured:
case *unstructured.UnstructuredList:
return c.unstructuredClient.List(ctx, obj, opts...)
case *metav1.PartialObjectMetadataList:
return c.metadataClient.List(ctx, obj, opts...)
Expand Down
30 changes: 30 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,36 @@ var _ = Describe("Client", func() {
close(done)
}, serverSideTimeoutSeconds)

It("should fetch unstructured collection of objects, even if scheme is empty", func(done Done) {
By("create an initial object")
_, err := clientset.AppsV1().Deployments(ns).Create(dep)
Expect(err).NotTo(HaveOccurred())

cl, err := client.New(cfg, client.Options{Scheme: runtime.NewScheme()})
Expect(err).NotTo(HaveOccurred())

By("listing all objects of that type in the cluster")
deps := &unstructured.UnstructuredList{}
deps.SetGroupVersionKind(schema.GroupVersionKind{
Group: "apps",
Kind: "DeploymentList",
Version: "v1",
})
err = cl.List(context.Background(), deps)
Expect(err).NotTo(HaveOccurred())

Expect(deps.Items).NotTo(BeEmpty())
hasDep := false
for _, item := range deps.Items {
if item.GetName() == dep.Name && item.GetNamespace() == dep.Namespace {
hasDep = true
break
}
}
Expect(hasDep).To(BeTrue())
close(done)
}, serverSideTimeoutSeconds)

It("should return an empty list if there are no matching objects", func(done Done) {
cl, err := client.New(cfg, client.Options{})
Expect(err).NotTo(HaveOccurred())
Expand Down

0 comments on commit 8d52513

Please sign in to comment.