@@ -86,6 +86,71 @@ var _ = Describe("Updater", func() {
8686 Expect ((obj .Object ["status" ].(map [string ]interface {}))["conditions" ]).To (HaveLen (1 ))
8787 Expect (obj .GetResourceVersion ()).NotTo (Equal (resourceVersion ))
8888 })
89+
90+ It ("should support a mix of standard and custom status updates" , func () {
91+ u .UpdateStatus (EnsureCondition (conditions .Deployed (corev1 .ConditionTrue , "" , "" )))
92+ u .UpdateStatusCustom (func (uSt * unstructured.Unstructured ) bool {
93+ Expect (unstructured .SetNestedMap (uSt .Object , map [string ]interface {}{"bar" : "baz" }, "foo" )).To (Succeed ())
94+ return true
95+ })
96+ u .UpdateStatus (EnsureCondition (conditions .Irreconcilable (corev1 .ConditionFalse , "" , "" )))
97+ u .UpdateStatusCustom (func (uSt * unstructured.Unstructured ) bool {
98+ Expect (unstructured .SetNestedField (uSt .Object , "quux" , "foo" , "qux" )).To (Succeed ())
99+ return true
100+ })
101+ u .UpdateStatus (EnsureCondition (conditions .Initialized (corev1 .ConditionTrue , "" , "" )))
102+
103+ Expect (u .Apply (context .TODO (), obj )).To (Succeed ())
104+ Expect (client .Get (context .TODO (), types.NamespacedName {Namespace : "testNamespace" , Name : "testDeployment" }, obj )).To (Succeed ())
105+ Expect ((obj .Object ["status" ].(map [string ]interface {}))["conditions" ]).To (HaveLen (3 ))
106+ _ , found , err := unstructured .NestedFieldNoCopy (obj .Object , "status" , "deployedRelease" )
107+ Expect (found ).To (BeFalse ())
108+ Expect (err ).To (Not (HaveOccurred ()))
109+
110+ val , found , err := unstructured .NestedString (obj .Object , "status" , "foo" , "bar" )
111+ Expect (val ).To (Equal ("baz" ))
112+ Expect (found ).To (BeTrue ())
113+ Expect (err ).To (Not (HaveOccurred ()))
114+
115+ val , found , err = unstructured .NestedString (obj .Object , "status" , "foo" , "qux" )
116+ Expect (val ).To (Equal ("quux" ))
117+ Expect (found ).To (BeTrue ())
118+ Expect (err ).To (Not (HaveOccurred ()))
119+ })
120+
121+ It ("should preserve any custom status across multiple apply calls" , func () {
122+ u .UpdateStatusCustom (func (uSt * unstructured.Unstructured ) bool {
123+ Expect (unstructured .SetNestedMap (uSt .Object , map [string ]interface {}{"bar" : "baz" }, "foo" )).To (Succeed ())
124+ return true
125+ })
126+ Expect (u .Apply (context .TODO (), obj )).To (Succeed ())
127+
128+ Expect (client .Get (context .TODO (), types.NamespacedName {Namespace : "testNamespace" , Name : "testDeployment" }, obj )).To (Succeed ())
129+
130+ _ , found , err := unstructured .NestedFieldNoCopy (obj .Object , "status" , "deployedRelease" )
131+ Expect (found ).To (BeFalse ())
132+ Expect (err ).To (Not (HaveOccurred ()))
133+
134+ val , found , err := unstructured .NestedString (obj .Object , "status" , "foo" , "bar" )
135+ Expect (val ).To (Equal ("baz" ))
136+ Expect (found ).To (BeTrue ())
137+ Expect (err ).To (Succeed ())
138+
139+ u .UpdateStatus (EnsureCondition (conditions .Deployed (corev1 .ConditionTrue , "" , "" )))
140+ Expect (u .Apply (context .TODO (), obj )).To (Succeed ())
141+
142+ Expect (client .Get (context .TODO (), types.NamespacedName {Namespace : "testNamespace" , Name : "testDeployment" }, obj )).To (Succeed ())
143+ Expect ((obj .Object ["status" ].(map [string ]interface {}))["conditions" ]).To (HaveLen (1 ))
144+
145+ _ , found , err = unstructured .NestedFieldNoCopy (obj .Object , "status" , "deployedRelease" )
146+ Expect (found ).To (BeFalse ())
147+ Expect (err ).To (Not (HaveOccurred ()))
148+
149+ val , found , err = unstructured .NestedString (obj .Object , "status" , "foo" , "bar" )
150+ Expect (val ).To (Equal ("baz" ))
151+ Expect (found ).To (BeTrue ())
152+ Expect (err ).To (Succeed ())
153+ })
89154 })
90155})
91156
@@ -241,8 +306,9 @@ var _ = Describe("statusFor", func() {
241306 })
242307
243308 It ("should handle map[string]interface{}" , func () {
244- obj .Object ["status" ] = map [string ]interface {}{}
245- Expect (statusFor (obj )).To (Equal (& helmAppStatus {}))
309+ uSt := map [string ]interface {}{}
310+ obj .Object ["status" ] = uSt
311+ Expect (statusFor (obj )).To (Equal (& helmAppStatus {StatusObject : uSt }))
246312 })
247313
248314 It ("should handle arbitrary types" , func () {
0 commit comments