Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only trigger lbm update on generation changed #141

Merged
merged 7 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ 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 (
// ServiceFinalizer Name of finalizer for controller4
ServiceFinalizer = "yawol.stackit.cloud/controller4"
DefaultRequeueTime = 10 * time.Millisecond
ServiceAccountNameAnnotation = "kubernetes.io/service-account.name"
)

Expand Down Expand Up @@ -103,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
Expand Down Expand Up @@ -173,7 +173,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: helper.OpenstackReconcileTime}, nil
}

if err := r.reconcilePort(ctx, osClient, req, loadBalancerMachine, loadbalancer); err != nil {
Expand Down Expand Up @@ -201,7 +201,7 @@ func (r *LoadBalancerMachineReconciler) Reconcile(ctx context.Context, req ctrl.
return ctrl.Result{}, err
}

return ctrl.Result{}, nil
return ctrl.Result{RequeueAfter: helper.OpenstackReconcileTime}, nil
}

// SetupWithManager is used by kubebuilder to init the controller loop
Expand All @@ -222,6 +222,7 @@ func (r *LoadBalancerMachineReconciler) SetupWithManager(mgr ctrl.Manager) error
WithOptions(controller.Options{
MaxConcurrentReconciles: r.WorkerCount,
}).
WithEventFilter(predicate.GenerationChangedPredicate{}).
Complete(r)
}

Expand Down
11 changes: 6 additions & 5 deletions internal/helper/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
3 changes: 2 additions & 1 deletion internal/helper/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion internal/helper/loadbalancermachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down