From 49c3b0d6f6513bfd4437df5eab1abef20f99fe6c Mon Sep 17 00:00:00 2001 From: wkd-woo Date: Mon, 18 Mar 2024 15:31:57 +0900 Subject: [PATCH] add IsRedisReplicationReady() Signed-off-by: wkd-woo --- k8sutils/redis-replication.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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{})