Skip to content

Commit 20476aa

Browse files
Added Unit tests for custom volumes and volume mounts
1 parent c68d425 commit 20476aa

File tree

2 files changed

+248
-0
lines changed

2 files changed

+248
-0
lines changed

tests/unit-test-volume-cluster.yaml

+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
apiVersion: ray.io/v1
2+
kind: RayCluster
3+
metadata:
4+
labels:
5+
controller-tools.k8s.io: '1.0'
6+
kueue.x-k8s.io/queue-name: local-queue-default
7+
name: unit-test-volume-cluster
8+
namespace: opendatahub
9+
spec:
10+
autoscalerOptions:
11+
idleTimeoutSeconds: 60
12+
imagePullPolicy: Always
13+
resources:
14+
limits:
15+
cpu: 500m
16+
memory: 512Mi
17+
requests:
18+
cpu: 500m
19+
memory: 512Mi
20+
upscalingMode: Default
21+
enableInTreeAutoscaling: false
22+
headGroupSpec:
23+
enableIngress: false
24+
rayStartParams:
25+
block: 'true'
26+
dashboard-host: 0.0.0.0
27+
num-gpus: '0'
28+
serviceType: ClusterIP
29+
template:
30+
spec:
31+
containers:
32+
- image: quay.io/project-codeflare/ray:latest-py39-cu118
33+
imagePullPolicy: Always
34+
lifecycle:
35+
preStop:
36+
exec:
37+
command:
38+
- /bin/sh
39+
- -c
40+
- ray stop
41+
name: ray-head
42+
ports:
43+
- containerPort: 6379
44+
name: gcs
45+
- containerPort: 8265
46+
name: dashboard
47+
- containerPort: 10001
48+
name: client
49+
resources:
50+
limits:
51+
cpu: 2
52+
memory: 8G
53+
nvidia.com/gpu: 0
54+
requests:
55+
cpu: 2
56+
memory: 8G
57+
nvidia.com/gpu: 0
58+
volumeMounts:
59+
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
60+
name: odh-trusted-ca-cert
61+
subPath: odh-trusted-ca-bundle.crt
62+
- mountPath: /etc/ssl/certs/odh-trusted-ca-bundle.crt
63+
name: odh-trusted-ca-cert
64+
subPath: odh-trusted-ca-bundle.crt
65+
- mountPath: /etc/pki/tls/certs/odh-ca-bundle.crt
66+
name: odh-ca-cert
67+
subPath: odh-ca-bundle.crt
68+
- mountPath: /etc/ssl/certs/odh-ca-bundle.crt
69+
name: odh-ca-cert
70+
subPath: odh-ca-bundle.crt
71+
- mountPath: /home/ray/test1
72+
name: test
73+
- mountPath: /home/ray/test2
74+
name: test2
75+
- mountPath: /home/ray/test2
76+
name: test3
77+
imagePullSecrets: []
78+
volumes:
79+
- configMap:
80+
items:
81+
- key: ca-bundle.crt
82+
path: odh-trusted-ca-bundle.crt
83+
name: odh-trusted-ca-bundle
84+
optional: true
85+
name: odh-trusted-ca-cert
86+
- configMap:
87+
items:
88+
- key: odh-ca-bundle.crt
89+
path: odh-ca-bundle.crt
90+
name: odh-trusted-ca-bundle
91+
optional: true
92+
name: odh-ca-cert
93+
- emptyDir:
94+
sizeLimit: 500Gi
95+
name: test
96+
- configMap:
97+
items:
98+
- key: test
99+
path: /home/ray/test2/data.txt
100+
name: config-map-test
101+
name: test2
102+
- name: test3
103+
secret:
104+
secretName: test-secret
105+
rayVersion: 2.7.0
106+
workerGroupSpecs:
107+
- groupName: small-group-unit-test-volume-cluster
108+
maxReplicas: 1
109+
minReplicas: 1
110+
rayStartParams:
111+
block: 'true'
112+
num-gpus: '0'
113+
replicas: 1
114+
template:
115+
metadata:
116+
annotations:
117+
key: value
118+
labels:
119+
key: value
120+
spec:
121+
containers:
122+
- image: quay.io/project-codeflare/ray:latest-py39-cu118
123+
lifecycle:
124+
preStop:
125+
exec:
126+
command:
127+
- /bin/sh
128+
- -c
129+
- ray stop
130+
name: machine-learning
131+
resources:
132+
limits:
133+
cpu: 1
134+
memory: 2G
135+
nvidia.com/gpu: 0
136+
requests:
137+
cpu: 1
138+
memory: 2G
139+
nvidia.com/gpu: 0
140+
volumeMounts:
141+
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
142+
name: odh-trusted-ca-cert
143+
subPath: odh-trusted-ca-bundle.crt
144+
- mountPath: /etc/ssl/certs/odh-trusted-ca-bundle.crt
145+
name: odh-trusted-ca-cert
146+
subPath: odh-trusted-ca-bundle.crt
147+
- mountPath: /etc/pki/tls/certs/odh-ca-bundle.crt
148+
name: odh-ca-cert
149+
subPath: odh-ca-bundle.crt
150+
- mountPath: /etc/ssl/certs/odh-ca-bundle.crt
151+
name: odh-ca-cert
152+
subPath: odh-ca-bundle.crt
153+
- mountPath: /home/ray/test1
154+
name: test
155+
- mountPath: /home/ray/test2
156+
name: test2
157+
- mountPath: /home/ray/test2
158+
name: test3
159+
imagePullSecrets: []
160+
volumes:
161+
- configMap:
162+
items:
163+
- key: ca-bundle.crt
164+
path: odh-trusted-ca-bundle.crt
165+
name: odh-trusted-ca-bundle
166+
optional: true
167+
name: odh-trusted-ca-cert
168+
- configMap:
169+
items:
170+
- key: odh-ca-bundle.crt
171+
path: odh-ca-bundle.crt
172+
name: odh-trusted-ca-bundle
173+
optional: true
174+
name: odh-ca-cert
175+
- emptyDir:
176+
sizeLimit: 500Gi
177+
name: test
178+
- configMap:
179+
items:
180+
- key: test
181+
path: /home/ray/test2/data.txt
182+
name: config-map-test
183+
name: test2
184+
- name: test3
185+
secret:
186+
secretName: test-secret

