Skip to content

Commit

Permalink
fix: return ASAP after handling finalizer (#940)
Browse files Browse the repository at this point in the history
Signed-off-by: drivebyer <[email protected]>
  • Loading branch information
drivebyer authored May 22, 2024
1 parent 39ed5d0 commit d15c80e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
10 changes: 6 additions & 4 deletions controllers/redis_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ func (r *RedisReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
}
return ctrl.Result{}, err
}
if instance.ObjectMeta.GetDeletionTimestamp() != nil {
if err = k8sutils.HandleRedisFinalizer(r.Client, r.K8sClient, r.Log, instance); err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
}
if _, found := instance.ObjectMeta.GetAnnotations()["redis.opstreelabs.in/skip-reconcile"]; found {
reqLogger.Info("Found annotations redis.opstreelabs.in/skip-reconcile, so skipping reconcile")
return ctrl.Result{RequeueAfter: time.Second * 10}, nil
}
if err = k8sutils.HandleRedisFinalizer(r.Client, r.K8sClient, r.Log, instance); err != nil {
return ctrl.Result{}, err
}

if err = k8sutils.AddFinalizer(instance, k8sutils.RedisFinalizer, r.Client); err != nil {
return ctrl.Result{}, err
}
Expand Down
13 changes: 7 additions & 6 deletions controllers/rediscluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,22 @@ func (r *RedisClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
}
return ctrl.Result{}, err
}
instance.SetDefault()

if instance.ObjectMeta.GetDeletionTimestamp() != nil {
if err = k8sutils.HandleRedisClusterFinalizer(r.Client, r.K8sClient, r.Log, instance); err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
}
if _, found := instance.ObjectMeta.GetAnnotations()["rediscluster.opstreelabs.in/skip-reconcile"]; found {
reqLogger.Info("Found annotations rediscluster.opstreelabs.in/skip-reconcile, so skipping reconcile")
return ctrl.Result{RequeueAfter: time.Second * 10}, nil
}
instance.SetDefault()

leaderReplicas := instance.Spec.GetReplicaCounts("leader")
followerReplicas := instance.Spec.GetReplicaCounts("follower")
totalReplicas := leaderReplicas + followerReplicas

if err = k8sutils.HandleRedisClusterFinalizer(r.Client, r.K8sClient, r.Log, instance); err != nil {
return ctrl.Result{}, err
}

if err = k8sutils.AddFinalizer(instance, k8sutils.RedisClusterFinalizer, r.Client); err != nil {
return ctrl.Result{}, err
}
Expand Down
11 changes: 6 additions & 5 deletions controllers/redisreplication_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ func (r *RedisReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Req
}
return ctrl.Result{}, err
}

if instance.ObjectMeta.GetDeletionTimestamp() != nil {
if err = k8sutils.HandleRedisReplicationFinalizer(r.Client, r.K8sClient, r.Log, instance); err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
}
if _, found := instance.ObjectMeta.GetAnnotations()["redisreplication.opstreelabs.in/skip-reconcile"]; found {
reqLogger.Info("Found annotations redisreplication.opstreelabs.in/skip-reconcile, so skipping reconcile")
return ctrl.Result{RequeueAfter: time.Second * 10}, nil
Expand All @@ -49,10 +54,6 @@ func (r *RedisReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Req
followerReplicas := instance.Spec.GetReplicationCounts("replication") - leaderReplicas
totalReplicas := leaderReplicas + followerReplicas

if err = k8sutils.HandleRedisReplicationFinalizer(r.Client, r.K8sClient, r.Log, instance); err != nil {
return ctrl.Result{}, err
}

if err = k8sutils.AddFinalizer(instance, k8sutils.RedisReplicationFinalizer, r.Client); err != nil {
return ctrl.Result{}, err
}
Expand Down
10 changes: 6 additions & 4 deletions controllers/redissentinel_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ func (r *RedisSentinelReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}
return ctrl.Result{}, err
}
if instance.ObjectMeta.GetDeletionTimestamp() != nil {
if err = k8sutils.HandleRedisSentinelFinalizer(r.Client, r.Log, instance); err != nil {
return ctrl.Result{RequeueAfter: time.Second * 60}, err
}
return ctrl.Result{}, nil
}

if _, found := instance.ObjectMeta.GetAnnotations()["redissentinel.opstreelabs.in/skip-reconcile"]; found {
reqLogger.Info("Found annotations redissentinel.opstreelabs.in/skip-reconcile, so skipping reconcile")
Expand All @@ -48,10 +54,6 @@ func (r *RedisSentinelReconciler) Reconcile(ctx context.Context, req ctrl.Reques
// Get total Sentinel Replicas
// sentinelReplicas := instance.Spec.GetSentinelCounts("sentinel")

if err = k8sutils.HandleRedisSentinelFinalizer(r.Client, r.Log, instance); err != nil {
return ctrl.Result{RequeueAfter: time.Second * 60}, err
}

if err = k8sutils.AddFinalizer(instance, k8sutils.RedisSentinelFinalizer, r.Client); err != nil {
return ctrl.Result{RequeueAfter: time.Second * 60}, err
}
Expand Down

0 comments on commit d15c80e

Please sign in to comment.