Skip to content

Commit

Permalink
Added Unit tests for custom volumes and volume mounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobbins228 authored and openshift-merge-bot[bot] committed Jun 18, 2024
1 parent c68d425 commit 20476aa
Show file tree
Hide file tree
Showing 2 changed files with 248 additions and 0 deletions.
186 changes: 186 additions & 0 deletions tests/unit-test-volume-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
apiVersion: ray.io/v1
kind: RayCluster
metadata:
labels:
controller-tools.k8s.io: '1.0'
kueue.x-k8s.io/queue-name: local-queue-default
name: unit-test-volume-cluster
namespace: opendatahub
spec:
autoscalerOptions:
idleTimeoutSeconds: 60
imagePullPolicy: Always
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 500m
memory: 512Mi
upscalingMode: Default
enableInTreeAutoscaling: false
headGroupSpec:
enableIngress: false
rayStartParams:
block: 'true'
dashboard-host: 0.0.0.0
num-gpus: '0'
serviceType: ClusterIP
template:
spec:
containers:
- image: quay.io/project-codeflare/ray:latest-py39-cu118
imagePullPolicy: Always
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- ray stop
name: ray-head
ports:
- containerPort: 6379
name: gcs
- containerPort: 8265
name: dashboard
- containerPort: 10001
name: client
resources:
limits:
cpu: 2
memory: 8G
nvidia.com/gpu: 0
requests:
cpu: 2
memory: 8G
nvidia.com/gpu: 0
volumeMounts:
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
name: odh-trusted-ca-cert
subPath: odh-trusted-ca-bundle.crt
- mountPath: /etc/ssl/certs/odh-trusted-ca-bundle.crt
name: odh-trusted-ca-cert
subPath: odh-trusted-ca-bundle.crt
- mountPath: /etc/pki/tls/certs/odh-ca-bundle.crt
name: odh-ca-cert
subPath: odh-ca-bundle.crt
- mountPath: /etc/ssl/certs/odh-ca-bundle.crt
name: odh-ca-cert
subPath: odh-ca-bundle.crt
- mountPath: /home/ray/test1
name: test
- mountPath: /home/ray/test2
name: test2
- mountPath: /home/ray/test2
name: test3
imagePullSecrets: []
volumes:
- configMap:
items:
- key: ca-bundle.crt
path: odh-trusted-ca-bundle.crt
name: odh-trusted-ca-bundle
optional: true
name: odh-trusted-ca-cert
- configMap:
items:
- key: odh-ca-bundle.crt
path: odh-ca-bundle.crt
name: odh-trusted-ca-bundle
optional: true
name: odh-ca-cert
- emptyDir:
sizeLimit: 500Gi
name: test
- configMap:
items:
- key: test
path: /home/ray/test2/data.txt
name: config-map-test
name: test2
- name: test3
secret:
secretName: test-secret
rayVersion: 2.7.0
workerGroupSpecs:
- groupName: small-group-unit-test-volume-cluster
maxReplicas: 1
minReplicas: 1
rayStartParams:
block: 'true'
num-gpus: '0'
replicas: 1
template:
metadata:
annotations:
key: value
labels:
key: value
spec:
containers:
- image: quay.io/project-codeflare/ray:latest-py39-cu118
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- ray stop
name: machine-learning
resources:
limits:
cpu: 1
memory: 2G
nvidia.com/gpu: 0
requests:
cpu: 1
memory: 2G
nvidia.com/gpu: 0
volumeMounts:
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
name: odh-trusted-ca-cert
subPath: odh-trusted-ca-bundle.crt
- mountPath: /etc/ssl/certs/odh-trusted-ca-bundle.crt
name: odh-trusted-ca-cert
subPath: odh-trusted-ca-bundle.crt
- mountPath: /etc/pki/tls/certs/odh-ca-bundle.crt
name: odh-ca-cert
subPath: odh-ca-bundle.crt
- mountPath: /etc/ssl/certs/odh-ca-bundle.crt
name: odh-ca-cert
subPath: odh-ca-bundle.crt
- mountPath: /home/ray/test1
name: test
- mountPath: /home/ray/test2
name: test2
- mountPath: /home/ray/test2
name: test3
imagePullSecrets: []
volumes:
- configMap:
items:
- key: ca-bundle.crt
path: odh-trusted-ca-bundle.crt
name: odh-trusted-ca-bundle
optional: true
name: odh-trusted-ca-cert
- configMap:
items:
- key: odh-ca-bundle.crt
path: odh-ca-bundle.crt
name: odh-trusted-ca-bundle
optional: true
name: odh-ca-cert
- emptyDir:
sizeLimit: 500Gi
name: test
- configMap:
items:
- key: test
path: /home/ray/test2/data.txt
name: config-map-test
name: test2
- name: test3
secret:
secretName: test-secret
62 changes: 62 additions & 0 deletions tests/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,68 @@ def test_default_cluster_creation(mocker):
assert cluster.config.namespace == "opendatahub"


def test_cluster_with_custom_volumes(mocker):
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
mocker.patch(
"codeflare_sdk.cluster.cluster.get_current_namespace",
return_value="opendatahub",
)
mocker.patch(
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
return_value=get_local_queue("kueue.x-k8s.io", "v1beta1", "ns", "localqueues"),
)

from kubernetes.client import (
V1Volume,
V1VolumeMount,
V1EmptyDirVolumeSource,
V1ConfigMapVolumeSource,
V1KeyToPath,
V1SecretVolumeSource,
)

volume_mounts = [
V1VolumeMount(mount_path="/home/ray/test1", name="test"),
V1VolumeMount(
mount_path="/home/ray/test2",
name="test2",
),
V1VolumeMount(
mount_path="/home/ray/test2",
name="test3",
),
]

volumes = [
V1Volume(
name="test",
empty_dir=V1EmptyDirVolumeSource(size_limit="500Gi"),
),
V1Volume(
name="test2",
config_map=V1ConfigMapVolumeSource(
name="config-map-test",
items=[V1KeyToPath(key="test", path="/home/ray/test2/data.txt")],
),
),
V1Volume(name="test3", secret=V1SecretVolumeSource(secret_name="test-secret")),
]

test_config = ClusterConfiguration(
name="unit-test-volume-cluster",
image="quay.io/project-codeflare/ray:latest-py39-cu118",
volume_mounts=volume_mounts,
volumes=volumes,
)
cluster = Cluster(test_config)
test_rc = yaml.load(cluster.app_wrapper_yaml, Loader=yaml.FullLoader)
with open(
f"{parent}/tests/unit-test-volume-cluster.yaml",
) as f:
volume_rc = yaml.load(f, Loader=yaml.FullLoader)
assert test_rc == volume_rc


def test_gen_names_with_name(mocker):
mocker.patch.object(
uuid, "uuid4", return_value=uuid.UUID("00000000-0000-0000-0000-000000000001")
Expand Down

0 comments on commit 20476aa

Please sign in to comment.