@@ -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"
@@ -642,23 +643,28 @@ var _ = Describe("Client", func() {
642
643
dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
643
644
Expect (err ).NotTo (HaveOccurred ())
644
645
645
- By ("encoding the Deployment as unstructured" )
646
- var u runtime.Unstructured = & unstructured.Unstructured {}
647
- scheme .Convert (dep , u , nil )
648
-
649
646
cl , err := client .New (cfg , client.Options {})
650
647
Expect (err ).NotTo (HaveOccurred ())
651
648
Expect (cl ).NotTo (BeNil ())
652
649
650
+ By ("encoding the Deployment as unstructured" )
651
+ var u runtime.Unstructured = & unstructured.Unstructured {}
652
+ scheme .Convert (dep , u , nil )
653
+
653
654
By ("fetching the created Deployment" )
654
- var actual appsv1.Deployment
655
+ var actual unstructured.Unstructured
656
+ actual .SetGroupVersionKind (schema.GroupVersionKind {
657
+ Group : "apps" ,
658
+ Kind : "Deployment" ,
659
+ Version : "v1" ,
660
+ })
655
661
key := client.ObjectKey {Namespace : ns , Name : dep .Name }
656
662
err = cl .Get (context .TODO (), key , & actual )
657
663
Expect (err ).NotTo (HaveOccurred ())
658
664
Expect (actual ).NotTo (BeNil ())
659
665
660
666
By ("validating the fetched Deployment equals the created one" )
661
- Expect (dep ).To (Equal (& actual ))
667
+ Expect (u ).To (Equal (& actual ))
662
668
663
669
close (done )
664
670
})
@@ -698,14 +704,19 @@ var _ = Describe("Client", func() {
698
704
Expect (cl ).NotTo (BeNil ())
699
705
700
706
By ("fetching the created Node" )
701
- var actual corev1.Node
707
+ var actual unstructured.Unstructured
708
+ actual .SetGroupVersionKind (schema.GroupVersionKind {
709
+ Group : "" ,
710
+ Kind : "Node" ,
711
+ Version : "v1" ,
712
+ })
702
713
key := client.ObjectKey {Namespace : ns , Name : node .Name }
703
714
err = cl .Get (context .TODO (), key , & actual )
704
715
Expect (err ).NotTo (HaveOccurred ())
705
716
Expect (actual ).NotTo (BeNil ())
706
717
707
718
By ("validating the fetched Node equals the created one" )
708
- Expect (node ).To (Equal (& actual ))
719
+ Expect (u ).To (Equal (& actual ))
709
720
710
721
close (done )
711
722
})
@@ -778,6 +789,38 @@ var _ = Describe("Client", func() {
778
789
close (done )
779
790
}, serverSideTimeoutSeconds )
780
791
792
+ It ("should fetch unstructured collection of objects" , func (done Done ) {
793
+ By ("create an initial object" )
794
+ _ , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
795
+ Expect (err ).NotTo (HaveOccurred ())
796
+
797
+ cl , err := client .New (cfg , client.Options {})
798
+ Expect (err ).NotTo (HaveOccurred ())
799
+
800
+ By ("listing all objects of that type in the cluster" )
801
+ deps := & unstructured.UnstructuredList {}
802
+ deps .SetGroupVersionKind (schema.GroupVersionKind {
803
+ Group : "apps" ,
804
+ Kind : "DeploymentList" ,
805
+ Version : "v1" ,
806
+ })
807
+ err = cl .List (context .Background (), nil , deps )
808
+ Expect (err ).NotTo (HaveOccurred ())
809
+
810
+ Expect (deps .Items ).NotTo (BeEmpty ())
811
+ hasDep := false
812
+ for _ , item := range deps .Items {
813
+ if item .GetName () == dep .Name && item .GetNamespace () == dep .Namespace {
814
+ fmt .Printf ("HERE!!!!!!!! ITEM: %v\n \n " , item )
815
+ hasDep = true
816
+ fmt .Printf ("HERE hasDep: %v\n \n " , hasDep )
817
+ break
818
+ }
819
+ }
820
+ Expect (hasDep ).To (BeTrue ())
821
+ close (done )
822
+ }, serverSideTimeoutSeconds )
823
+
781
824
It ("should return an empty list if there are no matching objects" , func (done Done ) {
782
825
cl , err := client .New (cfg , client.Options {})
783
826
Expect (err ).NotTo (HaveOccurred ())
0 commit comments