Skip to content

Commit 340f973

Browse files
chipspeaklaurafitzgerald
authored andcommitted
fix(RHOAIENG-20531): propagate annotations to ray pods
Signed-off-by: Pat O'Connor <[email protected]>
1 parent e46ee4c commit 340f973

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

src/codeflare_sdk/common/utils/unit_test_support.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,10 @@ def create_cluster_all_config_params(mocker, cluster_name, is_appwrapper) -> Clu
496496
extended_resource_mapping={"example.com/gpu": "GPU", "intel.com/gpu": "TPU"},
497497
overwrite_default_resource_mapping=True,
498498
local_queue="local-queue-default",
499-
annotations={"key1": "value1", "key2": "value2"},
499+
annotations={
500+
"key1": "value1",
501+
"key2": "value2",
502+
},
500503
volumes=volumes,
501504
volume_mounts=volume_mounts,
502505
)

src/codeflare_sdk/ray/cluster/build_ray_cluster.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,16 @@ def build_ray_cluster(cluster: "codeflare_sdk.ray.cluster.Cluster"):
138138
"num-gpus": str(head_gpu_count),
139139
"resources": head_resources,
140140
},
141-
"template": {
142-
"spec": get_pod_spec(
141+
"template": V1PodTemplateSpec(
142+
metadata=V1ObjectMeta(cluster.config.annotations)
143+
if cluster.config.annotations
144+
else None,
145+
spec=get_pod_spec(
143146
cluster,
144147
[get_head_container_spec(cluster)],
145148
cluster.config.head_tolerations,
146-
)
147-
},
149+
),
150+
),
148151
},
149152
"workerGroupSpecs": [
150153
{
@@ -158,11 +161,14 @@ def build_ray_cluster(cluster: "codeflare_sdk.ray.cluster.Cluster"):
158161
"resources": worker_resources,
159162
},
160163
"template": V1PodTemplateSpec(
164+
metadata=V1ObjectMeta(cluster.config.annotations)
165+
if cluster.config.annotations
166+
else None,
161167
spec=get_pod_spec(
162168
cluster,
163169
[get_worker_container_spec(cluster)],
164170
cluster.config.worker_tolerations,
165-
)
171+
),
166172
),
167173
}
168174
],
@@ -215,7 +221,7 @@ def build_ray_cluster(cluster: "codeflare_sdk.ray.cluster.Cluster"):
215221
# Metadata related functions
216222
def get_metadata(cluster: "codeflare_sdk.ray.cluster.Cluster"):
217223
"""
218-
The get_metadata() function builds and returns a V1ObjectMeta Object using cluster configurtation parameters
224+
The get_metadata() function builds and returns a V1ObjectMeta Object using cluster configuration parameters
219225
"""
220226
object_meta = V1ObjectMeta(
221227
name=cluster.config.name,
@@ -227,6 +233,7 @@ def get_metadata(cluster: "codeflare_sdk.ray.cluster.Cluster"):
227233
annotations = with_nb_annotations(cluster.config.annotations)
228234
if annotations != {}:
229235
object_meta.annotations = annotations # As annotations are not a guarantee they are appended to the metadata after creation.
236+
230237
return object_meta
231238

232239

src/codeflare_sdk/ray/cluster/test_config.py

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def test_default_cluster_creation(mocker):
4141
f"{expected_clusters_dir}/ray/default-ray-cluster.yaml",
4242
get_template_variables(),
4343
)
44+
4445
assert cluster.resource_yaml == expected_rc
4546

4647

@@ -114,6 +115,7 @@ def test_config_creation_all_parameters(mocker):
114115
@pytest.mark.filterwarnings("ignore::UserWarning")
115116
def test_all_config_params_aw(mocker):
116117
create_cluster_all_config_params(mocker, "aw-all-params", True)
118+
117119
assert filecmp.cmp(
118120
f"{aw_dir}aw-all-params.yaml",
119121
f"{expected_clusters_dir}/appwrapper/unit-test-all-params.yaml",

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

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ spec:
4242
resources: '"{\"TPU\": 2}"'
4343
serviceType: ClusterIP
4444
template:
45+
metadata:
46+
annotations:
47+
app.kubernetes.io/managed-by: test-prefix
48+
key1: value1
49+
key2: value2
4550
spec:
4651
containers:
4752
- env:
@@ -142,6 +147,11 @@ spec:
142147
resources: '"{}"'
143148
replicas: 10
144149
template:
150+
metadata:
151+
annotations:
152+
app.kubernetes.io/managed-by: test-prefix
153+
key1: value1
154+
key2: value2
145155
spec:
146156
containers:
147157
- env:

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

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ spec:
3333
resources: '"{\"TPU\": 2}"'
3434
serviceType: ClusterIP
3535
template:
36+
metadata:
37+
annotations:
38+
app.kubernetes.io/managed-by: test-prefix
39+
key1: value1
40+
key2: value2
3641
spec:
3742
containers:
3843
- env:
@@ -133,6 +138,11 @@ spec:
133138
resources: '"{}"'
134139
replicas: 10
135140
template:
141+
metadata:
142+
annotations:
143+
app.kubernetes.io/managed-by: test-prefix
144+
key1: value1
145+
key2: value2
136146
spec:
137147
containers:
138148
- env:

0 commit comments

Comments
 (0)