@@ -144,22 +144,39 @@ func setConditionValue(conditionType string, err error) operatorsv1.ConditionSta
144
144
}
145
145
146
146
type StatusHandler struct {
147
- client v1helpers.OperatorClient
147
+ client v1helpers.OperatorClient
148
+ // conditionUpdates are keyed by condition type so that we always choose the latest as authoritative
149
+ conditionUpdates map [string ]v1helpers.UpdateStatusFunc
150
+
148
151
statusFuncs []v1helpers.UpdateStatusFunc
149
152
}
150
153
151
- func (c * StatusHandler ) AddCondition (newStatusFunc v1helpers.UpdateStatusFunc ) {
152
- c .statusFuncs = append (c .statusFuncs , newStatusFunc )
154
+ type ConditionUpdate struct {
155
+ ConditionType string
156
+ StatusUpdateFn v1helpers.UpdateStatusFunc
157
+ }
158
+
159
+ func (c * StatusHandler ) AddCondition (conditionUpdate ConditionUpdate ) {
160
+ c .conditionUpdates [conditionUpdate .ConditionType ] = conditionUpdate .StatusUpdateFn
153
161
}
154
162
155
- func (c * StatusHandler ) AddConditions (newStatusFuncs []v1helpers.UpdateStatusFunc ) {
156
- for _ , newStatusFunc := range newStatusFuncs {
157
- c .statusFuncs = append (c .statusFuncs , newStatusFunc )
163
+ func (c * StatusHandler ) AddConditions (conditionUpdates []ConditionUpdate ) {
164
+ for i := range conditionUpdates {
165
+ conditionUpdate := conditionUpdates [i ]
166
+ c .conditionUpdates [conditionUpdate .ConditionType ] = conditionUpdate .StatusUpdateFn
158
167
}
159
168
}
160
169
161
170
func (c * StatusHandler ) FlushAndReturn (returnErr error ) error {
162
- if _ , _ , updateErr := v1helpers .UpdateStatus (context .TODO (), c .client , c .statusFuncs ... ); updateErr != nil {
171
+ allStatusFns := []v1helpers.UpdateStatusFunc {}
172
+ for i := range c .statusFuncs {
173
+ allStatusFns = append (allStatusFns , c .statusFuncs [i ])
174
+ }
175
+ for k := range c .conditionUpdates {
176
+ allStatusFns = append (allStatusFns , c .conditionUpdates [k ])
177
+ }
178
+
179
+ if _ , _ , updateErr := v1helpers .UpdateStatus (context .TODO (), c .client , allStatusFns ... ); updateErr != nil {
163
180
return updateErr
164
181
}
165
182
return returnErr
@@ -191,7 +208,8 @@ func (c *StatusHandler) UpdateDeploymentGeneration(actualDeployment *appsv1.Depl
191
208
192
209
func NewStatusHandler (client v1helpers.OperatorClient ) StatusHandler {
193
210
return StatusHandler {
194
- client : client ,
211
+ client : client ,
212
+ conditionUpdates : map [string ]v1helpers.UpdateStatusFunc {},
195
213
}
196
214
}
197
215
0 commit comments