diff --git a/ray-operator/test/e2eautoscaler/raycluster_autoscaler_part2_test.go b/ray-operator/test/e2eautoscaler/raycluster_autoscaler_part2_test.go index afd2d60b16f..a29ab532197 100644 --- a/ray-operator/test/e2eautoscaler/raycluster_autoscaler_part2_test.go +++ b/ray-operator/test/e2eautoscaler/raycluster_autoscaler_part2_test.go @@ -32,7 +32,7 @@ func TestRayClusterAutoscalerV2IdleTimeout(t *testing.T) { timeoutBuffer := int32(30) // Additional wait time to allow for scale down operation // Script for creating detached actors to trigger autoscaling - scriptsAC := newConfigMap(namespace.Name, files(test, "create_detached_actor.py", "terminate_detached_actor.py")) + scriptsAC := newConfigMap(namespace.Name, Files(test, "create_detached_actor.py", "terminate_detached_actor.py")) scripts, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), scriptsAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", scripts.Namespace, scripts.Name) @@ -64,7 +64,7 @@ func TestRayClusterAutoscalerV2IdleTimeout(t *testing.T) { WithTemplate(tc.WorkerPodTemplateGetter()), ) rayClusterAC := rayv1ac.RayCluster("ray-cluster", namespace.Name). - WithSpec(apply(rayClusterSpecAC, mountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) + WithSpec(Apply(rayClusterSpecAC, MountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) rayCluster, err := test.Client().Ray().RayV1().RayClusters(namespace.Name).Apply(test.Ctx(), rayClusterAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) @@ -110,7 +110,7 @@ func TestRayClusterAutoscalerGPUNodesForCPUTasks(t *testing.T) { namespace := test.NewTestNamespace() // Scripts for creating and terminating detached actors to trigger autoscaling - scriptsAC := newConfigMap(namespace.Name, files(test, "create_detached_actor.py", "terminate_detached_actor.py")) + scriptsAC := newConfigMap(namespace.Name, Files(test, "create_detached_actor.py", "terminate_detached_actor.py")) scripts, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), scriptsAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", scripts.Namespace, scripts.Name) @@ -133,7 +133,7 @@ func TestRayClusterAutoscalerGPUNodesForCPUTasks(t *testing.T) { WithTemplate(tc.WorkerPodTemplateGetter())) rayClusterAC := rayv1ac.RayCluster("ray-cluster-gpu-for-cpu", namespace.Name). - WithSpec(apply(rayClusterSpecAC, mountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) + WithSpec(Apply(rayClusterSpecAC, MountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) rayCluster, err := test.Client().Ray().RayV1().RayClusters(namespace.Name).Apply(test.Ctx(), rayClusterAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) @@ -183,7 +183,7 @@ func TestRayClusterAutoscalerDoNotRemoveIdlesForPlacementGroup(t *testing.T) { // Create a namespace namespace := test.NewTestNamespace() - scriptsAC := newConfigMap(namespace.Name, files(test, "do_not_remove_idles_for_pg.py")) + scriptsAC := newConfigMap(namespace.Name, Files(test, "do_not_remove_idles_for_pg.py")) scripts, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), scriptsAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", scripts.Namespace, scripts.Name) @@ -213,7 +213,7 @@ func TestRayClusterAutoscalerDoNotRemoveIdlesForPlacementGroup(t *testing.T) { WithTemplate(workerTemplate)) rayClusterAC := rayv1ac.RayCluster("ray-cluster", namespace.Name). - WithSpec(apply(rayClusterSpecAC, mountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) + WithSpec(Apply(rayClusterSpecAC, MountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) rayCluster, err := test.Client().Ray().RayV1().RayClusters(namespace.Name).Apply(test.Ctx(), rayClusterAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) @@ -245,7 +245,7 @@ func TestRayClusterAutoscalerSDKRequestResources(t *testing.T) { namespace := test.NewTestNamespace() // Mount the call_request_resources.py script as a ConfigMap - scriptsAC := newConfigMap(namespace.Name, files(test, "call_request_resources.py")) + scriptsAC := newConfigMap(namespace.Name, Files(test, "call_request_resources.py")) scripts, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), scriptsAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", scripts.Namespace, scripts.Name) @@ -266,7 +266,7 @@ func TestRayClusterAutoscalerSDKRequestResources(t *testing.T) { WithRayStartParams(map[string]string{"num-cpus": "1"}). WithTemplate(tc.WorkerPodTemplateGetter())) rayClusterAC := rayv1ac.RayCluster("ray-cluster-sdk", namespace.Name). - WithSpec(apply(rayClusterSpecAC, mountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) + WithSpec(Apply(rayClusterSpecAC, MountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) rayCluster, err := test.Client().Ray().RayV1().RayClusters(namespace.Name).Apply(test.Ctx(), rayClusterAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) @@ -304,7 +304,7 @@ func TestRayClusterAutoscalerAddNewWorkerGroup(t *testing.T) { namespace := test.NewTestNamespace() // Mount the create_detached_actor.py and terminate_detached_actor.py scripts as a ConfigMap - scriptsAC := newConfigMap(namespace.Name, files(test, "create_detached_actor.py", "terminate_detached_actor.py")) + scriptsAC := newConfigMap(namespace.Name, Files(test, "create_detached_actor.py", "terminate_detached_actor.py")) scripts, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), scriptsAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", scripts.Namespace, scripts.Name) @@ -328,7 +328,7 @@ func TestRayClusterAutoscalerAddNewWorkerGroup(t *testing.T) { WithRayStartParams(map[string]string{"num-cpus": "1"}). WithTemplate(tc.WorkerPodTemplateGetter())) rayClusterAC := rayv1ac.RayCluster("ray-cluster", namespace.Name). - WithSpec(apply(rayClusterSpecAC, mountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) + WithSpec(Apply(rayClusterSpecAC, MountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) rayCluster, err := test.Client().Ray().RayV1().RayClusters(namespace.Name).Apply(test.Ctx(), rayClusterAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) @@ -430,7 +430,7 @@ func TestRayClusterAutoscalerPlacementGroup(t *testing.T) { namespace := test.NewTestNamespace() // Mount the scripts as a ConfigMap - scriptsAC := newConfigMap(namespace.Name, files(test, "create_detached_placement_group.py", "check_placement_group_ready.py")) + scriptsAC := newConfigMap(namespace.Name, Files(test, "create_detached_placement_group.py", "check_placement_group_ready.py")) scripts, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), scriptsAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", scripts.Namespace, scripts.Name) @@ -451,7 +451,7 @@ func TestRayClusterAutoscalerPlacementGroup(t *testing.T) { WithRayStartParams(setting.workerGroupRayStartParams). WithTemplate(tc.WorkerPodTemplateGetter())) rayClusterAC := rayv1ac.RayCluster("ray-cluster", namespace.Name). - WithSpec(apply(rayClusterSpecAC, mountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) + WithSpec(Apply(rayClusterSpecAC, MountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) rayCluster, err := test.Client().Ray().RayV1().RayClusters(namespace.Name).Apply(test.Ctx(), rayClusterAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) @@ -511,7 +511,7 @@ func TestRayClusterAutoscalerGCSFT(t *testing.T) { namespace := test.NewTestNamespace() // Scripts for creating and terminating detached actors to trigger autoscaling - scriptsAC := newConfigMap(namespace.Name, files(test, "create_detached_actor.py", "terminate_detached_actor.py")) + scriptsAC := newConfigMap(namespace.Name, Files(test, "create_detached_actor.py", "terminate_detached_actor.py")) scripts, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), scriptsAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", scripts.Namespace, scripts.Name) @@ -544,7 +544,7 @@ func TestRayClusterAutoscalerGCSFT(t *testing.T) { WithTemplate(tc.WorkerPodTemplateGetter()), ) rayClusterAC := rayv1ac.RayCluster("ray-cluster", namespace.Name). - WithSpec(apply(rayClusterSpecAC, mountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) + WithSpec(Apply(rayClusterSpecAC, MountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) rayCluster, err := test.Client().Ray().RayV1().RayClusters(namespace.Name).Apply(test.Ctx(), rayClusterAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) diff --git a/ray-operator/test/e2eautoscaler/raycluster_autoscaler_test.go b/ray-operator/test/e2eautoscaler/raycluster_autoscaler_test.go index a72d83b8d65..5df0d60e6ef 100644 --- a/ray-operator/test/e2eautoscaler/raycluster_autoscaler_test.go +++ b/ray-operator/test/e2eautoscaler/raycluster_autoscaler_test.go @@ -24,7 +24,7 @@ func TestRayClusterAutoscaler(t *testing.T) { namespace := test.NewTestNamespace() // Scripts for creating and terminating detached actors to trigger autoscaling - scriptsAC := newConfigMap(namespace.Name, files(test, "create_detached_actor.py", "terminate_detached_actor.py")) + scriptsAC := newConfigMap(namespace.Name, Files(test, "create_detached_actor.py", "terminate_detached_actor.py")) scripts, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), scriptsAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", scripts.Namespace, scripts.Name) @@ -43,7 +43,7 @@ func TestRayClusterAutoscaler(t *testing.T) { WithRayStartParams(map[string]string{"num-cpus": "1"}). WithTemplate(tc.WorkerPodTemplateGetter())) rayClusterAC := rayv1ac.RayCluster("ray-cluster", namespace.Name). - WithSpec(apply(rayClusterSpecAC, mountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) + WithSpec(Apply(rayClusterSpecAC, MountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) rayCluster, err := test.Client().Ray().RayV1().RayClusters(namespace.Name).Apply(test.Ctx(), rayClusterAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) @@ -91,7 +91,7 @@ func TestRayClusterAutoscalerWithFakeGPU(t *testing.T) { namespace := test.NewTestNamespace() // Scripts for creating and terminating detached actors to trigger autoscaling - scriptsAC := newConfigMap(namespace.Name, files(test, "create_detached_actor.py", "terminate_detached_actor.py")) + scriptsAC := newConfigMap(namespace.Name, Files(test, "create_detached_actor.py", "terminate_detached_actor.py")) scripts, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), scriptsAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", scripts.Namespace, scripts.Name) @@ -110,7 +110,7 @@ func TestRayClusterAutoscalerWithFakeGPU(t *testing.T) { WithRayStartParams(map[string]string{"num-cpus": "1", "num-gpus": "1"}). WithTemplate(tc.WorkerPodTemplateGetter())) rayClusterAC := rayv1ac.RayCluster("ray-cluster", namespace.Name). - WithSpec(apply(rayClusterSpecAC, mountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) + WithSpec(Apply(rayClusterSpecAC, MountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) rayCluster, err := test.Client().Ray().RayV1().RayClusters(namespace.Name).Apply(test.Ctx(), rayClusterAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) @@ -151,7 +151,7 @@ func TestRayClusterAutoscalerWithCustomResource(t *testing.T) { namespace := test.NewTestNamespace() // Scripts for creating and terminating detached actors to trigger autoscaling - scriptsAC := newConfigMap(namespace.Name, files(test, "create_detached_actor.py", "terminate_detached_actor.py")) + scriptsAC := newConfigMap(namespace.Name, Files(test, "create_detached_actor.py", "terminate_detached_actor.py")) scripts, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), scriptsAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", scripts.Namespace, scripts.Name) @@ -172,7 +172,7 @@ func TestRayClusterAutoscalerWithCustomResource(t *testing.T) { WithRayStartParams(map[string]string{"num-cpus": "1", "resources": `'{"CustomResource": 1}'`}). WithTemplate(tc.WorkerPodTemplateGetter())) rayClusterAC := rayv1ac.RayCluster("ray-cluster", namespace.Name). - WithSpec(apply(rayClusterSpecAC, mountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) + WithSpec(Apply(rayClusterSpecAC, MountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) rayCluster, err := test.Client().Ray().RayV1().RayClusters(namespace.Name).Apply(test.Ctx(), rayClusterAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) @@ -214,7 +214,7 @@ func TestRayClusterAutoscalerWithDesiredState(t *testing.T) { namespace := test.NewTestNamespace() // Scripts for creating and terminating detached actors to trigger autoscaling - scriptsAC := newConfigMap(namespace.Name, files(test, "create_concurrent_tasks.py")) + scriptsAC := newConfigMap(namespace.Name, Files(test, "create_concurrent_tasks.py")) scripts, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), scriptsAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", scripts.Namespace, scripts.Name) @@ -236,7 +236,7 @@ func TestRayClusterAutoscalerWithDesiredState(t *testing.T) { WithAutoscalerOptions(rayv1ac.AutoscalerOptions(). WithIdleTimeoutSeconds(scaleDownWaitSec)) rayClusterAC := rayv1ac.RayCluster("ray-cluster", namespace.Name). - WithSpec(apply(rayClusterSpecAC, mountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) + WithSpec(Apply(rayClusterSpecAC, MountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) rayCluster, err := test.Client().Ray().RayV1().RayClusters(namespace.Name).Apply(test.Ctx(), rayClusterAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) @@ -272,7 +272,7 @@ func TestRayClusterAutoscalerMinReplicasUpdate(t *testing.T) { namespace := test.NewTestNamespace() // Script for creating detached actors to trigger autoscaling - scriptsAC := newConfigMap(namespace.Name, files(test, "create_detached_actor.py")) + scriptsAC := newConfigMap(namespace.Name, Files(test, "create_detached_actor.py")) scripts, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), scriptsAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", scripts.Namespace, scripts.Name) @@ -293,7 +293,7 @@ func TestRayClusterAutoscalerMinReplicasUpdate(t *testing.T) { WithRayStartParams(map[string]string{"num-cpus": "1"}). WithTemplate(tc.WorkerPodTemplateGetter())) rayClusterAC := rayv1ac.RayCluster("ray-cluster", namespace.Name). - WithSpec(apply(rayClusterSpecAC, mountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) + WithSpec(Apply(rayClusterSpecAC, MountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) rayCluster, err := test.Client().Ray().RayV1().RayClusters(namespace.Name).Apply(test.Ctx(), rayClusterAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) @@ -363,7 +363,7 @@ func TestRayClusterAutoscalerMaxReplicasUpdate(t *testing.T) { namespace := test.NewTestNamespace() - scriptsAC := newConfigMap(namespace.Name, files(test, "create_detached_actor.py")) + scriptsAC := newConfigMap(namespace.Name, Files(test, "create_detached_actor.py")) scripts, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), scriptsAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) @@ -383,7 +383,7 @@ func TestRayClusterAutoscalerMaxReplicasUpdate(t *testing.T) { WithRayStartParams(map[string]string{"num-cpus": "1"}). WithTemplate(tc.WorkerPodTemplateGetter())) rayClusterAC := rayv1ac.RayCluster("ray-cluster", namespace.Name). - WithSpec(apply(rayClusterSpecAC, mountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) + WithSpec(Apply(rayClusterSpecAC, MountConfigMap[rayv1ac.RayClusterSpecApplyConfiguration](scripts, "/home/ray/test_scripts"))) rayCluster, err := test.Client().Ray().RayV1().RayClusters(namespace.Name).Apply(test.Ctx(), rayClusterAC, TestApplyOptions) g.Expect(err).NotTo(gomega.HaveOccurred()) diff --git a/ray-operator/test/e2eautoscaler/support.go b/ray-operator/test/e2eautoscaler/support.go index b21010107a9..d2e1c584314 100644 --- a/ray-operator/test/e2eautoscaler/support.go +++ b/ray-operator/test/e2eautoscaler/support.go @@ -6,76 +6,15 @@ import ( corev1ac "k8s.io/client-go/applyconfigurations/core/v1" "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils" - rayv1ac "github.com/ray-project/kuberay/ray-operator/pkg/client/applyconfiguration/ray/v1" . "github.com/ray-project/kuberay/ray-operator/test/support" ) -type option[T any] func(t *T) *T - -func apply[T any](t *T, options ...option[T]) *T { - for _, opt := range options { - t = opt(t) - } - return t -} - -func options[T any](options ...option[T]) option[T] { - return func(t *T) *T { - for _, opt := range options { - t = opt(t) - } - return t - } -} - -func newConfigMap(namespace string, options ...option[corev1ac.ConfigMapApplyConfiguration]) *corev1ac.ConfigMapApplyConfiguration { +func newConfigMap(namespace string, options ...SupportOption[corev1ac.ConfigMapApplyConfiguration]) *corev1ac.ConfigMapApplyConfiguration { cmAC := corev1ac.ConfigMap("scripts", namespace). WithBinaryData(map[string][]byte{}). WithImmutable(true) - return configMapWith(cmAC, options...) -} - -func configMapWith(configMapAC *corev1ac.ConfigMapApplyConfiguration, options ...option[corev1ac.ConfigMapApplyConfiguration]) *corev1ac.ConfigMapApplyConfiguration { - return apply(configMapAC, options...) -} - -func file(t Test, fileName string) option[corev1ac.ConfigMapApplyConfiguration] { - return func(cmAC *corev1ac.ConfigMapApplyConfiguration) *corev1ac.ConfigMapApplyConfiguration { - cmAC.WithBinaryData(map[string][]byte{fileName: ReadFile(t, fileName)}) - return cmAC - } -} - -func files(t Test, fileNames ...string) option[corev1ac.ConfigMapApplyConfiguration] { - var files []option[corev1ac.ConfigMapApplyConfiguration] - for _, fileName := range fileNames { - files = append(files, file(t, fileName)) - } - return options(files...) -} - -func mountConfigMap[T rayv1ac.RayClusterSpecApplyConfiguration | corev1ac.PodTemplateSpecApplyConfiguration](configMap *corev1.ConfigMap, mountPath string) option[T] { - return func(t *T) *T { - switch obj := (interface{})(t).(type) { - case *rayv1ac.RayClusterSpecApplyConfiguration: - obj.HeadGroupSpec.Template.Spec.Containers[0].WithVolumeMounts(corev1ac.VolumeMount(). - WithName(configMap.Name). - WithMountPath(mountPath)) - obj.HeadGroupSpec.Template.Spec.WithVolumes(corev1ac.Volume(). - WithName(configMap.Name). - WithConfigMap(corev1ac.ConfigMapVolumeSource().WithName(configMap.Name))) - - case *corev1ac.PodTemplateSpecApplyConfiguration: - obj.Spec.Containers[0].WithVolumeMounts(corev1ac.VolumeMount(). - WithName(configMap.Name). - WithMountPath(mountPath)) - obj.Spec.WithVolumes(corev1ac.Volume(). - WithName(configMap.Name). - WithConfigMap(corev1ac.ConfigMapVolumeSource().WithName(configMap.Name))) - } - return t - } + return ConfigMapWith(cmAC, options...) } func headPodTemplateApplyConfiguration() *corev1ac.PodTemplateSpecApplyConfiguration { diff --git a/ray-operator/test/e2erayservice/rayservice_ha_test.go b/ray-operator/test/e2erayservice/rayservice_ha_test.go index f16ebebaf51..fe45fcb35ed 100644 --- a/ray-operator/test/e2erayservice/rayservice_ha_test.go +++ b/ray-operator/test/e2erayservice/rayservice_ha_test.go @@ -24,7 +24,7 @@ func TestStaticRayService(t *testing.T) { namespace := test.NewTestNamespace() // Create a ConfigMap with Locust runner script - configMapAC := newConfigMap(namespace.Name, files(test, "locust_runner.py")) + configMapAC := newConfigMap(namespace.Name, Files(test, "locust_runner.py")) configMap, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), configMapAC, TestApplyOptions) g.Expect(err).NotTo(HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", configMap.Namespace, configMap.Name) @@ -68,7 +68,7 @@ func TestAutoscalingRayService(t *testing.T) { namespace := test.NewTestNamespace() // Create a ConfigMap with Locust runner script - configMapAC := newConfigMap(namespace.Name, files(test, "locust_runner.py")) + configMapAC := newConfigMap(namespace.Name, Files(test, "locust_runner.py")) configMap, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), configMapAC, TestApplyOptions) g.Expect(err).NotTo(HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", configMap.Namespace, configMap.Name) @@ -132,7 +132,7 @@ func TestRayServiceZeroDowntimeUpgrade(t *testing.T) { namespace := test.NewTestNamespace() // Create a ConfigMap with Locust runner script - configMapAC := newConfigMap(namespace.Name, files(test, "locust_runner.py")) + configMapAC := newConfigMap(namespace.Name, Files(test, "locust_runner.py")) configMap, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), configMapAC, TestApplyOptions) g.Expect(err).NotTo(HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", configMap.Namespace, configMap.Name) @@ -200,7 +200,7 @@ func TestRayServiceGCSFaultTolerance(t *testing.T) { namespace := test.NewTestNamespace() // Create a ConfigMap with Locust runner script - configMapAC := newConfigMap(namespace.Name, files(test, "locust_runner.py")) + configMapAC := newConfigMap(namespace.Name, Files(test, "locust_runner.py")) configMap, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), configMapAC, TestApplyOptions) g.Expect(err).NotTo(HaveOccurred()) LogWithTimestamp(test.T(), "Created ConfigMap %s/%s successfully", configMap.Namespace, configMap.Name) diff --git a/ray-operator/test/e2erayservice/support.go b/ray-operator/test/e2erayservice/support.go index 45deac610b4..5cff9621485 100644 --- a/ray-operator/test/e2erayservice/support.go +++ b/ray-operator/test/e2erayservice/support.go @@ -16,49 +16,12 @@ import ( . "github.com/ray-project/kuberay/ray-operator/test/support" ) -type option[T any] func(t *T) *T - -func apply[T any](t *T, options ...option[T]) *T { - for _, opt := range options { - t = opt(t) - } - return t -} - -func options[T any](options ...option[T]) option[T] { - return func(t *T) *T { - for _, opt := range options { - t = opt(t) - } - return t - } -} - -func newConfigMap(namespace string, options ...option[corev1ac.ConfigMapApplyConfiguration]) *corev1ac.ConfigMapApplyConfiguration { +func newConfigMap(namespace string, options ...SupportOption[corev1ac.ConfigMapApplyConfiguration]) *corev1ac.ConfigMapApplyConfiguration { cmAC := corev1ac.ConfigMap("locust-runner-script", namespace). WithBinaryData(map[string][]byte{}). WithImmutable(true) - return configMapWith(cmAC, options...) -} - -func configMapWith(configMapAC *corev1ac.ConfigMapApplyConfiguration, options ...option[corev1ac.ConfigMapApplyConfiguration]) *corev1ac.ConfigMapApplyConfiguration { - return apply(configMapAC, options...) -} - -func file(t Test, fileName string) option[corev1ac.ConfigMapApplyConfiguration] { - return func(cmAC *corev1ac.ConfigMapApplyConfiguration) *corev1ac.ConfigMapApplyConfiguration { - cmAC.WithBinaryData(map[string][]byte{fileName: ReadFile(t, fileName)}) - return cmAC - } -} - -func files(t Test, fileNames ...string) option[corev1ac.ConfigMapApplyConfiguration] { - var files []option[corev1ac.ConfigMapApplyConfiguration] - for _, fileName := range fileNames { - files = append(files, file(t, fileName)) - } - return options(files...) + return ConfigMapWith(cmAC, options...) } func CurlRayServicePod(