Skip to content

Commit f0f722b

Browse files
committed
fix(RHOAIENG-20531): propagate annotations to ray pods
Signed-off-by: Pat O'Connor <[email protected]>
1 parent c311665 commit f0f722b

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

Diff for: src/codeflare_sdk/common/utils/unit_test_support.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,10 @@ def create_cluster_all_config_params(mocker, cluster_name, is_appwrapper) -> Clu
498498
extended_resource_mapping={"example.com/gpu": "GPU", "intel.com/gpu": "TPU"},
499499
overwrite_default_resource_mapping=True,
500500
local_queue="local-queue-default",
501-
annotations={"key1": "value1", "key2": "value2"},
501+
annotations={
502+
"key1": "value1",
503+
"key2": "value2",
504+
},
502505
volumes=volumes,
503506
volume_mounts=volume_mounts,
504507
)

Diff for: src/codeflare_sdk/ray/cluster/build_ray_cluster.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,16 @@ def build_ray_cluster(cluster: "codeflare_sdk.ray.cluster.Cluster"):
139139
"num-gpus": str(head_gpu_count),
140140
"resources": head_resources,
141141
},
142-
"template": {
143-
"spec": get_pod_spec(
142+
"template": V1PodTemplateSpec(
143+
metadata=V1ObjectMeta(cluster.config.annotations)
144+
if cluster.config.annotations
145+
else None,
146+
spec=get_pod_spec(
144147
cluster,
145148
[get_head_container_spec(cluster)],
146149
cluster.config.head_tolerations,
147-
)
148-
},
150+
),
151+
),
149152
},
150153
"workerGroupSpecs": [
151154
{
@@ -159,11 +162,14 @@ def build_ray_cluster(cluster: "codeflare_sdk.ray.cluster.Cluster"):
159162
"resources": worker_resources,
160163
},
161164
"template": V1PodTemplateSpec(
165+
metadata=V1ObjectMeta(cluster.config.annotations)
166+
if cluster.config.annotations
167+
else None,
162168
spec=get_pod_spec(
163169
cluster,
164170
[get_worker_container_spec(cluster)],
165171
cluster.config.worker_tolerations,
166-
)
172+
),
167173
),
168174
}
169175
],
@@ -191,7 +197,7 @@ def build_ray_cluster(cluster: "codeflare_sdk.ray.cluster.Cluster"):
191197
# Metadata related functions
192198
def get_metadata(cluster: "codeflare_sdk.ray.cluster.Cluster"):
193199
"""
194-
The get_metadata() function builds and returns a V1ObjectMeta Object using cluster configurtation parameters
200+
The get_metadata() function builds and returns a V1ObjectMeta Object using cluster configuration parameters
195201
"""
196202
object_meta = V1ObjectMeta(
197203
name=cluster.config.name,
@@ -203,6 +209,7 @@ def get_metadata(cluster: "codeflare_sdk.ray.cluster.Cluster"):
203209
annotations = with_nb_annotations(cluster.config.annotations)
204210
if annotations != {}:
205211
object_meta.annotations = annotations # As annotations are not a guarantee they are appended to the metadata after creation.
212+
206213
return object_meta
207214

208215

Diff for: 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",

Diff for: 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:

Diff for: 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)