@@ -18,6 +18,7 @@ package controllers
1818
1919import (
2020 "context"
21+ "errors"
2122 "fmt"
2223 "reflect"
2324
@@ -151,23 +152,21 @@ func (r *HostFirmwareComponentsReconciler) Reconcile(ctx context.Context, req ct
151152 return ctrl.Result {Requeue : true , RequeueAfter : provisionerRetryDelay }, nil
152153 }
153154
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 )
159156 // Check ironic for the components information if possible
160157 components , err := prov .GetFirmwareComponents ()
161- info .log .Info ("retrieving firmware components and saving to resource" , "Node" , bmh .Status .Provisioning .ID )
162158
163159 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 )
166164 return ctrl.Result {Requeue : true , RequeueAfter : provisionerRetryDelay }, err
167165 }
168166
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 )
171170 }
172171
173172 for _ , e := range info .events {
@@ -181,14 +180,19 @@ func (r *HostFirmwareComponentsReconciler) Reconcile(ctx context.Context, req ct
181180}
182181
183182// 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 ) {
185184 dirty := false
186-
185+ var newStatus metal3api. HostFirmwareComponentsStatus
187186 // change the Updates in Status
188187 newStatus .Updates = info .hfc .Spec .Updates
188+ // change the Components in Status
189+ newStatus .Components = components
189190
190191 // Check if the updates in the Spec are different than Status
191192 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+ }
192196
193197 reason := reasonValidComponent
194198 generation := info .hfc .GetGeneration ()
@@ -222,32 +226,6 @@ func (r *HostFirmwareComponentsReconciler) updateHostFirmware(info *rhfcInfo) (n
222226 info .log .Info ("Status for HostFirmwareComponents changed" )
223227 info .hfc .Status = * newStatus .DeepCopy ()
224228
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-
251229 t := metav1 .Now ()
252230 info .hfc .Status .LastUpdated = & t
253231 return r .Status ().Update (info .ctx , info .hfc )
0 commit comments