@@ -126,12 +126,6 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
126
126
}
127
127
}
128
128
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
-
135
129
// Let's just set the status as Unknown when no status is available
136
130
if len (gateway .Status .Conditions ) == 0 {
137
131
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
168
162
}
169
163
}
170
164
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
+
171
171
// Check if the Gateway instance is marked to be deleted, which is
172
172
// indicated by the deletion timestamp being set.
173
173
isGatewayMarkedToBeDeleted := gateway .GetDeletionTimestamp () != nil
@@ -176,7 +176,7 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
176
176
log .Info ("Performing Finalizer Operations for Gateway before delete CR" )
177
177
178
178
// 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 ,
180
180
Status : metav1 .ConditionUnknown , Reason : string (gatewayv1 .GatewayReasonPending ), ObservedGeneration : gateway .Generation ,
181
181
Message : fmt .Sprintf ("Performing finalizer operations for the custom resource: %s " , gateway .Name )})
182
182
@@ -201,7 +201,7 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
201
201
return ctrl.Result {}, err
202
202
}
203
203
204
- meta .SetStatusCondition (& gateway .Status .Conditions , metav1.Condition {Type : string ( gatewayv1 . GatewayConditionAccepted ) ,
204
+ meta .SetStatusCondition (& gateway .Status .Conditions , metav1.Condition {Type : typeDegradedGateway ,
205
205
Status : metav1 .ConditionTrue , Reason : "Finalizing" , ObservedGeneration : gateway .Generation ,
206
206
Message : fmt .Sprintf ("Finalizer operations for custom resource %s name were successfully accomplished" , gateway .Name )})
207
207
@@ -439,6 +439,11 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
439
439
return ctrl.Result {}, err
440
440
}
441
441
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
+
442
447
// The following implementation will update the status
443
448
meta .SetStatusCondition (& gateway .Status .Conditions , metav1.Condition {Type : string (gatewayv1 .GatewayConditionProgrammed ),
444
449
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
547
552
}
548
553
549
554
// 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 ,
551
556
Status : metav1 .ConditionTrue , Reason : string (gatewayv1 .GatewayReasonProgrammed ), ObservedGeneration : gateway .Generation ,
552
557
Message : fmt .Sprintf ("Deployment for custom resource (%s) reconciled successfully" , gateway .Name )})
553
558
@@ -750,7 +755,7 @@ func imageForGateway() (string, error) {
750
755
var imageEnvVar = "GATEWAY_IMAGE"
751
756
image , found := os .LookupEnv (imageEnvVar )
752
757
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 )
754
759
}
755
760
return image , nil
756
761
}
@@ -765,7 +770,6 @@ func imageForGateway() (string, error) {
765
770
// or deletion of a Custom Resource (CR) of the Gateway kind, as well as any changes
766
771
// to the Deployment that the controller manages and owns.
767
772
func (r * GatewayReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
768
- pred := predicate.GenerationChangedPredicate {}
769
773
return ctrl .NewControllerManagedBy (mgr ).
770
774
// Watch the Gateway CR(s) and trigger reconciliation whenever it
771
775
// is created, updated, or deleted
@@ -775,6 +779,6 @@ func (r *GatewayReconciler) SetupWithManager(mgr ctrl.Manager) error {
775
779
// owned and managed by this controller, it will trigger reconciliation, ensuring that the cluster
776
780
// state aligns with the desired state. See that the ownerRef was set when the Deployment was created.
777
781
Owns (& appsv1.Deployment {}).
778
- WithEventFilter (pred ).
782
+ WithEventFilter (predicate. GenerationChangedPredicate {} ).
779
783
Complete (r )
780
784
}
0 commit comments