@@ -18,6 +18,7 @@ package controllers
18
18
19
19
import (
20
20
"context"
21
+ "errors"
21
22
"fmt"
22
23
"reflect"
23
24
@@ -151,23 +152,21 @@ func (r *HostFirmwareComponentsReconciler) Reconcile(ctx context.Context, req ct
151
152
return ctrl.Result {Requeue : true , RequeueAfter : provisionerRetryDelay }, nil
152
153
}
153
154
154
- newStatus , err := r .updateHostFirmware (info )
155
- if err != nil {
156
- return ctrl.Result {}, fmt .Errorf ("could not update hostfirmwarecomponents: %w" , err )
157
- }
158
-
155
+ info .log .Info ("retrieving firmware components and saving to resource" , "Node" , bmh .Status .Provisioning .ID )
159
156
// Check ironic for the components information if possible
160
157
components , err := prov .GetFirmwareComponents ()
161
- info .log .Info ("retrieving firmware components and saving to resource" , "Node" , bmh .Status .Provisioning .ID )
162
158
163
159
if err != nil {
164
- reqLogger .Error (err , "provisioner returns error" , "RequeueAfter" , provisionerRetryDelay )
165
- setUpdatesCondition (info .hfc .GetGeneration (), & newStatus , info , metal3api .HostFirmwareComponentsValid , metav1 .ConditionFalse , reasonInvalidComponent , err .Error ())
160
+ if errors .Is (err , provisioner .ErrFirmwareUpdateUnsupported ) {
161
+ return ctrl.Result {Requeue : false }, err
162
+ }
163
+ reqLogger .Info ("provisioner returns error" , "Error" , err .Error (), "RequeueAfter" , provisionerRetryDelay )
166
164
return ctrl.Result {Requeue : true , RequeueAfter : provisionerRetryDelay }, err
167
165
}
168
166
169
- if err = r .updateHostFirmwareComponents (newStatus , components , info ); err != nil {
170
- return ctrl.Result {Requeue : false }, err
167
+ if err = r .updateHostFirmware (info , components ); err != nil {
168
+ info .log .Info ("updateHostFirmware returned error" )
169
+ return ctrl.Result {}, fmt .Errorf ("could not update hostfirmwarecomponents: %w" , err )
171
170
}
172
171
173
172
for _ , e := range info .events {
@@ -181,14 +180,19 @@ func (r *HostFirmwareComponentsReconciler) Reconcile(ctx context.Context, req ct
181
180
}
182
181
183
182
// Update the HostFirmwareComponents resource using the components from provisioner.
184
- func (r * HostFirmwareComponentsReconciler ) updateHostFirmware (info * rhfcInfo ) ( newStatus metal3api.HostFirmwareComponentsStatus , err error ) {
183
+ func (r * HostFirmwareComponentsReconciler ) updateHostFirmware (info * rhfcInfo , components [] metal3api.FirmwareComponentStatus ) ( err error ) {
185
184
dirty := false
186
-
185
+ var newStatus metal3api. HostFirmwareComponentsStatus
187
186
// change the Updates in Status
188
187
newStatus .Updates = info .hfc .Spec .Updates
188
+ // change the Components in Status
189
+ newStatus .Components = components
189
190
190
191
// Check if the updates in the Spec are different than Status
191
192
updatesMismatch := ! reflect .DeepEqual (info .hfc .Status .Updates , info .hfc .Spec .Updates )
193
+ if len (info .hfc .Spec .Updates ) == 0 && len (info .hfc .Status .Updates ) == 0 {
194
+ updatesMismatch = false
195
+ }
192
196
193
197
reason := reasonValidComponent
194
198
generation := info .hfc .GetGeneration ()
@@ -222,32 +226,6 @@ func (r *HostFirmwareComponentsReconciler) updateHostFirmware(info *rhfcInfo) (n
222
226
info .log .Info ("Status for HostFirmwareComponents changed" )
223
227
info .hfc .Status = * newStatus .DeepCopy ()
224
228
225
- t := metav1 .Now ()
226
- info .hfc .Status .LastUpdated = & t
227
- return newStatus , r .Status ().Update (info .ctx , info .hfc )
228
- }
229
- return newStatus , nil
230
- }
231
-
232
- // Update the HostFirmwareComponents resource using the components from provisioner.
233
- func (r * HostFirmwareComponentsReconciler ) updateHostFirmwareComponents (newStatus metal3api.HostFirmwareComponentsStatus , components []metal3api.FirmwareComponentStatus , info * rhfcInfo ) (err error ) {
234
- dirty := false
235
- // change the Components in Status
236
- newStatus .Components = components
237
- // Check if the components information we retrieved is different from the one in Status
238
- componentsInfoMismatch := ! reflect .DeepEqual (components , info .hfc .Status .Components )
239
- reason := reasonValidComponent
240
- generation := info .hfc .GetGeneration ()
241
- // Log the components we have
242
- info .log .Info ("firmware components for node" , "components" , components , "bmh" , info .bmh .Name )
243
- if componentsInfoMismatch {
244
- setUpdatesCondition (generation , & newStatus , info , metal3api .HostFirmwareComponentsChangeDetected , metav1 .ConditionTrue , reason , "" )
245
- dirty = true
246
- }
247
- if dirty {
248
- info .log .Info ("Components Status for HostFirmwareComponents changed" )
249
- info .hfc .Status = * newStatus .DeepCopy ()
250
-
251
229
t := metav1 .Now ()
252
230
info .hfc .Status .LastUpdated = & t
253
231
return r .Status ().Update (info .ctx , info .hfc )
0 commit comments