@@ -214,18 +214,34 @@ func (r *FunctionReconciler) ensureDeployment(ctx context.Context, function *v1a
214214func (r * FunctionReconciler ) handleMiddlewareUpdate (ctx context.Context , function * v1alpha1.Function , repo * git.Repository , metadata * funcfn.Function ) error {
215215 logger := log .FromContext (ctx )
216216
217+ functionDescribe , err := r .FuncCliManager .Describe (ctx , metadata .Name , function .Namespace )
218+ if err != nil {
219+ return fmt .Errorf ("failed to describe function to get image details: %w" , err )
220+ }
221+ function .Status .Deployment .Image = functionDescribe .Image
222+
223+ isMiddlewareUpdateEnabled , source , err := r .isMiddlewareUpdateEnabled (ctx , function )
224+ if err != nil {
225+ function .MarkMiddlewareNotUpToDate ("MiddlewareCheckFailed" , "Failed to check if middleware should be updated: %s" , err )
226+ return fmt .Errorf ("failed to check if middleware should be updated: %w" , err )
227+ }
228+ function .Status .Middleware .AutoUpdate .Enabled = isMiddlewareUpdateEnabled
229+ function .Status .Middleware .AutoUpdate .Source = source
230+ function .Status .Middleware .Current = functionDescribe .Middleware .Version
231+ function .Status .Middleware .PendingRebuild = false
232+
217233 isOnLatestMiddleware , err := r .isMiddlewareLatest (ctx , metadata , function .Namespace )
218234 if err != nil {
219235 function .MarkMiddlewareNotUpToDate ("MiddlewareCheckFailed" , "Failed to check middleware version: %s" , err .Error ())
220236 return fmt .Errorf ("failed to check if function is using latest middleware: %w" , err )
221237 }
222238
223239 if ! isOnLatestMiddleware {
224- isMiddlewareUpdateEnabled , source , err := r .isMiddlewareUpdateEnabled (ctx , function )
240+ latestMiddleware , err := r .FuncCliManager . GetLatestMiddlewareVersion (ctx , metadata . Runtime , metadata . Invoke )
225241 if err != nil {
226- function .MarkMiddlewareNotUpToDate ("MiddlewareCheckFailed" , "Failed to check if middleware should be updated: %s" , err )
227- return fmt .Errorf ("failed to check if middleware should be updated: %w" , err )
242+ return fmt .Errorf ("failed to get latest available middleware version: %w" , err )
228243 }
244+ function .Status .Middleware .Available = ptr .To (latestMiddleware )
229245
230246 if ! isMiddlewareUpdateEnabled {
231247 logger .Info ("Skipping middleware update, as middleware update is disabled" )
@@ -235,12 +251,7 @@ func (r *FunctionReconciler) handleMiddlewareUpdate(ctx context.Context, functio
235251 logger .Info ("Function is not on latest middleware and middleware update is enabled. Will redeploy" )
236252 function .MarkMiddlewareNotUpToDate ("MiddlewareOutdated" , "Middleware is outdated, redeploying" )
237253
238- // update function image in status before long redeploy operation
239- functionDescribe , err := r .FuncCliManager .Describe (ctx , metadata .Name , function .Namespace )
240- if err != nil {
241- return fmt .Errorf ("failed to describe function to get image details: %w" , err )
242- }
243- function .Status .Deployment .Image = functionDescribe .Image
254+ function .Status .Middleware .PendingRebuild = true
244255
245256 // Flush status before long deploy operation
246257 if err := FlushStatus (ctx , function ); err != nil {
@@ -252,20 +263,26 @@ func (r *FunctionReconciler) handleMiddlewareUpdate(ctx context.Context, functio
252263 return fmt .Errorf ("failed to redeploy function: %w" , err )
253264 }
254265
266+ function .Status .Middleware .PendingRebuild = false
267+ function .Status .Middleware .LastRebuild = metav1 .Now ()
268+
255269 // After successful deployment, middleware is now up-to-date
256270 function .MarkMiddlewareUpToDate ()
271+ function .Status .Middleware .Available = nil // if function is on latest, we don't need to show this field
257272 }
258273 } else {
259274 logger .Info ("Function is deployed with latest middleware. No need to redeploy" )
260275 function .MarkMiddlewareUpToDate ()
276+ function .Status .Middleware .Available = nil // if function is on latest, we don't need to show this field
261277 }
262278
263279 // Update deployment status
264- functionDescribe , err : = r .FuncCliManager .Describe (ctx , metadata .Name , function .Namespace )
280+ functionDescribe , err = r .FuncCliManager .Describe (ctx , metadata .Name , function .Namespace )
265281 if err != nil {
266282 return fmt .Errorf ("failed to describe function to get image details: %w" , err )
267283 }
268284 function .Status .Deployment .Image = functionDescribe .Image
285+ function .Status .Middleware .Current = functionDescribe .Middleware .Version
269286
270287 function .MarkDeployReady ()
271288 return nil
0 commit comments