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

refactor: add common AddFinalizer for all api #858

Merged
merged 2 commits into from
Apr 1, 2024
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
2 changes: 1 addition & 1 deletion controllers/redis_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (r *RedisReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
return ctrl.Result{}, err
}

if err = k8sutils.AddRedisFinalizer(instance, r.Client); err != nil {
if err = k8sutils.AddFinalizer(instance, k8sutils.RedisFinalizer, r.Client); err != nil {
return ctrl.Result{}, err
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/rediscluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (r *RedisClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
return ctrl.Result{}, err
}

if err = k8sutils.AddRedisClusterFinalizer(instance, r.Client); err != nil {
if err = k8sutils.AddFinalizer(instance, k8sutils.RedisClusterFinalizer, r.Client); err != nil {
return ctrl.Result{}, err
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/redisreplication_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (r *RedisReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Req
return ctrl.Result{}, err
}

if err = k8sutils.AddRedisReplicationFinalizer(instance, r.Client); err != nil {
if err = k8sutils.AddFinalizer(instance, k8sutils.RedisReplicationFinalizer, r.Client); err != nil {
return ctrl.Result{}, err
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/redissentinel_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *RedisSentinelReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return ctrl.Result{RequeueAfter: time.Second * 60}, err
}

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

Expand Down
35 changes: 4 additions & 31 deletions k8sutils/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,37 +92,10 @@ func HandleRedisSentinelFinalizer(ctrlclient client.Client, logger logr.Logger,
return nil
}

// AddRedisFinalizer add finalizer for graceful deletion
func AddRedisFinalizer(cr *redisv1beta2.Redis, cl client.Client) error {
if !controllerutil.ContainsFinalizer(cr, RedisFinalizer) {
controllerutil.AddFinalizer(cr, RedisFinalizer)
return cl.Update(context.TODO(), cr)
}
return nil
}

// AddRedisClusterFinalizer add finalizer for graceful deletion
func AddRedisClusterFinalizer(cr *redisv1beta2.RedisCluster, cl client.Client) error {
if !controllerutil.ContainsFinalizer(cr, RedisClusterFinalizer) {
controllerutil.AddFinalizer(cr, RedisClusterFinalizer)
return cl.Update(context.TODO(), cr)
}
return nil
}

// AddRedisReplicationFinalizer add finalizer for graceful deletion
func AddRedisReplicationFinalizer(cr *redisv1beta2.RedisReplication, cl client.Client) error {
if !controllerutil.ContainsFinalizer(cr, RedisReplicationFinalizer) {
controllerutil.AddFinalizer(cr, RedisReplicationFinalizer)
return cl.Update(context.TODO(), cr)
}
return nil
}

// AddRedisSentinelFinalizer add finalizer for graceful deletion
func AddRedisSentinelFinalizer(cr *redisv1beta2.RedisSentinel, cl client.Client) error {
if !controllerutil.ContainsFinalizer(cr, RedisSentinelFinalizer) {
controllerutil.AddFinalizer(cr, RedisSentinelFinalizer)
// AddFinalizer add finalizer for graceful deletion
func AddFinalizer(cr client.Object, finalizer string, cl client.Client) error {
if !controllerutil.ContainsFinalizer(cr, finalizer) {
controllerutil.AddFinalizer(cr, finalizer)
return cl.Update(context.TODO(), cr)
}
return nil
Expand Down
Loading
Loading