@@ -827,6 +827,57 @@ var _ = Describe("Client", func() {
827
827
close (done )
828
828
})
829
829
830
+ It ("should update status and preserve type information" , func (done Done ) {
831
+ cl , err := client .New (cfg , client.Options {})
832
+ Expect (err ).NotTo (HaveOccurred ())
833
+ Expect (cl ).NotTo (BeNil ())
834
+
835
+ By ("initially creating a Deployment" )
836
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
837
+ Expect (err ).NotTo (HaveOccurred ())
838
+
839
+ By ("updating the status of Deployment" )
840
+ u := & unstructured.Unstructured {}
841
+ dep .Status .Replicas = 1
842
+ Expect (scheme .Convert (dep , u , nil )).To (Succeed ())
843
+ err = cl .Status ().Update (context .TODO (), u )
844
+ Expect (err ).NotTo (HaveOccurred ())
845
+
846
+ By ("validating updated Deployment has type information" )
847
+ Expect (u .GroupVersionKind ()).To (Equal (depGvk ))
848
+
849
+ close (done )
850
+ })
851
+
852
+ It ("should patch status and preserve type information" , func (done Done ) {
853
+ cl , err := client .New (cfg , client.Options {})
854
+ Expect (err ).NotTo (HaveOccurred ())
855
+ Expect (cl ).NotTo (BeNil ())
856
+
857
+ By ("initially creating a Deployment" )
858
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
859
+ Expect (err ).NotTo (HaveOccurred ())
860
+
861
+ By ("patching the status of Deployment" )
862
+ u := & unstructured.Unstructured {}
863
+ depPatch := client .MergeFrom (dep .DeepCopy ())
864
+ dep .Status .Replicas = 1
865
+ Expect (scheme .Convert (dep , u , nil )).To (Succeed ())
866
+ err = cl .Status ().Patch (context .TODO (), u , depPatch )
867
+ Expect (err ).NotTo (HaveOccurred ())
868
+
869
+ By ("validating updated Deployment has type information" )
870
+ Expect (u .GroupVersionKind ()).To (Equal (depGvk ))
871
+
872
+ By ("validating patched Deployment has new status" )
873
+ actual , err := clientset .AppsV1 ().Deployments (ns ).Get (dep .Name , metav1.GetOptions {})
874
+ Expect (err ).NotTo (HaveOccurred ())
875
+ Expect (actual ).NotTo (BeNil ())
876
+ Expect (actual .Status .Replicas ).To (BeEquivalentTo (1 ))
877
+
878
+ close (done )
879
+ })
880
+
830
881
It ("should not update spec of an existing object" , func (done Done ) {
831
882
cl , err := client .New (cfg , client.Options {})
832
883
Expect (err ).NotTo (HaveOccurred ())
0 commit comments