diff --git a/controllers/redis_controller.go b/controllers/redis_controller.go index 991c18d48..2ac11f27e 100644 --- a/controllers/redis_controller.go +++ b/controllers/redis_controller.go @@ -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 } diff --git a/controllers/rediscluster_controller.go b/controllers/rediscluster_controller.go index d3f6e0df6..fc280c916 100644 --- a/controllers/rediscluster_controller.go +++ b/controllers/rediscluster_controller.go @@ -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 } diff --git a/controllers/redisreplication_controller.go b/controllers/redisreplication_controller.go index 9459785db..0473d412a 100644 --- a/controllers/redisreplication_controller.go +++ b/controllers/redisreplication_controller.go @@ -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 @@ -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 } diff --git a/controllers/redissentinel_controller.go b/controllers/redissentinel_controller.go index f817abccb..d660e1c12 100644 --- a/controllers/redissentinel_controller.go +++ b/controllers/redissentinel_controller.go @@ -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") @@ -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 }