Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test : Add redis_test.go #702

Merged
merged 7 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions k8sutils/cluster-scaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
if *cr.Spec.ClusterVersion == "v7" {
cmd = append(cmd, getRedisHostname(transferPOD, cr, "leader")+":6379")
} else {
cmd = append(cmd, getRedisServerIP(transferPOD)+":6379")
cmd = append(cmd, getRedisServerIP(client, logger, transferPOD)+":6379")

Check warning on line 35 in k8sutils/cluster-scaling.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/cluster-scaling.go#L35

Added line #L35 was not covered by tests
}

if cr.Spec.KubernetesConfig.ExistingPasswordSecret != nil {
Expand Down Expand Up @@ -71,7 +71,7 @@
logger.V(1).Info("Skipped the execution of", "Cmd", cmd)
return
}
executeCommand(cr, cmd, cr.ObjectMeta.Name+"-leader-0")
executeCommand(client, logger, cr, cmd, cr.ObjectMeta.Name+"-leader-0")

Check warning on line 74 in k8sutils/cluster-scaling.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/cluster-scaling.go#L74

Added line #L74 was not covered by tests
}

func getRedisClusterSlots(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster, nodeID string) string {
Expand Down Expand Up @@ -153,7 +153,7 @@
if *cr.Spec.ClusterVersion == "v7" {
cmd = append(cmd, getRedisHostname(pod, cr, "leader")+":6379")
} else {
cmd = append(cmd, getRedisServerIP(pod)+":6379")
cmd = append(cmd, getRedisServerIP(client, logger, pod)+":6379")

Check warning on line 156 in k8sutils/cluster-scaling.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/cluster-scaling.go#L156

Added line #L156 was not covered by tests
}

cmd = append(cmd, "--cluster-use-empty-masters")
Expand All @@ -170,7 +170,7 @@
cmd = append(cmd, getRedisTLSArgs(cr.Spec.TLS, cr.ObjectMeta.Name+"-leader-0")...)

logger.V(1).Info("Redis cluster rebalance command is", "Command", cmd)
executeCommand(cr, cmd, cr.ObjectMeta.Name+"-leader-1")
executeCommand(client, logger, cr, cmd, cr.ObjectMeta.Name+"-leader-1")

Check warning on line 173 in k8sutils/cluster-scaling.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/cluster-scaling.go#L173

Added line #L173 was not covered by tests
}

func CheckIfEmptyMasters(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster) {
Expand Down Expand Up @@ -205,7 +205,7 @@
if *cr.Spec.ClusterVersion == "v7" {
cmd = append(cmd, getRedisHostname(pod, cr, "leader")+":6379")
} else {
cmd = append(cmd, getRedisServerIP(pod)+":6379")
cmd = append(cmd, getRedisServerIP(client, logger, pod)+":6379")

Check warning on line 208 in k8sutils/cluster-scaling.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/cluster-scaling.go#L208

Added line #L208 was not covered by tests
}

if cr.Spec.KubernetesConfig.ExistingPasswordSecret != nil {
Expand All @@ -220,7 +220,7 @@
cmd = append(cmd, getRedisTLSArgs(cr.Spec.TLS, cr.ObjectMeta.Name+"-leader-0")...)

logger.V(1).Info("Redis cluster rebalance command is", "Command", cmd)
executeCommand(cr, cmd, cr.ObjectMeta.Name+"-leader-1")
executeCommand(client, logger, cr, cmd, cr.ObjectMeta.Name+"-leader-1")

Check warning on line 223 in k8sutils/cluster-scaling.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/cluster-scaling.go#L223

Added line #L223 was not covered by tests
}

// Add redis cluster node would add a node to the existing redis cluster using redis-cli
Expand All @@ -243,8 +243,8 @@
cmd = append(cmd, getRedisHostname(newPod, cr, "leader")+":6379")
cmd = append(cmd, getRedisHostname(existingPod, cr, "leader")+":6379")
} else {
cmd = append(cmd, getRedisServerIP(newPod)+":6379")
cmd = append(cmd, getRedisServerIP(existingPod)+":6379")
cmd = append(cmd, getRedisServerIP(client, logger, newPod)+":6379")
cmd = append(cmd, getRedisServerIP(client, logger, existingPod)+":6379")

Check warning on line 247 in k8sutils/cluster-scaling.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/cluster-scaling.go#L246-L247

Added lines #L246 - L247 were not covered by tests
}

