Skip to content

Commit

Permalink
fix: only reconcile if generation changes (#163)
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Plant <[email protected]>
  • Loading branch information
pl4nty authored Oct 13, 2024
1 parent fa0f650 commit 3eec298
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/controller/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"

gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
)
Expand Down Expand Up @@ -332,9 +333,9 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
})
if err != nil {
if strings.Contains(err.Error(), "429 Too Many Requests") {
log.Error(err, "Rate limited, requeueing after 10 minutes")
log.Error(err, "Rate limited, requeueing after 5 minutes")
return ctrl.Result{
RequeueAfter: time.Minute * 10, // https://developers.cloudflare.com/fundamentals/api/reference/limits/
RequeueAfter: time.Minute * 5, // https://developers.cloudflare.com/fundamentals/api/reference/limits/
}, nil
} else {
return ctrl.Result{}, err
Expand Down Expand Up @@ -667,8 +668,10 @@ func imageForGateway() (string, error) {
// Note that the Deployment will be also watched in order to ensure its
// desirable state on the cluster
func (r *GatewayReconciler) SetupWithManager(mgr ctrl.Manager) error {
pred := predicate.GenerationChangedPredicate{}
return ctrl.NewControllerManagedBy(mgr).
For(&gatewayv1.Gateway{}).
Owns(&appsv1.Deployment{}).
WithEventFilter(pred).
Complete(r)
}
3 changes: 3 additions & 0 deletions internal/controller/gatewayclass_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"

gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
)
Expand Down Expand Up @@ -101,11 +102,13 @@ func (r *GatewayClassReconciler) Reconcile(ctx context.Context, req ctrl.Request

// SetupWithManager sets up the controller with the Manager.
func (r *GatewayClassReconciler) SetupWithManager(mgr ctrl.Manager) error {
pred := predicate.GenerationChangedPredicate{}
return ctrl.NewControllerManagedBy(mgr).
For(&gatewayv1.GatewayClass{
Spec: gatewayv1.GatewayClassSpec{
ControllerName: "github.com/pl4nty/cloudflare-kubernetes-gateway",
},
}).
WithEventFilter(pred).
Complete(r)
}
3 changes: 3 additions & 0 deletions internal/controller/httproute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"

gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
)
Expand Down Expand Up @@ -283,8 +284,10 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (

// SetupWithManager sets up the controller with the Manager.
func (r *HTTPRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
pred := predicate.GenerationChangedPredicate{}
return ctrl.NewControllerManagedBy(mgr).
For(&gatewayv1.HTTPRoute{}).
WithEventFilter(pred).
Complete(r)
}

Expand Down

0 comments on commit 3eec298

Please sign in to comment.