@@ -1810,6 +1810,57 @@ var _ = Describe("Fake client", func() {
1810
1810
Expect (cmp .Diff (objOriginal , actual )).To (BeEmpty ())
1811
1811
})
1812
1812
1813
+ It ("should Unmarshal the schemaless object with int64 to preserve ints" , func () {
1814
+ schemeBuilder := & scheme.Builder {GroupVersion : schema.GroupVersion {Group : "test" , Version : "v1" }}
1815
+ schemeBuilder .Register (& WithSchemalessSpec {}, & WithSchemalessSpecList {})
1816
+
1817
+ scheme := runtime .NewScheme ()
1818
+ Expect (schemeBuilder .AddToScheme (scheme )).NotTo (HaveOccurred ())
1819
+
1820
+ spec := Schemaless {
1821
+ "key" : int64 (1 ),
1822
+ }
1823
+
1824
+ obj := & WithSchemalessSpec {
1825
+ ObjectMeta : metav1.ObjectMeta {
1826
+ Name : "a-foo" ,
1827
+ },
1828
+ Spec : spec ,
1829
+ }
1830
+ cl := NewClientBuilder ().WithScheme (scheme ).WithStatusSubresource (obj ).WithObjects (obj ).Build ()
1831
+
1832
+ Expect (cl .Update (context .Background (), obj )).To (Succeed ())
1833
+ Expect (cl .Get (context .Background (), client .ObjectKeyFromObject (obj ), obj )).To (Succeed ())
1834
+
1835
+ Expect (obj .Spec ).To (BeEquivalentTo (spec ))
1836
+ })
1837
+
1838
+ It ("should Unmarshal the schemaless object with float64 to preserve ints" , func () {
1839
+ schemeBuilder := & scheme.Builder {GroupVersion : schema.GroupVersion {Group : "test" , Version : "v1" }}
1840
+ schemeBuilder .Register (& WithSchemalessSpec {}, & WithSchemalessSpecList {})
1841
+
1842
+ scheme := runtime .NewScheme ()
1843
+ Expect (schemeBuilder .AddToScheme (scheme )).NotTo (HaveOccurred ())
1844
+
1845
+ spec := Schemaless {
1846
+ "key" : 1.1 ,
1847
+ }
1848
+
1849
+ obj := & WithSchemalessSpec {
1850
+
1851
+ ObjectMeta : metav1.ObjectMeta {
1852
+ Name : "a-foo" ,
1853
+ },
1854
+ Spec : spec ,
1855
+ }
1856
+ cl := NewClientBuilder ().WithScheme (scheme ).WithStatusSubresource (obj ).WithObjects (obj ).Build ()
1857
+
1858
+ Expect (cl .Update (context .Background (), obj )).To (Succeed ())
1859
+ Expect (cl .Get (context .Background (), client .ObjectKeyFromObject (obj ), obj )).To (Succeed ())
1860
+
1861
+ Expect (obj .Spec ).To (BeEquivalentTo (spec ))
1862
+ })
1863
+
1813
1864
It ("should not change the status of unstructured objects that are configured to have a status subresource on update" , func () {
1814
1865
obj := & unstructured.Unstructured {}
1815
1866
obj .SetAPIVersion ("foo/v1" )
@@ -2695,6 +2746,81 @@ var _ = Describe("Fake client", func() {
2695
2746
}
2696
2747
})
2697
2748
2749
+ type WithSchemalessSpecList struct {
2750
+ * metav1.ListMeta
2751
+ * metav1.TypeMeta
2752
+ Items []* WithPointerMeta
2753
+ }
2754
+
2755
+ func (t * WithSchemalessSpecList ) DeepCopy () * WithSchemalessSpecList {
2756
+ l := & WithSchemalessSpecList {
2757
+ ListMeta : t .ListMeta .DeepCopy (),
2758
+ }
2759
+ if t .TypeMeta != nil {
2760
+ l .TypeMeta = & metav1.TypeMeta {
2761
+
2762
+ APIVersion : t .APIVersion ,
2763
+
2764
+ Kind : t .Kind ,
2765
+ }
2766
+ }
2767
+ for _ , item := range t .Items {
2768
+ l .Items = append (l .Items , item .DeepCopy ())
2769
+ }
2770
+
2771
+ return l
2772
+ }
2773
+
2774
+ func (t * WithSchemalessSpecList ) DeepCopyObject () runtime.Object {
2775
+ return t .DeepCopy ()
2776
+ }
2777
+
2778
+ type Schemaless map [string ]interface {}
2779
+
2780
+ type WithSchemalessSpec struct {
2781
+ metav1.TypeMeta `json:",inline"`
2782
+ metav1.ObjectMeta `json:"metadata,omitempty"`
2783
+
2784
+ Spec Schemaless `json:"spec,omitempty"`
2785
+ }
2786
+
2787
+ func (t * WithSchemalessSpec ) DeepCopy () * WithSchemalessSpec {
2788
+ w := & WithSchemalessSpec {
2789
+ ObjectMeta : * t .ObjectMeta .DeepCopy (),
2790
+ }
2791
+ w .TypeMeta = metav1.TypeMeta {
2792
+ APIVersion : t .APIVersion ,
2793
+ Kind : t .Kind ,
2794
+ }
2795
+ t .Spec .DeepCopyInto (& w .Spec )
2796
+
2797
+ return w
2798
+ }
2799
+
2800
+ func (t * WithSchemalessSpec ) DeepCopyObject () runtime.Object {
2801
+ return t .DeepCopy ()
2802
+ }
2803
+
2804
+ // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
2805
+ func (in * Schemaless ) DeepCopyInto (out * Schemaless ) {
2806
+ if * in != nil {
2807
+ * out = make (Schemaless , len (* in ))
2808
+ for key := range * in {
2809
+ (* out )[key ] = (* in )[key ]
2810
+ }
2811
+ }
2812
+ }
2813
+
2814
+ // DeepCopy copies the receiver, creating a new Schemaless.
2815
+ func (in * Schemaless ) DeepCopy () * Schemaless {
2816
+ if in == nil {
2817
+ return nil
2818
+ }
2819
+ out := new (Schemaless )
2820
+ in .DeepCopyInto (out )
2821
+ return out
2822
+ }
2823
+
2698
2824
type WithPointerMetaList struct {
2699
2825
* metav1.ListMeta
2700
2826
* metav1.TypeMeta
0 commit comments