@@ -92,6 +92,71 @@ var _ = Describe("Updater", func() {
92
92
Expect ((obj .Object ["status" ].(map [string ]interface {}))["conditions" ]).To (HaveLen (1 ))
93
93
Expect (obj .GetResourceVersion ()).NotTo (Equal (resourceVersion ))
94
94
})
95
+
96
+ It ("should support a mix of standard and custom status updates" , func () {
97
+ u .UpdateStatus (EnsureCondition (conditions .Deployed (corev1 .ConditionTrue , "" , "" )))
98
+ u .UpdateStatusCustom (func (uSt * unstructured.Unstructured ) bool {
99
+ Expect (unstructured .SetNestedMap (uSt .Object , map [string ]interface {}{"bar" : "baz" }, "foo" )).To (Succeed ())
100
+ return true
101
+ })
102
+ u .UpdateStatus (EnsureCondition (conditions .Irreconcilable (corev1 .ConditionFalse , "" , "" )))
103
+ u .UpdateStatusCustom (func (uSt * unstructured.Unstructured ) bool {
104
+ Expect (unstructured .SetNestedField (uSt .Object , "quux" , "foo" , "qux" )).To (Succeed ())
105
+ return true
106
+ })
107
+ u .UpdateStatus (EnsureCondition (conditions .Initialized (corev1 .ConditionTrue , "" , "" )))
108
+
109
+ Expect (u .Apply (context .TODO (), obj )).To (Succeed ())
110
+ Expect (client .Get (context .TODO (), types.NamespacedName {Namespace : "testNamespace" , Name : "testDeployment" }, obj )).To (Succeed ())
111
+ Expect ((obj .Object ["status" ].(map [string ]interface {}))["conditions" ]).To (HaveLen (3 ))
112
+ _ , found , err := unstructured .NestedFieldNoCopy (obj .Object , "status" , "deployedRelease" )
113
+ Expect (found ).To (BeFalse ())
114
+ Expect (err ).To (Not (HaveOccurred ()))
115
+
116
+ val , found , err := unstructured .NestedString (obj .Object , "status" , "foo" , "bar" )
117
+ Expect (val ).To (Equal ("baz" ))
118
+ Expect (found ).To (BeTrue ())
119
+ Expect (err ).To (Not (HaveOccurred ()))
120
+
121
+ val , found , err = unstructured .NestedString (obj .Object , "status" , "foo" , "qux" )
122
+ Expect (val ).To (Equal ("quux" ))
123
+ Expect (found ).To (BeTrue ())
124
+ Expect (err ).To (Not (HaveOccurred ()))
125
+ })
126
+
127
+ It ("should preserve any custom status across multiple apply calls" , func () {
128
+ u .UpdateStatusCustom (func (uSt * unstructured.Unstructured ) bool {
129
+ Expect (unstructured .SetNestedMap (uSt .Object , map [string ]interface {}{"bar" : "baz" }, "foo" )).To (Succeed ())
130
+ return true
131
+ })
132
+ Expect (u .Apply (context .TODO (), obj )).To (Succeed ())
133
+
134
+ Expect (client .Get (context .TODO (), types.NamespacedName {Namespace : "testNamespace" , Name : "testDeployment" }, obj )).To (Succeed ())
135
+
136
+ _ , found , err := unstructured .NestedFieldNoCopy (obj .Object , "status" , "deployedRelease" )
137
+ Expect (found ).To (BeFalse ())
138
+ Expect (err ).To (Not (HaveOccurred ()))
139
+
140
+ val , found , err := unstructured .NestedString (obj .Object , "status" , "foo" , "bar" )
141
+ Expect (val ).To (Equal ("baz" ))
142
+ Expect (found ).To (BeTrue ())
143
+ Expect (err ).To (Succeed ())
144
+
145
+ u .UpdateStatus (EnsureCondition (conditions .Deployed (corev1 .ConditionTrue , "" , "" )))
146
+ Expect (u .Apply (context .TODO (), obj )).To (Succeed ())
147
+
148
+ Expect (client .Get (context .TODO (), types.NamespacedName {Namespace : "testNamespace" , Name : "testDeployment" }, obj )).To (Succeed ())
149
+ Expect ((obj .Object ["status" ].(map [string ]interface {}))["conditions" ]).To (HaveLen (1 ))
150
+
151
+ _ , found , err = unstructured .NestedFieldNoCopy (obj .Object , "status" , "deployedRelease" )
152
+ Expect (found ).To (BeFalse ())
153
+ Expect (err ).To (Not (HaveOccurred ()))
154
+
155
+ val , found , err = unstructured .NestedString (obj .Object , "status" , "foo" , "bar" )
156
+ Expect (val ).To (Equal ("baz" ))
157
+ Expect (found ).To (BeTrue ())
158
+ Expect (err ).To (Succeed ())
159
+ })
95
160
})
96
161
})
97
162
@@ -228,8 +293,9 @@ var _ = Describe("statusFor", func() {
228
293
})
229
294
230
295
It ("should handle map[string]interface{}" , func () {
231
- obj .Object ["status" ] = map [string ]interface {}{}
232
- Expect (statusFor (obj )).To (Equal (& helmAppStatus {}))
296
+ uSt := map [string ]interface {}{}
297
+ obj .Object ["status" ] = uSt
298
+ Expect (statusFor (obj )).To (Equal (& helmAppStatus {StatusObject : uSt }))
233
299
})
234
300
235
301
It ("should handle arbitrary types" , func () {
0 commit comments