@@ -95,76 +95,143 @@ func (r *NicFirmwareSourceReconciler) Reconcile(ctx context.Context, req ctrl.Re
9595 }
9696 }
9797
98+ // Handle Binary Firmware URLs
99+ var binaryVersions map [string ][]string
100+ if len (instance .Spec .BinUrlSources ) > 0 {
101+ binaryVersions , err = r .processBinarySources (ctx , instance , cacheName )
102+ if err != nil {
103+ log .Log .Error (err , "failed to process binary source" , "name" , instance .Name )
104+ return reconcile.Result {}, err
105+ }
106+ }
107+
108+ // Handle BFB Firmware URL
109+ var bfbVersions map [string ]string
110+ if instance .Spec .BFBUrlSource != "" {
111+ bfbVersions , err = r .processBFBSource (ctx , instance , cacheName )
112+ if err != nil {
113+ log .Log .Error (err , "failed to process BFB source" , "name" , instance .Name )
114+ return reconcile.Result {}, err
115+ }
116+ }
117+
118+ // Update final status with both binary versions and BFB info
119+ if err = r .updateStatus (ctx , instance , consts .FirmwareSourceSuccessStatus , nil , binaryVersions , bfbVersions ); err != nil {
120+ return reconcile.Result {}, err
121+ }
122+
123+ return ctrl.Result {}, nil
124+ }
125+
126+ // processBinarySources handles downloading and processing of binary firmware files
127+ func (r * NicFirmwareSourceReconciler ) processBinarySources (ctx context.Context , instance * v1alpha1.NicFirmwareSource , cacheName string ) (map [string ][]string , error ) {
98128 urlsToProcess , err := r .FirmwareProvisioner .VerifyCachedBinaries (cacheName , instance .Spec .BinUrlSources )
99129 if err != nil {
100130 log .Log .Error (err , "failed to verify cached binaries" , "name" , instance .Name )
101131
102- if updateErr := r .updateStatus (ctx , instance , consts .FirmwareSourceCacheVerificationFailedStatus , err , nil ); updateErr != nil {
103- return reconcile. Result {} , updateErr
132+ if updateErr := r .updateStatus (ctx , instance , consts .FirmwareSourceCacheVerificationFailedStatus , err , nil , nil ); updateErr != nil {
133+ return nil , updateErr
104134 }
105- return reconcile. Result {} , err
135+ return nil , err
106136 }
137+
107138 if len (urlsToProcess ) != 0 {
108- if err = r .updateStatus (ctx , instance , consts .FirmwareSourceDownloadingStatus , nil , nil ); err != nil {
109- return reconcile. Result {} , err
139+ if err = r .updateStatus (ctx , instance , consts .FirmwareSourceDownloadingStatus , nil , nil , nil ); err != nil {
140+ return nil , err
110141 }
111142
112143 err = r .FirmwareProvisioner .DownloadAndUnzipFirmwareArchives (cacheName , urlsToProcess , true )
113144 if err != nil {
114145 log .Log .Error (err , "failed to download fw binaries archives" , "name" , instance .Name )
115146
116- if updateErr := r .updateStatus (ctx , instance , consts .FirmwareSourceDownloadFailedStatus , err , nil ); updateErr != nil {
117- return reconcile. Result {} , updateErr
147+ if updateErr := r .updateStatus (ctx , instance , consts .FirmwareSourceDownloadFailedStatus , err , nil , nil ); updateErr != nil {
148+ return nil , updateErr
118149 }
119- return reconcile. Result {} , err
150+ return nil , err
120151 }
121152 } else {
122- log .Log .Info ("Files for all requested URLs already present, skipping download" , "cacheName" , instance .Name )
153+ log .Log .Info ("Files for all requested binary URLs already present, skipping download" , "cacheName" , instance .Name )
123154 }
124155
125- if err = r .updateStatus (ctx , instance , consts .FirmwareSourceProcessingStatus , nil , nil ); err != nil {
126- return reconcile. Result {} , err
156+ if err = r .updateStatus (ctx , instance , consts .FirmwareSourceProcessingStatus , nil , nil , nil ); err != nil {
157+ return nil , err
127158 }
128159
129160 err = r .FirmwareProvisioner .AddFirmwareBinariesToCacheByMetadata (cacheName )
130161 if err != nil {
131162 log .Log .Error (err , "failed to add fw binaries to cache" , "name" , instance .Name )
132163
133- if updateErr := r .updateStatus (ctx , instance , consts .FirmwareSourceProcessingFailedStatus , err , nil ); updateErr != nil {
134- return reconcile. Result {} , updateErr
164+ if updateErr := r .updateStatus (ctx , instance , consts .FirmwareSourceProcessingFailedStatus , err , nil , nil ); updateErr != nil {
165+ return nil , updateErr
135166 }
136- return reconcile. Result {} , err
167+ return nil , err
137168 }
138169
139- return r .ValidateCache (ctx , instance )
170+ versions , err := r .FirmwareProvisioner .ValidateCache (cacheName )
171+ if err != nil {
172+ log .Log .Error (err , "failed to validate fw binaries cache" , "name" , instance .Name )
173+ if updateErr := r .updateStatus (ctx , instance , consts .FirmwareSourceProcessingFailedStatus , err , nil , nil ); updateErr != nil {
174+ return nil , updateErr
175+ }
176+ return nil , err
177+ }
178+
179+ return versions , nil
140180}
141181
142- func (r * NicFirmwareSourceReconciler ) ValidateCache (ctx context.Context , instance * v1alpha1.NicFirmwareSource ) (reconcile.Result , error ) {
143- versions , err := r .FirmwareProvisioner .ValidateCache (instance .Name )
182+ // processBFBSource handles downloading and processing of BFB firmware files
183+ func (r * NicFirmwareSourceReconciler ) processBFBSource (ctx context.Context , instance * v1alpha1.NicFirmwareSource , cacheName string ) (map [string ]string , error ) {
184+ needsDownload , err := r .FirmwareProvisioner .VerifyCachedBFB (cacheName , instance .Spec .BFBUrlSource )
144185 if err != nil {
145- log .Log .Error (err , "failed to validate fw binaries cache" , "name" , instance .Name )
146- if updateErr := r .updateStatus (ctx , instance , consts .FirmwareSourceProcessingFailedStatus , err , nil ); updateErr != nil {
147- return reconcile.Result {}, updateErr
186+ log .Log .Error (err , "failed to verify cached BFB" , "name" , instance .Name )
187+
188+ if updateErr := r .updateStatus (ctx , instance , consts .FirmwareSourceCacheVerificationFailedStatus , err , nil , map [string ]string {}); updateErr != nil {
189+ return nil , updateErr
148190 }
149- return reconcile. Result {} , err
191+ return nil , err
150192 }
151193
152- if err = r .updateStatus (ctx , instance , consts .FirmwareSourceSuccessStatus , nil , versions ); err != nil {
153- return reconcile.Result {}, err
194+ var bfbFileName string
195+ if needsDownload {
196+ if err = r .updateStatus (ctx , instance , consts .FirmwareSourceDownloadingStatus , nil , nil , nil ); err != nil {
197+ return nil , err
198+ }
199+
200+ bfbFileName , err = r .FirmwareProvisioner .DownloadBFB (cacheName , instance .Spec .BFBUrlSource )
201+ if err != nil {
202+ log .Log .Error (err , "failed to download BFB file" , "name" , instance .Name )
203+
204+ if updateErr := r .updateStatus (ctx , instance , consts .FirmwareSourceDownloadFailedStatus , err , nil , map [string ]string {}); updateErr != nil {
205+ return nil , updateErr
206+ }
207+ return nil , err
208+ }
154209 }
155210
156- return ctrl.Result {}, nil
211+ bfbVersions , err := r .FirmwareProvisioner .ValidateBFB (cacheName )
212+ if err != nil {
213+ log .Log .Error (err , "failed to validate BFB file" , "name" , instance .Name )
214+ if updateErr := r .updateStatus (ctx , instance , consts .FirmwareSourceProcessingFailedStatus , err , nil , map [string ]string {}); updateErr != nil {
215+ return nil , updateErr
216+ }
217+ return nil , err
218+ }
219+
220+ log .Log .Info ("BFB file successfully processed" , "cacheName" , instance .Name , "filename" , bfbFileName )
221+ return bfbVersions , nil
157222}
158223
159- func (r * NicFirmwareSourceReconciler ) updateStatus (ctx context.Context , obj * v1alpha1.NicFirmwareSource , status string , statusError error , versions map [string ][]string ) error {
224+ func (r * NicFirmwareSourceReconciler ) updateStatus (ctx context.Context , obj * v1alpha1.NicFirmwareSource , status string , statusError error , binaryVersions map [string ][] string , bfbVersions map [ string ]string ) error {
160225 obj .Status .State = status
161226 if statusError != nil {
162227 obj .Status .Reason = statusError .Error ()
163228 } else {
164229 obj .Status .Reason = ""
165230 }
166231
167- obj .Status .Versions = versions
232+ obj .Status .BinaryVersions = binaryVersions
233+ obj .Status .BFBVersions = bfbVersions
234+
168235 err := r .Status ().Update (ctx , obj )
169236 if err != nil {
170237 log .Log .Error (err , "failed to update the status of NicFirmwareSource object" , "name" , obj .Name )
0 commit comments