@@ -18,6 +18,7 @@ package controller
1818
1919import (
2020 "context"
21+ "errors"
2122 "fmt"
2223 "strconv"
2324 "strings"
@@ -218,17 +219,16 @@ func (r *FunctionReconciler) reconcileDeployment(ctx context.Context, function *
218219 logger := log .FromContext (ctx )
219220 logger .Info ("Reconciling Function" )
220221
221- deployed , err := r .isDeployed (ctx , metadata .Name , function .Namespace )
222- if err != nil {
223- function .MarkDeployNotReady ("DeployFailed" , "Failed to check deployment status: %s" , err .Error ())
224- return fmt .Errorf ("failed to check if function is already deployed: %w" , err )
225- }
226-
227- if ! deployed {
222+ initialDesc , err := r .FuncCliManager .Describe (ctx , metadata .Name , function .Namespace )
223+ if errors .Is (err , funccli .ErrFunctionNotFound ) {
228224 logger .Info ("Function is not deployed" )
229225 function .MarkDeployNotReady ("NotDeployed" , "Function not deployed yet" )
230226 return nil
231227 }
228+ if err != nil {
229+ function .MarkDeployNotReady ("DeployFailed" , "Failed to check deployment status: %s" , err .Error ())
230+ return fmt .Errorf ("failed to check if function is already deployed: %w" , err )
231+ }
232232
233233 // function is deployed -> update status with metadata information
234234 deployer := metadata .Deploy .Deployer
@@ -241,7 +241,7 @@ func (r *FunctionReconciler) reconcileDeployment(ctx context.Context, function *
241241 applyLastDeployedAnnotation (ctx , function )
242242
243243 // Function is deployed - check middleware version
244- return r .handleMiddlewareUpdate (ctx , function , repo , metadata )
244+ return r .handleMiddlewareUpdate (ctx , function , repo , metadata , & initialDesc )
245245}
246246
247247// middlewareCheck is a sealed interface representing the result of inspecting a function's
@@ -279,12 +279,7 @@ type autoUpdateStatus struct {
279279 source string // "function" or "operator"
280280}
281281
282- func (r * FunctionReconciler ) checkMiddlewareState (ctx context.Context , function * v1alpha1.Function , metadata * funcfn.Function ) (middlewareCheck , error ) {
283- desc , err := r .FuncCliManager .Describe (ctx , metadata .Name , function .Namespace )
284- if err != nil {
285- return nil , fmt .Errorf ("failed to describe function: %w" , err )
286- }
287-
282+ func (r * FunctionReconciler ) checkMiddlewareState (ctx context.Context , function * v1alpha1.Function , metadata * funcfn.Function , desc * funcfn.Instance ) (middlewareCheck , error ) {
288283 autoUpdate , err := r .getAutoUpdateStatus (ctx , function )
289284 if err != nil {
290285 return nil , fmt .Errorf ("failed to check middleware update setting: %w" , err )
@@ -326,10 +321,10 @@ func (r *FunctionReconciler) getAutoUpdateStatus(ctx context.Context, function *
326321}
327322
328323// handleMiddlewareUpdate checks if the function is using the latest middleware and redeploys if needed
329- func (r * FunctionReconciler ) handleMiddlewareUpdate (ctx context.Context , function * v1alpha1.Function , repo * git.Repository , metadata * funcfn.Function ) error {
324+ func (r * FunctionReconciler ) handleMiddlewareUpdate (ctx context.Context , function * v1alpha1.Function , repo * git.Repository , metadata * funcfn.Function , desc * funcfn. Instance ) error {
330325 logger := log .FromContext (ctx )
331326
332- check , err := r .checkMiddlewareState (ctx , function , metadata )
327+ check , err := r .checkMiddlewareState (ctx , function , metadata , desc )
333328 if err != nil {
334329 function .MarkMiddlewareNotUpToDate ("MiddlewareCheckFailed" , "Failed to check middleware: %s" , err )
335330 return err
@@ -412,19 +407,6 @@ func markServiceStatus(ready string, function *v1alpha1.Function) {
412407 }
413408}
414409
415- func (r * FunctionReconciler ) isDeployed (ctx context.Context , name , namespace string ) (bool , error ) {
416- _ , err := r .FuncCliManager .Describe (ctx , name , namespace )
417- if err != nil {
418- if strings .Contains (err .Error (), "not found" ) || strings .Contains (err .Error (), "no describe function" ) {
419- return false , nil
420- }
421-
422- return false , fmt .Errorf ("failed to describe function: %w" , err )
423- }
424-
425- return true , nil
426- }
427-
428410// SetupWithManager sets up the controller with the Manager.
429411func (r * FunctionReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
430412 return ctrl .NewControllerManagedBy (mgr ).
0 commit comments