diff --git a/k8sutils/redis-replication.go b/k8sutils/redis-replication.go index c03d3a103..774b8018f 100644 --- a/k8sutils/redis-replication.go +++ b/k8sutils/redis-replication.go @@ -2,6 +2,7 @@ package k8sutils import ( "context" + "sigs.k8s.io/controller-runtime/pkg/client" redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2" "github.com/OT-CONTAINER-KIT/redis-operator/pkg/util" @@ -209,6 +210,18 @@ func generateRedisReplicationInitContainerParams(cr *redisv1beta2.RedisReplicati return initcontainerProp } +func IsRedisReplicationReady(ctx context.Context, ki kubernetes.Interface, o *client.ObjectKey) bool { + // statefulset name the same as the redis replication name + sts, err := ki.AppsV1().StatefulSets(o.Namespace).Get(ctx, o.Name, metav1.GetOptions{}) + if err != nil { + return false + } + if sts.Status.ReadyReplicas != *sts.Spec.Replicas { + return false + } + return true +} + func updatePodLabel(ctx context.Context, cl kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisReplication, role string, nodes []string) error { for _, node := range nodes { pod, err := cl.CoreV1().Pods(cr.Namespace).Get(context.TODO(), node, metav1.GetOptions{})