Skip to content

Commit

Permalink
add IsRedisReplicationReady()
Browse files Browse the repository at this point in the history
Signed-off-by: wkd-woo <[email protected]>
  • Loading branch information
wkd-woo committed Mar 18, 2024
1 parent 843da9f commit 49c3b0d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions k8sutils/redis-replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{})
Expand Down

0 comments on commit 49c3b0d

Please sign in to comment.