@@ -40,32 +40,44 @@ import (
40
40
// Message: error string value is used as message
41
41
//
42
42
// all degraded suffix conditions will be aggregated into a final "Degraded" status that will be set on the console ClusterOperator
43
- func HandleDegraded (typePrefix string , reason string , err error ) v1helpers. UpdateStatusFunc {
43
+ func HandleDegraded (typePrefix string , reason string , err error ) ConditionUpdate {
44
44
conditionType := typePrefix + operatorsv1 .OperatorStatusTypeDegraded
45
45
condition := handleCondition (conditionType , reason , err )
46
- return v1helpers .UpdateConditionFn (condition )
46
+ return ConditionUpdate {
47
+ ConditionType : conditionType ,
48
+ StatusUpdateFn : v1helpers .UpdateConditionFn (condition ),
49
+ }
47
50
}
48
51
49
- func HandleProgressing (typePrefix string , reason string , err error ) v1helpers. UpdateStatusFunc {
52
+ func HandleProgressing (typePrefix string , reason string , err error ) ConditionUpdate {
50
53
conditionType := typePrefix + operatorsv1 .OperatorStatusTypeProgressing
51
54
condition := handleCondition (conditionType , reason , err )
52
- return v1helpers .UpdateConditionFn (condition )
55
+ return ConditionUpdate {
56
+ ConditionType : conditionType ,
57
+ StatusUpdateFn : v1helpers .UpdateConditionFn (condition ),
58
+ }
53
59
}
54
60
55
- func HandleAvailable (typePrefix string , reason string , err error ) v1helpers. UpdateStatusFunc {
61
+ func HandleAvailable (typePrefix string , reason string , err error ) ConditionUpdate {
56
62
conditionType := typePrefix + operatorsv1 .OperatorStatusTypeAvailable
57
63
condition := handleCondition (conditionType , reason , err )
58
- return v1helpers .UpdateConditionFn (condition )
64
+ return ConditionUpdate {
65
+ ConditionType : conditionType ,
66
+ StatusUpdateFn : v1helpers .UpdateConditionFn (condition ),
67
+ }
59
68
}
60
69
61
- func HandleUpgradable (typePrefix string , reason string , err error ) v1helpers. UpdateStatusFunc {
70
+ func HandleUpgradable (typePrefix string , reason string , err error ) ConditionUpdate {
62
71
conditionType := typePrefix + operatorsv1 .OperatorStatusTypeUpgradeable
63
72
condition := handleCondition (conditionType , reason , err )
64
- return v1helpers .UpdateConditionFn (condition )
73
+ return ConditionUpdate {
74
+ ConditionType : conditionType ,
75
+ StatusUpdateFn : v1helpers .UpdateConditionFn (condition ),
76
+ }
65
77
}
66
78
67
- func (c * StatusHandler ) ResetConditions (conditions []operatorsv1.OperatorCondition ) []v1helpers. UpdateStatusFunc {
68
- updateStatusFuncs := []v1helpers. UpdateStatusFunc {}
79
+ func (c * StatusHandler ) ResetConditions (conditions []operatorsv1.OperatorCondition ) []ConditionUpdate {
80
+ updateStatusFuncs := []ConditionUpdate {}
69
81
for _ , condition := range conditions {
70
82
klog .V (2 ).Info ("\n resetting condition: " , condition .Type )
71
83
if strings .HasSuffix (condition .Type , operatorsv1 .OperatorStatusTypeDegraded ) {
@@ -101,8 +113,8 @@ func (c *StatusHandler) ResetConditions(conditions []operatorsv1.OperatorConditi
101
113
// - Type suffix will be set to Degraded
102
114
// TODO: when we eliminate the special case SyncError, this helper can go away.
103
115
// When we do that, however, we must make sure to register deprecated conditions with NewRemoveStaleConditions()
104
- func HandleProgressingOrDegraded (typePrefix string , reason string , err error ) []v1helpers. UpdateStatusFunc {
105
- updateStatusFuncs := []v1helpers. UpdateStatusFunc {}
116
+ func HandleProgressingOrDegraded (typePrefix string , reason string , err error ) []ConditionUpdate {
117
+ updateStatusFuncs := []ConditionUpdate {}
106
118
if errors .IsSyncError (err ) {
107
119
updateStatusFuncs = append (updateStatusFuncs , HandleDegraded (typePrefix , reason , nil ))
108
120
updateStatusFuncs = append (updateStatusFuncs , HandleProgressing (typePrefix , reason , err ))
@@ -144,22 +156,39 @@ func setConditionValue(conditionType string, err error) operatorsv1.ConditionSta
144
156
}
145
157
146
158
type StatusHandler struct {
147
- client v1helpers.OperatorClient
159
+ client v1helpers.OperatorClient
160
+ // conditionUpdates are keyed by condition type so that we always choose the latest as authoritative
161
+ conditionUpdates map [string ]v1helpers.UpdateStatusFunc
162
+
148
163
statusFuncs []v1helpers.UpdateStatusFunc
149
164
}
150
165
151
- func (c * StatusHandler ) AddCondition (newStatusFunc v1helpers.UpdateStatusFunc ) {
152
- c .statusFuncs = append (c .statusFuncs , newStatusFunc )
166
+ type ConditionUpdate struct {
167
+ ConditionType string
168
+ StatusUpdateFn v1helpers.UpdateStatusFunc
153
169
}
154
170
155
- func (c * StatusHandler ) AddConditions (newStatusFuncs []v1helpers.UpdateStatusFunc ) {
156
- for _ , newStatusFunc := range newStatusFuncs {
157
- c .statusFuncs = append (c .statusFuncs , newStatusFunc )
171
+ func (c * StatusHandler ) AddCondition (conditionUpdate ConditionUpdate ) {
172
+ c .conditionUpdates [conditionUpdate .ConditionType ] = conditionUpdate .StatusUpdateFn
173
+ }
174
+
175
+ func (c * StatusHandler ) AddConditions (conditionUpdates []ConditionUpdate ) {
176
+ for i := range conditionUpdates {
177
+ conditionUpdate := conditionUpdates [i ]
178
+ c .conditionUpdates [conditionUpdate .ConditionType ] = conditionUpdate .StatusUpdateFn
158
179
}
159
180
}
160
181
161
182
func (c * StatusHandler ) FlushAndReturn (returnErr error ) error {
162
- if _ , _ , updateErr := v1helpers .UpdateStatus (context .TODO (), c .client , c .statusFuncs ... ); updateErr != nil {
183
+ allStatusFns := []v1helpers.UpdateStatusFunc {}
184
+ for i := range c .statusFuncs {
185
+ allStatusFns = append (allStatusFns , c .statusFuncs [i ])
186
+ }
187
+ for k := range c .conditionUpdates {
188
+ allStatusFns = append (allStatusFns , c .conditionUpdates [k ])
189
+ }
190
+
191
+ if _ , _ , updateErr := v1helpers .UpdateStatus (context .TODO (), c .client , allStatusFns ... ); updateErr != nil {
163
192
return updateErr
164
193
}
165
194
return returnErr
@@ -191,7 +220,8 @@ func (c *StatusHandler) UpdateDeploymentGeneration(actualDeployment *appsv1.Depl
191
220
192
221
func NewStatusHandler (client v1helpers.OperatorClient ) StatusHandler {
193
222
return StatusHandler {
194
- client : client ,
223
+ client : client ,
224
+ conditionUpdates : map [string ]v1helpers.UpdateStatusFunc {},
195
225
}
196
226
}
197
227
0 commit comments