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

[GCS FT] Redis e2e cleanup check #2773

Merged
merged 3 commits into from
Jan 20, 2025
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
2 changes: 1 addition & 1 deletion ray-operator/controllers/ray/raycluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ func (r *RayClusterReconciler) buildRedisCleanupJob(ctx context.Context, instanc
"redis_address = os.getenv('RAY_REDIS_ADDRESS', '').split(',')[0]; " +
"redis_address = redis_address if '://' in redis_address else 'redis://' + redis_address; " +
"parsed = urlparse(redis_address); " +
"sys.exit(1) if not cleanup_redis_storage(host=parsed.hostname, port=parsed.port, password=os.getenv('REDIS_PASSWORD', parsed.password), use_ssl=parsed.scheme=='rediss', storage_namespace=os.getenv('RAY_external_storage_namespace')) else None\"",
"sys.exit(1) if not cleanup_redis_storage(host=parsed.hostname, port=parsed.port, password=os.getenv('REDIS_PASSWORD', parsed.password or ''), use_ssl=parsed.scheme=='rediss', storage_namespace=os.getenv('RAY_external_storage_namespace')) else None\"",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind explaining the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the change, we could pass None to the password parameter and resulting in this error:
image

}

// Disable liveness and readiness probes because the Job will not launch processes like Raylet and GCS.
Expand Down
13 changes: 11 additions & 2 deletions ray-operator/test/e2e/raycluster_gcsft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e

import (
"testing"
"time"

. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -81,7 +82,8 @@ func TestGcsFaultToleranceOptions(t *testing.T) {
g := NewWithT(t)
namespace := test.NewTestNamespace()

deployRedis(test, namespace.Name, tc.redisPassword)
checkRedisDBSize := deployRedis(test, namespace.Name, tc.redisPassword)
defer g.Eventually(checkRedisDBSize, time.Second*30, time.Second).Should(BeEquivalentTo("0"))

if tc.createSecret {
test.T().Logf("Creating Redis password secret")
Expand Down Expand Up @@ -116,6 +118,9 @@ func TestGcsFaultToleranceOptions(t *testing.T) {
} else {
g.Expect(utils.EnvVarExists(utils.REDIS_PASSWORD, headPod.Spec.Containers[utils.RayContainerIndex].Env)).Should(BeTrue())
}

err = test.Client().Ray().RayV1().RayClusters(namespace.Name).Delete(test.Ctx(), rayCluster.Name, metav1.DeleteOptions{})
g.Expect(err).NotTo(HaveOccurred())
})
}
}
Expand Down Expand Up @@ -171,7 +176,8 @@ func TestGcsFaultToleranceAnnotations(t *testing.T) {
redisPassword = tc.redisPasswordInRayStartParams
}

deployRedis(test, namespace.Name, redisPassword)
checkRedisDBSize := deployRedis(test, namespace.Name, redisPassword)
defer g.Eventually(checkRedisDBSize, time.Second*30, time.Second).Should(BeEquivalentTo("0"))

// Prepare RayCluster ApplyConfiguration
podTemplateAC := headPodTemplateApplyConfiguration()
Expand Down Expand Up @@ -224,6 +230,9 @@ func TestGcsFaultToleranceAnnotations(t *testing.T) {
} else {
g.Expect(utils.EnvVarExists(utils.REDIS_PASSWORD, headPod.Spec.Containers[utils.RayContainerIndex].Env)).Should(BeTrue())
}

err = test.Client().Ray().RayV1().RayClusters(namespace.Name).Delete(test.Ctx(), rayCluster.Name, metav1.DeleteOptions{})
g.Expect(err).NotTo(HaveOccurred())
})
}
}
28 changes: 13 additions & 15 deletions ray-operator/test/e2e/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package e2e

import (
"embed"
"strings"

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
appsv1ac "k8s.io/client-go/applyconfigurations/apps/v1"
corev1ac "k8s.io/client-go/applyconfigurations/core/v1"
metav1ac "k8s.io/client-go/applyconfigurations/meta/v1"

rayv1ac "github.com/ray-project/kuberay/ray-operator/pkg/client/applyconfiguration/ray/v1"
. "github.com/ray-project/kuberay/ray-operator/test/support"
Expand Down Expand Up @@ -177,26 +176,20 @@ func jobSubmitterPodTemplateApplyConfiguration() *corev1ac.PodTemplateSpecApplyC
}))))
}

func deployRedis(t Test, namespace string, password string) {
func deployRedis(t Test, namespace string, password string) func() string {
redisContainer := corev1ac.Container().WithName("redis").WithImage("redis:7.4").
WithPorts(corev1ac.ContainerPort().WithContainerPort(6379))
dbSizeCmd := []string{"redis-cli", "--no-auth-warning", "DBSIZE"}
if password != "" {
redisContainer.WithCommand("redis-server", "--requirepass", password)
dbSizeCmd = []string{"redis-cli", "--no-auth-warning", "-a", password, "DBSIZE"}
}

_, err := t.Client().Core().AppsV1().Deployments(namespace).Apply(
pod, err := t.Client().Core().CoreV1().Pods(namespace).Apply(
t.Ctx(),
appsv1ac.Deployment("redis", namespace).
WithSpec(appsv1ac.DeploymentSpec().
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for us to use Deployment for Redis in tests. just use Pod instead.

WithReplicas(1).
WithSelector(metav1ac.LabelSelector().WithMatchLabels(map[string]string{"app": "redis"})).
WithTemplate(corev1ac.PodTemplateSpec().
WithLabels(map[string]string{"app": "redis"}).
WithSpec(corev1ac.PodSpec().
WithContainers(redisContainer),
),
),
),
corev1ac.Pod("redis", namespace).
WithLabels(map[string]string{"app": "redis"}).
WithSpec(corev1ac.PodSpec().WithContainers(redisContainer)),
TestApplyOptions,
)
assert.NoError(t.T(), err)
Expand All @@ -213,4 +206,9 @@ func deployRedis(t Test, namespace string, password string) {
TestApplyOptions,
)
assert.NoError(t.T(), err)

return func() string {
stdout, stderr := ExecPodCmd(t, pod, "redis", dbSizeCmd)
return strings.TrimSpace(stdout.String() + stderr.String())
}
}
Loading