Skip to content

Commit

Permalink
fix: sentinel should not reconcile until replication cluster ready
Browse files Browse the repository at this point in the history
Signed-off-by: drivebyer <[email protected]>
  • Loading branch information
drivebyer committed Jun 4, 2024
1 parent a207422 commit e48c96a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
16 changes: 2 additions & 14 deletions controllers/redissentinel_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/util/workqueue"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
)

// RedisSentinelReconciler reconciles a RedisSentinel object
Expand Down Expand Up @@ -80,22 +77,13 @@ func (r *RedisSentinelReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return ctrl.Result{}, err
}

reqLogger.Info("Will reconcile after 600 seconds")
return ctrl.Result{RequeueAfter: time.Second * 600}, nil
reqLogger.Info("Will reconcile after 10 seconds")
return ctrl.Result{RequeueAfter: time.Second * 10}, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *RedisSentinelReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&redisv1beta2.RedisSentinel{}).
Watches(&redisv1beta2.RedisReplication{}, &handler.Funcs{
CreateFunc: nil,
UpdateFunc: func(ctx context.Context, event event.UpdateEvent, limitingInterface workqueue.RateLimitingInterface) {
_ = event.ObjectNew.GetName()
_ = event.ObjectNew.GetNamespace()
},
DeleteFunc: nil,
GenericFunc: nil,
}).
Complete(r)
}
6 changes: 6 additions & 0 deletions k8sutils/redis-replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ func IsRedisReplicationReady(ctx context.Context, logger logr.Logger, client kub
if sts.Status.ReadyReplicas != *sts.Spec.Replicas {
return false
}
if sts.Status.ObservedGeneration != sts.Generation {
return false

Check warning on line 214 in k8sutils/redis-replication.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/redis-replication.go#L213-L214

Added lines #L213 - L214 were not covered by tests
}
if sts.Status.UpdateRevision != sts.Status.CurrentRevision {
return false

Check warning on line 217 in k8sutils/redis-replication.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/redis-replication.go#L216-L217

Added lines #L216 - L217 were not covered by tests
}
// Enhanced check: When the pod is ready, it may not have been
// created as part of a replication cluster, so we should verify
// whether there is an actual master node.
Expand Down

0 comments on commit e48c96a

Please sign in to comment.