if cr.Spec.KubernetesConfig.ExistingPasswordSecret != nil {
Expand All @@ -259,7 +259,7 @@
cmd = append(cmd, getRedisTLSArgs(cr.Spec.TLS, cr.ObjectMeta.Name+"-leader-0")...)

logger.V(1).Info("Redis cluster add-node command is", "Command", cmd)
executeCommand(cr, cmd, cr.ObjectMeta.Name+"-leader-0")
executeCommand(client, logger, cr, cmd, cr.ObjectMeta.Name+"-leader-0")

Check warning on line 262 in k8sutils/cluster-scaling.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/cluster-scaling.go#L262

Added line #L262 was not covered by tests
}

// getAttachedFollowerNodeIDs would return a slice of redis followers attached to a redis leader
Expand Down Expand Up @@ -323,14 +323,14 @@
if *cr.Spec.ClusterVersion == "v7" {
cmd = append(cmd, getRedisHostname(existingPod, cr, "leader")+":6379")
} else {
cmd = append(cmd, getRedisServerIP(existingPod)+":6379")
cmd = append(cmd, getRedisServerIP(client, logger, existingPod)+":6379")

Check warning on line 326 in k8sutils/cluster-scaling.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/cluster-scaling.go#L326

Added line #L326 was not covered by tests
}

for _, followerNodeID := range followerNodeIDs {

cmd = append(cmd, followerNodeID)
logger.V(1).Info("Redis cluster follower remove command is", "Command", cmd)
executeCommand(cr, cmd, cr.ObjectMeta.Name+"-leader-0")
executeCommand(client, logger, cr, cmd, cr.ObjectMeta.Name+"-leader-0")

Check warning on line 333 in k8sutils/cluster-scaling.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/cluster-scaling.go#L333

Added line #L333 was not covered by tests
cmd = cmd[:len(cmd)-1]
}
}
Expand All @@ -354,7 +354,7 @@
if *cr.Spec.ClusterVersion == "v7" {
cmd = append(cmd, getRedisHostname(existingPod, cr, "leader")+":6379")
} else {
cmd = append(cmd, getRedisServerIP(existingPod)+":6379")
cmd = append(cmd, getRedisServerIP(client, logger, existingPod)+":6379")

Check warning on line 357 in k8sutils/cluster-scaling.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/cluster-scaling.go#L357

Added line #L357 was not covered by tests
}

removePodNodeID := getRedisNodeID(ctx, client, logger, cr, removePod)
Expand All @@ -375,7 +375,7 @@
if getRedisClusterSlots(ctx, client, logger, cr, removePodNodeID) != "0" {
logger.V(1).Info("Skipping execution remove leader not empty", "cmd", cmd)
}
executeCommand(cr, cmd, cr.ObjectMeta.Name+"-leader-0")
executeCommand(client, logger, cr, cmd, cr.ObjectMeta.Name+"-leader-0")

Check warning on line 378 in k8sutils/cluster-scaling.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/cluster-scaling.go#L378

Added line #L378 was not covered by tests
}

// verifyLeaderPod return true if the pod is leader/master
Expand Down Expand Up @@ -415,7 +415,7 @@
if *cr.Spec.ClusterVersion == "v7" {
cmd = append(cmd, getRedisHostname(pod, cr, "leader")+":6379")
} else {
cmd = append(cmd, getRedisServerIP(pod)+":6379")
cmd = append(cmd, getRedisServerIP(client, logger, pod)+":6379")

Check warning on line 418 in k8sutils/cluster-scaling.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/cluster-scaling.go#L418

Added line #L418 was not covered by tests
}

if cr.Spec.KubernetesConfig.ExistingPasswordSecret != nil {
Expand All @@ -430,5 +430,5 @@
cmd = append(cmd, getRedisTLSArgs(cr.Spec.TLS, slavePodName)...)

logger.V(1).Info("Redis cluster failover command is", "Command", cmd)
executeCommand(cr, cmd, slavePodName)
executeCommand(client, logger, cr, cmd, slavePodName)

Check warning on line 433 in k8sutils/cluster-scaling.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/cluster-scaling.go#L433

Added line #L433 was not covered by tests
}
2 changes: 1 addition & 1 deletion k8sutils/redis-sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,6 @@
Namespace: replicationNamespace,
}

realMasterPodIP := getRedisServerIP(realMasterInfo)
realMasterPodIP := getRedisServerIP(client, logger, realMasterInfo)

Check warning on line 339 in k8sutils/redis-sentinel.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/redis-sentinel.go#L339

Added line #L339 was not covered by tests
return realMasterPodIP
}
Loading
Loading