Skip to content

Commit 917824c

Browse files
committed
test: add volumes/volume mounts tests
1 parent 93c4c12 commit 917824c

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

src/codeflare_sdk/common/utils/unit_test_support.py

+42
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ def create_cluster_all_config_params(mocker, cluster_name, is_appwrapper) -> Clu
417417
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
418418
return_value=get_local_queue("kueue.x-k8s.io", "v1beta1", "ns", "localqueues"),
419419
)
420+
volumes, volume_mounts = get_example_extended_storage_opts()
420421

421422
config = ClusterConfiguration(
422423
name=cluster_name,
@@ -443,5 +444,46 @@ def create_cluster_all_config_params(mocker, cluster_name, is_appwrapper) -> Clu
443444
overwrite_default_resource_mapping=True,
444445
local_queue="local-queue-default",
445446
annotations={"key1": "value1", "key2": "value2"},
447+
volumes=volumes,
448+
volume_mounts=volume_mounts,
446449
)
447450
return Cluster(config)
451+
452+
453+
def get_example_extended_storage_opts():
454+
from kubernetes.client import (
455+
V1Volume,
456+
V1VolumeMount,
457+
V1EmptyDirVolumeSource,
458+
V1ConfigMapVolumeSource,
459+
V1KeyToPath,
460+
V1SecretVolumeSource,
461+
)
462+
463+
volume_mounts = [
464+
V1VolumeMount(mount_path="/home/ray/test1", name="test"),
465+
V1VolumeMount(
466+
mount_path="/home/ray/test2",
467+
name="test2",
468+
),
469+
V1VolumeMount(
470+
mount_path="/home/ray/test2",
471+
name="test3",
472+
),
473+
]
474+
475+
volumes = [
476+
V1Volume(
477+
name="test",
478+
empty_dir=V1EmptyDirVolumeSource(size_limit="500Gi"),
479+
),
480+
V1Volume(
481+
name="test2",
482+
config_map=V1ConfigMapVolumeSource(
483+
name="config-map-test",
484+
items=[V1KeyToPath(key="test", path="/home/ray/test2/data.txt")],
485+
),
486+
),
487+
V1Volume(name="test3", secret=V1SecretVolumeSource(secret_name="test-secret")),
488+
]
489+
return volumes, volume_mounts

src/codeflare_sdk/ray/cluster/test_config.py

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from codeflare_sdk.common.utils.unit_test_support import (
1616
apply_template,
1717
createClusterWrongType,
18+
get_example_extended_storage_opts,
1819
create_cluster_all_config_params,
1920
get_template_variables,
2021
)
@@ -64,6 +65,7 @@ def test_config_creation_all_parameters(mocker):
6465
expected_extended_resource_mapping = DEFAULT_RESOURCE_MAPPING
6566
expected_extended_resource_mapping.update({"example.com/gpu": "GPU"})
6667
expected_extended_resource_mapping["intel.com/gpu"] = "TPU"
68+
volumes, volume_mounts = get_example_extended_storage_opts()
6769

6870
cluster = create_cluster_all_config_params(mocker, "test-all-params", False)
6971
assert cluster.config.name == "test-all-params" and cluster.config.namespace == "ns"
@@ -98,6 +100,8 @@ def test_config_creation_all_parameters(mocker):
98100
"key1": "value1",
99101
"key2": "value2",
100102
}
103+
assert cluster.config.volumes == volumes
104+
assert cluster.config.volume_mounts == volume_mounts
101105

102106
assert filecmp.cmp(
103107
f"{aw_dir}test-all-params.yaml",

tests/test_cluster_yamls/appwrapper/unit-test-all-params.yaml

+36
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ spec:
7878
memory: 12G
7979
nvidia.com/gpu: 1
8080
volumeMounts:
81+
- mountPath: /home/ray/test1
82+
name: test
83+
- mountPath: /home/ray/test2
84+
name: test2
85+
- mountPath: /home/ray/test2
86+
name: test3
8187
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
8288
name: odh-trusted-ca-cert
8389
subPath: odh-trusted-ca-bundle.crt
@@ -94,6 +100,18 @@ spec:
94100
- name: secret1
95101
- name: secret2
96102
volumes:
103+
- emptyDir:
104+
sizeLimit: 500Gi
105+
name: test
106+
- configMap:
107+
items:
108+
- key: test
109+
path: /home/ray/test2/data.txt
110+
name: config-map-test
111+
name: test2
112+
- name: test3
113+
secret:
114+
secretName: test-secret
97115
- configMap:
98116
items:
99117
- key: ca-bundle.crt
@@ -146,6 +164,12 @@ spec:
146164
memory: 12G
147165
nvidia.com/gpu: 1
148166
volumeMounts:
167+
- mountPath: /home/ray/test1
168+
name: test
169+
- mountPath: /home/ray/test2
170+
name: test2
171+
- mountPath: /home/ray/test2
172+
name: test3
149173
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
150174
name: odh-trusted-ca-cert
151175
subPath: odh-trusted-ca-bundle.crt
@@ -162,6 +186,18 @@ spec:
162186
- name: secret1
163187
- name: secret2
164188
volumes:
189+
- emptyDir:
190+
sizeLimit: 500Gi
191+
name: test
192+
- configMap:
193+
items:
194+
- key: test
195+
path: /home/ray/test2/data.txt
196+
name: config-map-test
197+
name: test2
198+
- name: test3
199+
secret:
200+
secretName: test-secret
165201
- configMap:
166202
items:
167203
- key: ca-bundle.crt

tests/test_cluster_yamls/ray/unit-test-all-params.yaml

+36
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ spec:
6969
memory: 12G
7070
nvidia.com/gpu: 1
7171
volumeMounts:
72+
- mountPath: /home/ray/test1
73+
name: test
74+
- mountPath: /home/ray/test2
75+
name: test2
76+
- mountPath: /home/ray/test2
77+
name: test3
7278
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
7379
name: odh-trusted-ca-cert
7480
subPath: odh-trusted-ca-bundle.crt
@@ -85,6 +91,18 @@ spec:
8591
- name: secret1
8692
- name: secret2
8793
volumes:
94+
- emptyDir:
95+
sizeLimit: 500Gi
96+
name: test
97+
- configMap:
98+
items:
99+
- key: test
100+
path: /home/ray/test2/data.txt
101+
name: config-map-test
102+
name: test2
103+
- name: test3
104+
secret:
105+
secretName: test-secret
88106
- configMap:
89107
items:
90108
- key: ca-bundle.crt
@@ -137,6 +155,12 @@ spec:
137155
memory: 12G
138156
nvidia.com/gpu: 1
139157
volumeMounts:
158+
- mountPath: /home/ray/test1
159+
name: test
160+
- mountPath: /home/ray/test2
161+
name: test2
162+
- mountPath: /home/ray/test2
163+
name: test3
140164
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
141165
name: odh-trusted-ca-cert
142166
subPath: odh-trusted-ca-bundle.crt
@@ -153,6 +177,18 @@ spec:
153177
- name: secret1
154178
- name: secret2
155179
volumes:
180+
- emptyDir:
181+
sizeLimit: 500Gi
182+
name: test
183+
- configMap:
184+
items:
185+
- key: test
186+
path: /home/ray/test2/data.txt
187+
name: config-map-test
188+
name: test2
189+
- name: test3
190+
secret:
191+
secretName: test-secret
156192
- configMap:
157193
items:
158194
- key: ca-bundle.crt

0 commit comments

Comments
 (0)