@@ -108,6 +108,71 @@ var _ = Describe("Updater", func() {
108
108
Expect ((obj .Object ["status" ].(map [string ]interface {}))["conditions" ]).To (HaveLen (1 ))
109
109
Expect (obj .GetResourceVersion ()).NotTo (Equal (resourceVersion ))
110
110
})
111
+
112
+ It ("should support a mix of standard and custom status updates" , func () {
113
+ u .UpdateStatus (EnsureCondition (conditions .Deployed (corev1 .ConditionTrue , "" , "" )))
114
+ u .UpdateStatusCustom (func (uSt * unstructured.Unstructured ) bool {
115
+ Expect (unstructured .SetNestedMap (uSt .Object , map [string ]interface {}{"bar" : "baz" }, "foo" )).To (Succeed ())
116
+ return true
117
+ })
118
+ u .UpdateStatus (EnsureCondition (conditions .Irreconcilable (corev1 .ConditionFalse , "" , "" )))
119
+ u .UpdateStatusCustom (func (uSt * unstructured.Unstructured ) bool {
120
+ Expect (unstructured .SetNestedField (uSt .Object , "quux" , "foo" , "qux" )).To (Succeed ())
121
+ return true
122
+ })
123
+ u .UpdateStatus (EnsureCondition (conditions .Initialized (corev1 .ConditionTrue , "" , "" )))
124
+
125
+ Expect (u .Apply (context .TODO (), obj )).To (Succeed ())
126
+ Expect (cl .Get (context .TODO (), types.NamespacedName {Namespace : "testNamespace" , Name : "testDeployment" }, obj )).To (Succeed ())
127
+ Expect ((obj .Object ["status" ].(map [string ]interface {}))["conditions" ]).To (HaveLen (3 ))
128
+ _ , found , err := unstructured .NestedFieldNoCopy (obj .Object , "status" , "deployedRelease" )
129
+ Expect (found ).To (BeFalse ())
130
+ Expect (err ).To (Not (HaveOccurred ()))
131
+
132
+ val , found , err := unstructured .NestedString (obj .Object , "status" , "foo" , "bar" )
133
+ Expect (val ).To (Equal ("baz" ))
134
+ Expect (found ).To (BeTrue ())
135
+ Expect (err ).To (Not (HaveOccurred ()))
136
+
137
+ val , found , err = unstructured .NestedString (obj .Object , "status" , "foo" , "qux" )
138
+ Expect (val ).To (Equal ("quux" ))
139
+ Expect (found ).To (BeTrue ())
140
+ Expect (err ).To (Not (HaveOccurred ()))
141
+ })
142
+
143
+ It ("should preserve any custom status across multiple apply calls" , func () {
144
+ u .UpdateStatusCustom (func (uSt * unstructured.Unstructured ) bool {
145
+ Expect (unstructured .SetNestedMap (uSt .Object , map [string ]interface {}{"bar" : "baz" }, "foo" )).To (Succeed ())
146
+ return true
147
+ })
148
+ Expect (u .Apply (context .TODO (), obj )).To (Succeed ())
149
+
150
+ Expect (cl .Get (context .TODO (), types.NamespacedName {Namespace : "testNamespace" , Name : "testDeployment" }, obj )).To (Succeed ())
151
+
152
+ _ , found , err := unstructured .NestedFieldNoCopy (obj .Object , "status" , "deployedRelease" )
153
+ Expect (found ).To (BeFalse ())
154
+ Expect (err ).To (Not (HaveOccurred ()))
155
+
156
+ val , found , err := unstructured .NestedString (obj .Object , "status" , "foo" , "bar" )
157
+ Expect (val ).To (Equal ("baz" ))
158
+ Expect (found ).To (BeTrue ())
159
+ Expect (err ).To (Succeed ())
160
+
161
+ u .UpdateStatus (EnsureCondition (conditions .Deployed (corev1 .ConditionTrue , "" , "" )))
162
+ Expect (u .Apply (context .TODO (), obj )).To (Succeed ())
163
+
164
+ Expect (cl .Get (context .TODO (), types.NamespacedName {Namespace : "testNamespace" , Name : "testDeployment" }, obj )).To (Succeed ())
165
+ Expect ((obj .Object ["status" ].(map [string ]interface {}))["conditions" ]).To (HaveLen (1 ))
166
+
167
+ _ , found , err = unstructured .NestedFieldNoCopy (obj .Object , "status" , "deployedRelease" )
168
+ Expect (found ).To (BeFalse ())
169
+ Expect (err ).To (Not (HaveOccurred ()))
170
+
171
+ val , found , err = unstructured .NestedString (obj .Object , "status" , "foo" , "bar" )
172
+ Expect (val ).To (Equal ("baz" ))
173
+ Expect (found ).To (BeTrue ())
174
+ Expect (err ).To (Succeed ())
175
+ })
111
176
})
112
177
})
113
178
@@ -244,8 +309,9 @@ var _ = Describe("statusFor", func() {
244
309
})
245
310
246
311
It ("should handle map[string]interface{}" , func () {
247
- obj .Object ["status" ] = map [string ]interface {}{}
248
- Expect (statusFor (obj )).To (Equal (& helmAppStatus {}))
312
+ uSt := map [string ]interface {}{}
313
+ obj .Object ["status" ] = uSt
314
+ Expect (statusFor (obj )).To (Equal (& helmAppStatus {StatusObject : uSt }))
249
315
})
250
316
251
317
It ("should handle arbitrary types" , func () {
0 commit comments