Skip to content

Commit e4faaeb

Browse files
fix: Recover redisreplication from master pod deletion without sentinel(#1449)
* Recover from orphaned master Signed-off-by: David Caputo <[email protected]> * Fix linting error Signed-off-by: David Caputo <[email protected]> * fix lint Signed-off-by: yangw <[email protected]> --------- Signed-off-by: David Caputo <[email protected]> Signed-off-by: yangw <[email protected]> Co-authored-by: yangw <[email protected]>
1 parent 809d48e commit e4faaeb

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

internal/controller/redisreplication/redisreplication_controller.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,22 @@ func (r *Reconciler) reconcileRedis(ctx context.Context, instance *rrvb2.RedisRe
156156
if err := k8sutils.CreateMasterSlaveReplication(ctx, r.K8sClient, instance, masterNodes, realMaster); err != nil {
157157
return intctrlutil.RequeueAfter(ctx, time.Second*60, "")
158158
}
159+
} else if len(masterNodes) == 1 && len(slaveNodes) > 0 {
160+
realMaster = masterNodes[0]
161+
currentRealMaster := k8sutils.GetRedisReplicationRealMaster(ctx, r.K8sClient, instance, masterNodes)
162+
163+
if currentRealMaster == "" {
164+
log.FromContext(ctx).Info("Detected disconnected slaves, reconfiguring replication",
165+
"master", realMaster, "slaves", slaveNodes)
166+
167+
allPods := append(masterNodes, slaveNodes...)
168+
if err := k8sutils.CreateMasterSlaveReplication(ctx, r.K8sClient, instance, allPods, realMaster); err != nil {
169+
log.FromContext(ctx).Error(err, "Failed to reconfigure master-slave replication",
170+
"master", realMaster, "slaves", slaveNodes)
171+
return intctrlutil.RequeueAfter(ctx, time.Second*60, "")
172+
}
173+
log.FromContext(ctx).Info("Successfully reconfigured slave replication")
174+
}
159175
}
160176

161177
monitoring.RedisReplicationReplicasSizeMismatch.WithLabelValues(instance.Namespace, instance.Name).Set(0)

0 commit comments

Comments
 (0)