@@ -126,12 +126,6 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
126126 }
127127 }
128128
129- account , api , err := InitCloudflareApi (ctx , r .Client , gatewayClass .Name )
130- if err != nil {
131- log .Error (err , "Failed to load Cloudflare API" )
132- return ctrl.Result {}, err
133- }
134-
135129 // Let's just set the status as Unknown when no status is available
136130 if len (gateway .Status .Conditions ) == 0 {
137131 meta .SetStatusCondition (& gateway .Status .Conditions , metav1.Condition {Type : typeAvailableGateway , Status : metav1 .ConditionUnknown , Reason : "Reconciling" , Message : "Starting reconciliation" })
@@ -168,6 +162,12 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
168162 }
169163 }
170164
165+ account , api , err := InitCloudflareApi (ctx , r .Client , gatewayClass .Name )
166+ if err != nil {
167+ log .Error (err , "Failed to load Cloudflare API" )
168+ return ctrl.Result {}, err
169+ }
170+
171171 // Check if the Gateway instance is marked to be deleted, which is
172172 // indicated by the deletion timestamp being set.
173173 isGatewayMarkedToBeDeleted := gateway .GetDeletionTimestamp () != nil
@@ -176,7 +176,7 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
176176 log .Info ("Performing Finalizer Operations for Gateway before delete CR" )
177177
178178 // Let's add here a status "Downgrade" to reflect that this resource began its process to be terminated.
179- meta .SetStatusCondition (& gateway .Status .Conditions , metav1.Condition {Type : string ( gatewayv1 . GatewayConditionAccepted ) ,
179+ meta .SetStatusCondition (& gateway .Status .Conditions , metav1.Condition {Type : typeDegradedGateway ,
180180 Status : metav1 .ConditionUnknown , Reason : string (gatewayv1 .GatewayReasonPending ), ObservedGeneration : gateway .Generation ,
181181 Message : fmt .Sprintf ("Performing finalizer operations for the custom resource: %s " , gateway .Name )})
182182
@@ -201,7 +201,7 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
201201 return ctrl.Result {}, err
202202 }
203203
204- meta .SetStatusCondition (& gateway .Status .Conditions , metav1.Condition {Type : string ( gatewayv1 . GatewayConditionAccepted ) ,
204+ meta .SetStatusCondition (& gateway .Status .Conditions , metav1.Condition {Type : typeDegradedGateway ,
205205 Status : metav1 .ConditionTrue , Reason : "Finalizing" , ObservedGeneration : gateway .Generation ,
206206 Message : fmt .Sprintf ("Finalizer operations for custom resource %s name were successfully accomplished" , gateway .Name )})
207207
@@ -439,6 +439,11 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
439439 return ctrl.Result {}, err
440440 }
441441
442+ if err := r .Get (ctx , req .NamespacedName , gateway ); err != nil {
443+ log .Error (err , "Failed to re-fetch gateway" )
444+ return ctrl.Result {}, err
445+ }
446+
442447 // The following implementation will update the status
443448 meta .SetStatusCondition (& gateway .Status .Conditions , metav1.Condition {Type : string (gatewayv1 .GatewayConditionProgrammed ),
444449 Status : metav1 .ConditionTrue , Reason : string (gatewayv1 .GatewayReasonProgrammed ), ObservedGeneration : gateway .Generation ,
@@ -547,7 +552,7 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
547552 }
548553
549554 // The following implementation will update the status
550- meta .SetStatusCondition (& gateway .Status .Conditions , metav1.Condition {Type : string ( gatewayv1 . GatewayConditionProgrammed ) ,
555+ meta .SetStatusCondition (& gateway .Status .Conditions , metav1.Condition {Type : typeAvailableGateway ,
551556 Status : metav1 .ConditionTrue , Reason : string (gatewayv1 .GatewayReasonProgrammed ), ObservedGeneration : gateway .Generation ,
552557 Message : fmt .Sprintf ("Deployment for custom resource (%s) reconciled successfully" , gateway .Name )})
553558
@@ -750,7 +755,7 @@ func imageForGateway() (string, error) {
750755 var imageEnvVar = "GATEWAY_IMAGE"
751756 image , found := os .LookupEnv (imageEnvVar )
752757 if ! found {
753- return "" , fmt .Errorf ("unable to find %s environment variable with the image" , imageEnvVar )
758+ return "" , fmt .Errorf ("Unable to find %s environment variable with the image" , imageEnvVar )
754759 }
755760 return image , nil
756761}
@@ -765,7 +770,6 @@ func imageForGateway() (string, error) {
765770// or deletion of a Custom Resource (CR) of the Gateway kind, as well as any changes
766771// to the Deployment that the controller manages and owns.
767772func (r * GatewayReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
768- pred := predicate.GenerationChangedPredicate {}
769773 return ctrl .NewControllerManagedBy (mgr ).
770774 // Watch the Gateway CR(s) and trigger reconciliation whenever it
771775 // is created, updated, or deleted
@@ -775,6 +779,6 @@ func (r *GatewayReconciler) SetupWithManager(mgr ctrl.Manager) error {
775779 // owned and managed by this controller, it will trigger reconciliation, ensuring that the cluster
776780 // state aligns with the desired state. See that the ownerRef was set when the Deployment was created.
777781 Owns (& appsv1.Deployment {}).
778- WithEventFilter (pred ).
782+ WithEventFilter (predicate. GenerationChangedPredicate {} ).
779783 Complete (r )
780784}
0 commit comments