Skip to content

fix(RHOAIENG-20531): propagate annotations to ray pods #809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/codeflare_sdk/common/utils/unit_test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,10 @@ def create_cluster_all_config_params(mocker, cluster_name, is_appwrapper) -> Clu
extended_resource_mapping={"example.com/gpu": "GPU", "intel.com/gpu": "TPU"},
overwrite_default_resource_mapping=True,
local_queue="local-queue-default",
annotations={"key1": "value1", "key2": "value2"},
annotations={
"key1": "value1",
"key2": "value2",
},
volumes=volumes,
volume_mounts=volume_mounts,
)
Expand Down
19 changes: 13 additions & 6 deletions src/codeflare_sdk/ray/cluster/build_ray_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,16 @@ def build_ray_cluster(cluster: "codeflare_sdk.ray.cluster.Cluster"):
"num-gpus": str(head_gpu_count),
"resources": head_resources,
},
"template": {
"spec": get_pod_spec(
"template": V1PodTemplateSpec(
metadata=V1ObjectMeta(cluster.config.annotations)
if cluster.config.annotations
else None,
spec=get_pod_spec(
cluster,
[get_head_container_spec(cluster)],
cluster.config.head_tolerations,
)
},
),
),
},
"workerGroupSpecs": [
{
Expand All @@ -159,11 +162,14 @@ def build_ray_cluster(cluster: "codeflare_sdk.ray.cluster.Cluster"):
"resources": worker_resources,
},
"template": V1PodTemplateSpec(
metadata=V1ObjectMeta(cluster.config.annotations)
if cluster.config.annotations
else None,
spec=get_pod_spec(
cluster,
[get_worker_container_spec(cluster)],
cluster.config.worker_tolerations,
)
),
),
}
],
Expand Down Expand Up @@ -191,7 +197,7 @@ def build_ray_cluster(cluster: "codeflare_sdk.ray.cluster.Cluster"):
# Metadata related functions
def get_metadata(cluster: "codeflare_sdk.ray.cluster.Cluster"):
"""
The get_metadata() function builds and returns a V1ObjectMeta Object using cluster configurtation parameters
The get_metadata() function builds and returns a V1ObjectMeta Object using cluster configuration parameters
"""
object_meta = V1ObjectMeta(
name=cluster.config.name,
Expand All @@ -203,6 +209,7 @@ def get_metadata(cluster: "codeflare_sdk.ray.cluster.Cluster"):
annotations = with_nb_annotations(cluster.config.annotations)
if annotations != {}:
object_meta.annotations = annotations # As annotations are not a guarantee they are appended to the metadata after creation.

return object_meta


Expand Down
2 changes: 2 additions & 0 deletions src/codeflare_sdk/ray/cluster/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_default_cluster_creation(mocker):
f"{expected_clusters_dir}/ray/default-ray-cluster.yaml",
get_template_variables(),
)

assert cluster.resource_yaml == expected_rc


Expand Down Expand Up @@ -114,6 +115,7 @@ def test_config_creation_all_parameters(mocker):
@pytest.mark.filterwarnings("ignore::UserWarning")
def test_all_config_params_aw(mocker):
create_cluster_all_config_params(mocker, "aw-all-params", True)

assert filecmp.cmp(
f"{aw_dir}aw-all-params.yaml",
f"{expected_clusters_dir}/appwrapper/unit-test-all-params.yaml",
Expand Down
10 changes: 10 additions & 0 deletions tests/test_cluster_yamls/appwrapper/unit-test-all-params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ spec:
resources: '"{\"TPU\": 2}"'
serviceType: ClusterIP
template:
metadata:
annotations:
app.kubernetes.io/managed-by: test-prefix
key1: value1
key2: value2
spec:
containers:
- env:
Expand Down Expand Up @@ -142,6 +147,11 @@ spec:
resources: '"{}"'
replicas: 10
template:
metadata:
annotations:
app.kubernetes.io/managed-by: test-prefix
key1: value1
key2: value2
spec:
containers:
- env:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_cluster_yamls/ray/unit-test-all-params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ spec:
resources: '"{\"TPU\": 2}"'
serviceType: ClusterIP
template:
metadata:
annotations:
app.kubernetes.io/managed-by: test-prefix
key1: value1
key2: value2
spec:
containers:
- env:
Expand Down Expand Up @@ -133,6 +138,11 @@ spec:
resources: '"{}"'
replicas: 10
template:
metadata:
annotations:
app.kubernetes.io/managed-by: test-prefix
key1: value1
key2: value2
spec:
containers:
- env:
Expand Down
Loading