From e2b640ef4e8431fb942d41835cafe1be4d735ce5 Mon Sep 17 00:00:00 2001 From: Felix Breuer Date: Wed, 22 Mar 2023 10:26:04 +0100 Subject: [PATCH 1/4] only trigger lbm update on generation changed Signed-off-by: Felix Breuer --- .../loadbalancermachine/loadbalancermachine_controller.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go b/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go index 86da9316..8c97f673 100644 --- a/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go +++ b/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go @@ -35,6 +35,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" + "sigs.k8s.io/controller-runtime/pkg/predicate" ) const ( @@ -222,6 +223,7 @@ func (r *LoadBalancerMachineReconciler) SetupWithManager(mgr ctrl.Manager) error WithOptions(controller.Options{ MaxConcurrentReconciles: r.WorkerCount, }). + WithEventFilter(predicate.GenerationChangedPredicate{}). Complete(r) } From 98678468f243b00d20d5cdd6b217cc8333d8c69c Mon Sep 17 00:00:00 2001 From: Felix Breuer Date: Thu, 23 Mar 2023 15:11:34 +0100 Subject: [PATCH 2/4] add default requeue time to check for openstack resources Signed-off-by: Felix Breuer --- .../loadbalancermachine/loadbalancermachine_controller.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go b/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go index 8c97f673..85205a7c 100644 --- a/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go +++ b/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go @@ -42,6 +42,7 @@ const ( // ServiceFinalizer Name of finalizer for controller4 ServiceFinalizer = "yawol.stackit.cloud/controller4" DefaultRequeueTime = 10 * time.Millisecond + OpenstackRequeueTime = 1 * time.Minute ServiceAccountNameAnnotation = "kubernetes.io/service-account.name" ) @@ -174,7 +175,7 @@ func (r *LoadBalancerMachineReconciler) Reconcile(ctx context.Context, req ctrl. // check if reconcile is needed if !helper.LoadBalancerMachineOpenstackReconcileIsNeeded(loadBalancerMachine) { - return ctrl.Result{}, nil + return ctrl.Result{RequeueAfter: OpenstackRequeueTime}, nil } if err := r.reconcilePort(ctx, osClient, req, loadBalancerMachine, loadbalancer); err != nil { @@ -202,7 +203,7 @@ func (r *LoadBalancerMachineReconciler) Reconcile(ctx context.Context, req ctrl. return ctrl.Result{}, err } - return ctrl.Result{}, nil + return ctrl.Result{RequeueAfter: OpenstackRequeueTime}, nil } // SetupWithManager is used by kubebuilder to init the controller loop From bac796f85427175b912820a13e1b9b7fd7a9d1b2 Mon Sep 17 00:00:00 2001 From: Felix Breuer Date: Mon, 27 Mar 2023 14:36:22 +0200 Subject: [PATCH 3/4] reconfigure openstack requeue time Signed-off-by: Felix Breuer --- .../loadbalancermachine_controller.go | 8 +++----- internal/helper/const.go | 11 ++++++----- internal/helper/loadbalancer.go | 3 ++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go b/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go index 85205a7c..7e3ae52c 100644 --- a/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go +++ b/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go @@ -41,8 +41,6 @@ import ( const ( // ServiceFinalizer Name of finalizer for controller4 ServiceFinalizer = "yawol.stackit.cloud/controller4" - DefaultRequeueTime = 10 * time.Millisecond - OpenstackRequeueTime = 1 * time.Minute ServiceAccountNameAnnotation = "kubernetes.io/service-account.name" ) @@ -105,7 +103,7 @@ func (r *LoadBalancerMachineReconciler) Reconcile(ctx context.Context, req ctrl. return ctrl.Result{}, err } if requeue { - return ctrl.Result{RequeueAfter: DefaultRequeueTime}, nil + return ctrl.Result{RequeueAfter: helper.DefaultRequeueTime}, nil } // delete k8s resources @@ -175,7 +173,7 @@ func (r *LoadBalancerMachineReconciler) Reconcile(ctx context.Context, req ctrl. // check if reconcile is needed if !helper.LoadBalancerMachineOpenstackReconcileIsNeeded(loadBalancerMachine) { - return ctrl.Result{RequeueAfter: OpenstackRequeueTime}, nil + return ctrl.Result{RequeueAfter: helper.OpenstackReconcileTime}, nil } if err := r.reconcilePort(ctx, osClient, req, loadBalancerMachine, loadbalancer); err != nil { @@ -203,7 +201,7 @@ func (r *LoadBalancerMachineReconciler) Reconcile(ctx context.Context, req ctrl. return ctrl.Result{}, err } - return ctrl.Result{RequeueAfter: OpenstackRequeueTime}, nil + return ctrl.Result{RequeueAfter: helper.OpenstackReconcileTime}, nil } // SetupWithManager is used by kubebuilder to init the controller loop diff --git a/internal/helper/const.go b/internal/helper/const.go index 758a9394..69d2cdff 100644 --- a/internal/helper/const.go +++ b/internal/helper/const.go @@ -3,9 +3,10 @@ package helper import "time" const ( - DefaultRequeueTime = 10 * time.Millisecond - RevisionAnnotation = "loadbalancer.yawol.stackit.cloud/revision" - HashLabel = "lbm-template-hash" - LoadBalancerKind = "LoadBalancer" - VRRPInstanceName = "ENVOY" + OpenstackReconcileTime = 5 * time.Minute + DefaultRequeueTime = 10 * time.Millisecond + RevisionAnnotation = "loadbalancer.yawol.stackit.cloud/revision" + HashLabel = "lbm-template-hash" + LoadBalancerKind = "LoadBalancer" + VRRPInstanceName = "ENVOY" ) diff --git a/internal/helper/loadbalancer.go b/internal/helper/loadbalancer.go index 394a50ea..938a7f54 100644 --- a/internal/helper/loadbalancer.go +++ b/internal/helper/loadbalancer.go @@ -28,7 +28,8 @@ func LoadBalancerOpenstackReconcileIsNeeded(lb *yawolv1beta1.LoadBalancer) bool } // lastOpenstackReconcile is older than 5 min - if lb.Status.LastOpenstackReconcile.Before(&metaV1.Time{Time: time.Now().Add(-5 * time.Minute)}) { + // add some seconds in order to be sure it reconciles + if lb.Status.LastOpenstackReconcile.Before(&metaV1.Time{Time: time.Now().Add(-OpenstackReconcileTime).Add(2 * time.Second)}) { return true } From 35cabcad606ce8a8744b54247450b3c00136a5c7 Mon Sep 17 00:00:00 2001 From: Felix Breuer Date: Wed, 29 Mar 2023 16:28:01 +0200 Subject: [PATCH 4/4] use openstackreconcile constant for lbm reconcile Signed-off-by: Felix Breuer --- internal/helper/loadbalancermachine.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/helper/loadbalancermachine.go b/internal/helper/loadbalancermachine.go index ed48a62c..66a6197c 100644 --- a/internal/helper/loadbalancermachine.go +++ b/internal/helper/loadbalancermachine.go @@ -24,7 +24,8 @@ func LoadBalancerMachineOpenstackReconcileIsNeeded(lbm *yawolv1beta1.LoadBalance } // lastOpenstackReconcile is older than 5 min - if lbm.Status.LastOpenstackReconcile.Before(&metaV1.Time{Time: time.Now().Add(-5 * time.Minute)}) { + // add some seconds in order to be sure it reconciles + if lbm.Status.LastOpenstackReconcile.Before(&metaV1.Time{Time: time.Now().Add(-OpenstackReconcileTime).Add(2 * time.Second)}) { return true }