Skip to content

Commit adc6236

Browse files
committed
Move e2e test and add another unit test
Signed-off-by: Ryan O'Leary <[email protected]>
1 parent 5bb6bfe commit adc6236

File tree

5 files changed

+96
-73
lines changed

5 files changed

+96
-73
lines changed

ray-operator/controllers/ray/rayservice_controller_unit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,7 @@ func makeHTTPRoute(name, namespace string, isReady bool) *gwv1.HTTPRoute {
18601860
func TestCheckIfNeedIncrementalUpgradeUpdate(t *testing.T) {
18611861
rayServiceName := "test-rayservice"
18621862
gatewayName := fmt.Sprintf("%s-%s", rayServiceName, "gateway")
1863-
httpRouteName := fmt.Sprintf("%s-%s", "httproute-", rayServiceName)
1863+
httpRouteName := fmt.Sprintf("%s-%s", "httproute", rayServiceName)
18641864
namespace := "test-ns"
18651865

18661866
tests := []struct {

ray-operator/test/e2erayservice/rayservice_incremental_upgrade_test.go renamed to ray-operator/test/e2eincrementalupgrade/rayservice_incremental_upgrade_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package e2erayservice
1+
package e2eincrementalupgrade
22

33
import (
44
"fmt"
@@ -78,10 +78,14 @@ func TestRayServiceIncrementalUpgrade(t *testing.T) {
7878
return updatedPod
7979
}, TestTimeoutShort).Should(WithTransform(sampleyaml.IsPodRunningAndReady, BeTrue()))
8080

81+
// Get the Gateway endpoint to send requests to
82+
gatewayIP := GetGatewayIP(gateway)
83+
g.Expect(gatewayIP).NotTo(BeEmpty())
84+
8185
LogWithTimestamp(test.T(), "Verifying RayService is serving traffic")
82-
stdout, _ := CurlRayServicePod(test, rayService, curlPod, curlContainerName, "/fruit", `["MANGO", 2]`)
86+
stdout, _ := CurlRayServiceGateway(test, gatewayIP, curlPod, curlContainerName, "/fruit", `["MANGO", 2]`)
8387
g.Expect(stdout.String()).To(Equal("6"))
84-
stdout, _ = CurlRayServicePod(test, rayService, curlPod, curlContainerName, "/calc", `["MUL", 3]`)
88+
stdout, _ = CurlRayServiceGateway(test, gatewayIP, curlPod, curlContainerName, "/calc", `["MUL", 3]`)
8589
g.Expect(stdout.String()).To(Equal("15 pizzas please!"))
8690

8791
// Trigger incremental upgrade by updating RayService serve config
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package e2eincrementalupgrade
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
7+
corev1 "k8s.io/api/core/v1"
8+
"k8s.io/utils/ptr"
9+
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
10+
11+
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
12+
rayv1ac "github.com/ray-project/kuberay/ray-operator/pkg/client/applyconfiguration/ray/v1"
13+
e2eRayService "github.com/ray-project/kuberay/ray-operator/test/e2erayservice"
14+
. "github.com/ray-project/kuberay/ray-operator/test/support"
15+
)
16+
17+
func CurlRayServiceHeadService(
18+
t Test,
19+
headSvcName string,
20+
rayService *rayv1.RayService,
21+
curlPod *corev1.Pod,
22+
curlPodContainerName,
23+
rayServicePath,
24+
body string,
25+
) (bytes.Buffer, bytes.Buffer) {
26+
cmd := []string{
27+
"curl",
28+
"-X", "POST",
29+
"-H", "Content-Type: application/json",
30+
fmt.Sprintf("%s.%s.svc.cluster.local:8000%s", headSvcName, rayService.Namespace, rayServicePath),
31+
"-d", body,
32+
}
33+
34+
return ExecPodCmd(t, curlPod, curlPodContainerName, cmd)
35+
}
36+
37+
func CurlRayServiceGateway(
38+
t Test,
39+
gatewayIP string,
40+
curlPod *corev1.Pod,
41+
curlPodContainerName,
42+
rayServicePath,
43+
body string,
44+
) (bytes.Buffer, bytes.Buffer) {
45+
cmd := []string{
46+
"curl",
47+
"-X", "POST",
48+
"-H", "Content-Type: application/json",
49+
fmt.Sprintf("%s:80%s", gatewayIP, rayServicePath),
50+
"-d", body,
51+
}
52+
53+
return ExecPodCmd(t, curlPod, curlPodContainerName, cmd)
54+
}
55+
56+
func IncrementalUpgradeRayServiceApplyConfiguration(
57+
stepSizePercent, intervalSeconds, maxSurgePercent *int32,
58+
) *rayv1ac.RayServiceSpecApplyConfiguration {
59+
spec := e2eRayService.RayServiceSampleYamlApplyConfiguration()
60+
61+
spec.RayClusterSpec.EnableInTreeAutoscaling = ptr.To(true)
62+
spec.WithUpgradeStrategy(rayv1ac.RayServiceUpgradeStrategy().
63+
WithType(rayv1.IncrementalUpgrade).
64+
WithIncrementalUpgradeOptions(
65+
rayv1ac.IncrementalUpgradeOptions().
66+
WithGatewayClassName("istio").
67+
WithStepSizePercent(*stepSizePercent).
68+
WithIntervalSeconds(*intervalSeconds).
69+
WithMaxSurgePercent(*maxSurgePercent),
70+
),
71+
)
72+
73+
return spec
74+
}
75+
76+
// GetGatewayIP retrieves the external IP for a Gateway object
77+
func GetGatewayIP(gateway *gwv1.Gateway) string {
78+
if gateway == nil {
79+
return ""
80+
}
81+
for _, addr := range gateway.Status.Addresses {
82+
if addr.Type == nil || *addr.Type == gwv1.IPAddressType {
83+
return addr.Value
84+
}
85+
}
86+
87+
return ""
88+
}

ray-operator/test/e2erayservice/support.go

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
corev1 "k8s.io/api/core/v1"
1010
"k8s.io/apimachinery/pkg/api/resource"
1111
corev1ac "k8s.io/client-go/applyconfigurations/core/v1"
12-
"k8s.io/utils/ptr"
1312

1413
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
1514
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
@@ -91,46 +90,6 @@ func CurlRayServicePod(
9190
return ExecPodCmd(t, curlPod, curlPodContainerName, cmd)
9291
}
9392

94-
func CurlRayServiceHeadService(
95-
t Test,
96-
headSvcName string,
97-
rayService *rayv1.RayService,
98-
curlPod *corev1.Pod,
99-
curlPodContainerName,
100-
rayServicePath,
101-
body string,
102-
) (bytes.Buffer, bytes.Buffer) {
103-
cmd := []string{
104-
"curl",
105-
"-X", "POST",
106-
"-H", "Content-Type: application/json",
107-
fmt.Sprintf("%s.%s.svc.cluster.local:8000%s", headSvcName, rayService.Namespace, rayServicePath),
108-
"-d", body,
109-
}
110-
111-
return ExecPodCmd(t, curlPod, curlPodContainerName, cmd)
112-
}
113-
114-
// func CurlRayServiceGateway(
115-
// t Test,
116-
// gatewayName string,
117-
// rayService *rayv1.RayService,
118-
// curlPod *corev1.Pod,
119-
// curlPodContainerName,
120-
// rayServicePath,
121-
// body string,
122-
// ) (bytes.Buffer, bytes.Buffer) {
123-
// cmd := []string{
124-
// "curl",
125-
// "-X", "POST",
126-
// "-H", "Content-Type: application/json",
127-
// fmt.Sprintf("%s.%s.svc.cluster.local:8000%s", headSvcName, rayService.Namespace, rayServicePath),
128-
// "-d", body,
129-
// }
130-
131-
// return ExecPodCmd(t, curlPod, curlPodContainerName, cmd)
132-
// }
133-
13493
func RayServiceSampleYamlApplyConfiguration() *rayv1ac.RayServiceSpecApplyConfiguration {
13594
return rayv1ac.RayServiceSpec().WithServeConfigV2(`applications:
13695
- name: fruit_app
@@ -203,23 +162,3 @@ func RayServiceSampleYamlApplyConfiguration() *rayv1ac.RayServiceSpecApplyConfig
203162
})))))),
204163
)
205164
}
206-
207-
func IncrementalUpgradeRayServiceApplyConfiguration(
208-
stepSizePercent, intervalSeconds, maxSurgePercent *int32,
209-
) *rayv1ac.RayServiceSpecApplyConfiguration {
210-
spec := RayServiceSampleYamlApplyConfiguration()
211-
212-
spec.RayClusterSpec.EnableInTreeAutoscaling = ptr.To(true)
213-
spec.WithUpgradeStrategy(rayv1ac.RayServiceUpgradeStrategy().
214-
WithType(rayv1.IncrementalUpgrade).
215-
WithIncrementalUpgradeOptions(
216-
rayv1ac.IncrementalUpgradeOptions().
217-
WithGatewayClassName("istio").
218-
WithStepSizePercent(*stepSizePercent).
219-
WithIntervalSeconds(*intervalSeconds).
220-
WithMaxSurgePercent(*maxSurgePercent),
221-
),
222-
)
223-
224-
return spec
225-
}

ray-operator/test/support/ray.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,3 @@ func Gateway(t Test, namespace, name string) func() (*gwv1.Gateway, error) {
243243
return GetGateway(t, namespace, name)
244244
}
245245
}
246-
247-
// func IsGatewayReady(gateway *gwv1.Gateway) bool {
248-
// return meta.IsStatusConditionTrue(gateway.Status.Conditions, string(gwv1.GatewayConditionAccepted))
249-
// }
250-
251-
// func IsHTTPRouteReady(httpRoute *gwv1.HTTPRoute) bool {
252-
// return meta.IsStatusConditionTrue(httpRoute.Status.Conditions, string(gwv1.RouteConditionAccepted))
253-
// }

0 commit comments

Comments
 (0)