tests/unit_test.py

+62
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,68 @@ def test_default_cluster_creation(mocker):
444444
assert cluster.config.namespace == "opendatahub"
445445

446446

447+
def test_cluster_with_custom_volumes(mocker):
448+
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
449+
mocker.patch(
450+
"codeflare_sdk.cluster.cluster.get_current_namespace",
451+
return_value="opendatahub",
452+
)
453+
mocker.patch(
454+
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
455+
return_value=get_local_queue("kueue.x-k8s.io", "v1beta1", "ns", "localqueues"),
456+
)
457+
458+
from kubernetes.client import (
459+
V1Volume,
460+
V1VolumeMount,
461+
V1EmptyDirVolumeSource,
462+
V1ConfigMapVolumeSource,
463+
V1KeyToPath,
464+
V1SecretVolumeSource,
465+
)
466+
467+
volume_mounts = [
468+
V1VolumeMount(mount_path="/home/ray/test1", name="test"),
469+
V1VolumeMount(
470+
mount_path="/home/ray/test2",
471+
name="test2",
472+
),
473+
V1VolumeMount(
474+
mount_path="/home/ray/test2",
475+
name="test3",
476+
),
477+
]
478+
479+
volumes = [
480+
V1Volume(
481+
name="test",
482+
empty_dir=V1EmptyDirVolumeSource(size_limit="500Gi"),
483+
),
484+
V1Volume(
485+
name="test2",
486+
config_map=V1ConfigMapVolumeSource(
487+
name="config-map-test",
488+
items=[V1KeyToPath(key="test", path="/home/ray/test2/data.txt")],
489+
),
490+
),
491+
V1Volume(name="test3", secret=V1SecretVolumeSource(secret_name="test-secret")),
492+
]
493+
494+
test_config = ClusterConfiguration(
495+
name="unit-test-volume-cluster",
496+
image="quay.io/project-codeflare/ray:latest-py39-cu118",
497+
volume_mounts=volume_mounts,
498+
volumes=volumes,
499+
)
500+
cluster = Cluster(test_config)
501+
test_rc = yaml.load(cluster.app_wrapper_yaml, Loader=yaml.FullLoader)
502+
with open(
503+
f"{parent}/tests/unit-test-volume-cluster.yaml",
504+
) as f:
505+
volume_rc = yaml.load(f, Loader=yaml.FullLoader)
506+
assert test_rc == volume_rc
507+
508+
447509
def test_gen_names_with_name(mocker):
448510
mocker.patch.object(
449511
uuid, "uuid4", return_value=uuid.UUID("00000000-0000-0000-0000-000000000001")

0 commit comments

Comments
 (0)