Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
  • Loading branch information
shubham-cmyk committed Nov 11, 2023
1 parent 2b6ad4b commit 34413cd
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion mocks/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func CreateFakeClientWithPodIPs(cr *redisv1beta2.RedisCluster) *fake.Clientset {
}
for i := 0; i < int(followerReplicas); i++ {
podName := cr.ObjectMeta.Name + "-follower-" + strconv.Itoa(i)
// Adjust the index to place follower pods after leader pods
pods[i+int(leaderReplicas)] = &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: podName,
Expand All @@ -63,3 +62,46 @@ func CreateFakeClientWithPodIPs(cr *redisv1beta2.RedisCluster) *fake.Clientset {

return fake.NewSimpleClientset(pods...)
}

func CreateFakeClientWithSecrets(cr *redisv1beta2.RedisCluster, secretName, secretKey, secretValue string) *fake.Clientset {
leaderReplicas := cr.Spec.GetReplicaCounts("leader")
followerReplicas := cr.Spec.GetReplicaCounts("follower")
pods := make([]runtime.Object, leaderReplicas+followerReplicas)

for i := 0; i < int(leaderReplicas); i++ {
podName := cr.ObjectMeta.Name + "-leader-" + strconv.Itoa(i)
pods[i] = &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: podName,
Namespace: cr.Namespace,
},
Status: corev1.PodStatus{
PodIP: fmt.Sprintf("192.168.1.%d", i+1),
},
}
}
for i := 0; i < int(followerReplicas); i++ {
podName := cr.ObjectMeta.Name + "-follower-" + strconv.Itoa(i)
pods[i+int(leaderReplicas)] = &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: podName,
Namespace: cr.Namespace,
},
Status: corev1.PodStatus{
PodIP: fmt.Sprintf("192.168.2.%d", i+1),
},
}
}

secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: secretName,
Namespace: cr.Namespace,
},
Data: map[string][]byte{
secretKey: []byte(secretValue),
},
}

return fake.NewSimpleClientset(append(pods, secret)...)
}

0 comments on commit 34413cd

Please sign in to comment.