@@ -28,6 +28,7 @@ import (
28
28
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29
29
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
30
30
"k8s.io/apimachinery/pkg/runtime"
31
+ "k8s.io/apimachinery/pkg/runtime/schema"
31
32
"sigs.k8s.io/controller-runtime/pkg/client"
32
33
33
34
kscheme "k8s.io/client-go/kubernetes/scheme"
@@ -527,23 +528,28 @@ var _ = Describe("Client", func() {
527
528
dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
528
529
Expect (err ).NotTo (HaveOccurred ())
529
530
530
- By ("encoding the Deployment as unstructured" )
531
- var u runtime.Unstructured = & unstructured.Unstructured {}
532
- scheme .Convert (dep , u , nil )
533
-
534
531
cl , err := client .New (cfg , client.Options {})
535
532
Expect (err ).NotTo (HaveOccurred ())
536
533
Expect (cl ).NotTo (BeNil ())
537
534
535
+ By ("encoding the Deployment as unstructured" )
536
+ var u runtime.Unstructured = & unstructured.Unstructured {}
537
+ scheme .Convert (dep , u , nil )
538
+
538
539
By ("fetching the created Deployment" )
539
- var actual appsv1.Deployment
540
+ var actual unstructured.Unstructured
541
+ actual .SetGroupVersionKind (schema.GroupVersionKind {
542
+ Group : "apps" ,
543
+ Kind : "Deployment" ,
544
+ Version : "v1" ,
545
+ })
540
546
key := client.ObjectKey {Namespace : ns , Name : dep .Name }
541
547
err = cl .Get (context .TODO (), key , & actual )
542
548
Expect (err ).NotTo (HaveOccurred ())
543
549
Expect (actual ).NotTo (BeNil ())
544
550
545
551
By ("validating the fetched Deployment equals the created one" )
546
- Expect (dep ).To (Equal (& actual ))
552
+ Expect (u ).To (Equal (& actual ))
547
553
548
554
close (done )
549
555
})
@@ -583,14 +589,19 @@ var _ = Describe("Client", func() {
583
589
Expect (cl ).NotTo (BeNil ())
584
590
585
591
By ("fetching the created Node" )
586
- var actual corev1.Node
592
+ var actual unstructured.Unstructured
593
+ actual .SetGroupVersionKind (schema.GroupVersionKind {
594
+ Group : "" ,
595
+ Kind : "Node" ,
596
+ Version : "v1" ,
597
+ })
587
598
key := client.ObjectKey {Namespace : ns , Name : node .Name }
588
599
err = cl .Get (context .TODO (), key , & actual )
589
600
Expect (err ).NotTo (HaveOccurred ())
590
601
Expect (actual ).NotTo (BeNil ())
591
602
592
603
By ("validating the fetched Node equals the created one" )
593
- Expect (node ).To (Equal (& actual ))
604
+ Expect (u ).To (Equal (& actual ))
594
605
595
606
close (done )
596
607
})
@@ -663,6 +674,38 @@ var _ = Describe("Client", func() {
663
674
close (done )
664
675
}, serverSideTimeoutSeconds )
665
676
677
+ It ("should fetch unstructured collection of objects" , func (done Done ) {
678
+ By ("create an initial object" )
679
+ _ , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
680
+ Expect (err ).NotTo (HaveOccurred ())
681
+
682
+ cl , err := client .New (cfg , client.Options {})
683
+ Expect (err ).NotTo (HaveOccurred ())
684
+
685
+ By ("listing all objects of that type in the cluster" )
686
+ deps := & unstructured.UnstructuredList {}
687
+ deps .SetGroupVersionKind (schema.GroupVersionKind {
688
+ Group : "apps" ,
689
+ Kind : "DeploymentList" ,
690
+ Version : "v1" ,
691
+ })
692
+ err = cl .List (context .Background (), nil , deps )
693
+ Expect (err ).NotTo (HaveOccurred ())
694
+
695
+ Expect (deps .Items ).NotTo (BeEmpty ())
696
+ hasDep := false
697
+ for _ , item := range deps .Items {
698
+ if item .GetName () == dep .Name && item .GetNamespace () == dep .Namespace {
699
+ fmt .Printf ("HERE!!!!!!!! ITEM: %v\n \n " , item )
700
+ hasDep = true
701
+ fmt .Printf ("HERE hasDep: %v\n \n " , hasDep )
702
+ break
703
+ }
704
+ }
705
+ Expect (hasDep ).To (BeTrue ())
706
+ close (done )
707
+ }, serverSideTimeoutSeconds )
708
+
666
709
It ("should return an empty list if there are no matching objects" , func (done Done ) {
667
710
cl , err := client .New (cfg , client.Options {})
668
711
Expect (err ).NotTo (HaveOccurred ())
0 commit comments