Skip to content

Commit 901de36

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

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,11 @@ 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+
"app.kubernetes.io/managed-by": "test-prefix",
503+
"key1": "value1",
504+
"key2": "value2",
505+
},
502506
volumes=volumes,
503507
volume_mounts=volume_mounts,
504508
)

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

+10-7
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,14 @@ 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) if cluster.config.annotations else None,
144+
spec=get_pod_spec(
144145
cluster,
145146
[get_head_container_spec(cluster)],
146147
cluster.config.head_tolerations,
147-
)
148-
},
148+
),
149+
),
149150
},
150151
"workerGroupSpecs": [
151152
{
@@ -159,11 +160,12 @@ def build_ray_cluster(cluster: "codeflare_sdk.ray.cluster.Cluster"):
159160
"resources": worker_resources,
160161
},
161162
"template": V1PodTemplateSpec(
163+
metadata=V1ObjectMeta(cluster.config.annotations) if cluster.config.annotations else None,
162164
spec=get_pod_spec(
163165
cluster,
164166
[get_worker_container_spec(cluster)],
165167
cluster.config.worker_tolerations,
166-
)
168+
),
167169
),
168170
}
169171
],
@@ -191,7 +193,7 @@ def build_ray_cluster(cluster: "codeflare_sdk.ray.cluster.Cluster"):
191193
# Metadata related functions
192194
def get_metadata(cluster: "codeflare_sdk.ray.cluster.Cluster"):
193195
"""
194-
The get_metadata() function builds and returns a V1ObjectMeta Object using cluster configurtation parameters
196+
The get_metadata() function builds and returns a V1ObjectMeta Object using cluster configuration parameters
195197
"""
196198
object_meta = V1ObjectMeta(
197199
name=cluster.config.name,
@@ -203,7 +205,8 @@ def get_metadata(cluster: "codeflare_sdk.ray.cluster.Cluster"):
203205
annotations = with_nb_annotations(cluster.config.annotations)
204206
if annotations != {}:
205207
object_meta.annotations = annotations # As annotations are not a guarantee they are appended to the metadata after creation.
206-
return object_meta
208+
209+
return object_meta
207210

208211

209212
def get_labels(cluster: "codeflare_sdk.ray.cluster.Cluster"):

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

+3-1
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

@@ -103,7 +104,7 @@ def test_config_creation_all_parameters(mocker):
103104
}
104105
assert cluster.config.volumes == volumes
105106
assert cluster.config.volume_mounts == volume_mounts
106-
107+
107108
assert filecmp.cmp(
108109
f"{aw_dir}test-all-params.yaml",
109110
f"{expected_clusters_dir}/ray/unit-test-all-params.yaml",
@@ -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)