Skip to content

Commit 8cbb7aa

Browse files
fix remove by name function to not be in place
Signed-off-by: Kevin <[email protected]>
1 parent 07f79ad commit 8cbb7aa

File tree

6 files changed

+17
-46
lines changed

6 files changed

+17
-46
lines changed

src/codeflare_sdk/templates/base-template.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ spec:
198198
name: odh-trusted-ca-bundle
199199
items:
200200
- key: ca-bundle.crt
201-
path: odh-custom-ca-bundle.crt
201+
path: odh-trusted-ca-bundle.crt
202202
optional: true
203203
- name: odh-ca-cert
204204
configMap:
@@ -327,7 +327,7 @@ spec:
327327
name: odh-trusted-ca-bundle
328328
items:
329329
- key: ca-bundle.crt
330-
path: odh-custom-ca-bundle.crt
330+
path: odh-trusted-ca-bundle.crt
331331
optional: true
332332
- name: odh-ca-cert
333333
configMap:

src/codeflare_sdk/utils/generate_yaml.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -467,34 +467,38 @@ def enable_local_interactive(resources, cluster_name, namespace, ingress_domain)
467467
][0].get("command")[2] = command
468468

469469

470-
def del_from_list_by_name(l: list, target: typing.List[str]):
471-
for item in l:
472-
if item["name"] in ["ca-vol", "server-cert"]:
473-
l.remove(item)
470+
def del_from_list_by_name(l: list, target: typing.List[str]) -> list:
471+
return [x for x in l if x["name"] not in target]
474472

475473

476474
def disable_raycluster_tls(resources):
477475
generic_template_spec = resources["GenericItems"][0]["generictemplate"]["spec"]
478476

479-
del_from_list_by_name(
480-
generic_template_spec["headGroupSpec"]["template"]["spec"].get("volumes", []),
477+
headGroupTemplateSpec = generic_template_spec["headGroupSpec"]["template"]["spec"]
478+
headGroupTemplateSpec["volumes"] = del_from_list_by_name(
479+
headGroupTemplateSpec.get("volumes", []),
481480
["ca-vol", "server-cert"],
482481
)
483482

484483
c: dict
485484
for c in generic_template_spec["headGroupSpec"]["template"]["spec"]["containers"]:
486-
del_from_list_by_name(c.get("volumeMounts", []), ["ca-vol", "server-cert"])
485+
c["volumeMounts"] = del_from_list_by_name(
486+
c.get("volumeMounts", []), ["ca-vol", "server-cert"]
487+
)
487488

488489
if "initContainers" in generic_template_spec["headGroupSpec"]["template"]["spec"]:
489490
del generic_template_spec["headGroupSpec"]["template"]["spec"]["initContainers"]
490491

491-
for workerGroup in generic_template_spec.get("workerGroupSpecs"):
492-
del_from_list_by_name(
493-
workerGroup["template"]["spec"].get("volumes", []),
492+
for workerGroup in generic_template_spec.get("workerGroupSpecs", []):
493+
workerGroupSpec = workerGroup["template"]["spec"]
494+
workerGroupSpec["volumes"] = del_from_list_by_name(
495+
workerGroupSpec.get("volumes", []),
494496
["ca-vol", "server-cert"],
495497
)
496498
for c in workerGroup["template"]["spec"].get("containers", []):
497-
del_from_list_by_name(c.get("volumeMounts", []), ["ca-vol", "server-cert"])
499+
c["volumeMounts"] = del_from_list_by_name(
500+
c.get("volumeMounts", []), ["ca-vol", "server-cert"]
501+
)
498502

499503
del generic_template_spec["workerGroupSpecs"][0]["template"]["spec"][
500504
"initContainers"

tests/test-case-no-mcad.yamls

-10
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ spec:
7878
memory: 8G
7979
nvidia.com/gpu: 0
8080
volumeMounts:
81-
- mountPath: /home/ray/workspace/tls
82-
name: server-cert
83-
readOnly: true
8481
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
8582
name: odh-trusted-ca-cert
8683
subPath: odh-trusted-ca-bundle.crt
@@ -96,8 +93,6 @@ spec:
9693
imagePullSecrets:
9794
- name: unit-test-pull-secret
9895
volumes:
99-
- emptyDir: {}
100-
name: server-cert
10196
- configMap:
10297
items:
10398
- key: ca-bundle.crt
@@ -170,9 +165,6 @@ spec:
170165
memory: 5G
171166
nvidia.com/gpu: 7
172167
volumeMounts:
173-
- mountPath: /home/ray/workspace/tls
174-
name: server-cert
175-
readOnly: true
176168
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
177169
name: odh-trusted-ca-cert
178170
subPath: odh-trusted-ca-bundle.crt
@@ -188,8 +180,6 @@ spec:
188180
imagePullSecrets:
189181
- name: unit-test-pull-secret
190182
volumes:
191-
- emptyDir: {}
192-
name: server-cert
193183
- configMap:
194184
items:
195185
- key: ca-bundle.crt

tests/test-case-prio.yaml

-10
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ spec:
108108
memory: 8G
109109
nvidia.com/gpu: 0
110110
volumeMounts:
111-
- mountPath: /home/ray/workspace/tls
112-
name: server-cert
113-
readOnly: true
114111
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
115112
name: odh-trusted-ca-cert
116113
subPath: odh-trusted-ca-bundle.crt
@@ -127,8 +124,6 @@ spec:
127124
- name: unit-test-pull-secret
128125
priorityClassName: default
129126
volumes:
130-
- emptyDir: {}
131-
name: server-cert
132127
- configMap:
133128
items:
134129
- key: ca-bundle.crt
@@ -201,9 +196,6 @@ spec:
201196
memory: 5G
202197
nvidia.com/gpu: 7
203198
volumeMounts:
204-
- mountPath: /home/ray/workspace/tls
205-
name: server-cert
206-
readOnly: true
207199
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
208200
name: odh-trusted-ca-cert
209201
subPath: odh-trusted-ca-bundle.crt
@@ -220,8 +212,6 @@ spec:
220212
- name: unit-test-pull-secret
221213
priorityClassName: default
222214
volumes:
223-
- emptyDir: {}
224-
name: server-cert
225215
- configMap:
226216
items:
227217
- key: ca-bundle.crt

tests/test-case.yaml

-10
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ spec:
107107
memory: 8G
108108
nvidia.com/gpu: 0
109109
volumeMounts:
110-
- mountPath: /home/ray/workspace/tls
111-
name: server-cert
112-
readOnly: true
113110
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
114111
name: odh-trusted-ca-cert
115112
subPath: odh-trusted-ca-bundle.crt
@@ -125,8 +122,6 @@ spec:
125122
imagePullSecrets:
126123
- name: unit-test-pull-secret
127124
volumes:
128-
- emptyDir: {}
129-
name: server-cert
130125
- configMap:
131126
items:
132127
- key: ca-bundle.crt
@@ -199,9 +194,6 @@ spec:
199194
memory: 5G
200195
nvidia.com/gpu: 7
201196
volumeMounts:
202-
- mountPath: /home/ray/workspace/tls
203-
name: server-cert
204-
readOnly: true
205197
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
206198
name: odh-trusted-ca-cert
207199
subPath: odh-trusted-ca-bundle.crt
@@ -217,8 +209,6 @@ spec:
217209
imagePullSecrets:
218210
- name: unit-test-pull-secret
219211
volumes:
220-
- emptyDir: {}
221-
name: server-cert
222212
- configMap:
223213
items:
224214
- key: ca-bundle.crt

tests/unit_test.py

-3
Original file line numberDiff line numberDiff line change
@@ -2756,9 +2756,6 @@ def test_enable_local_interactive(mocker):
27562756
head_group_spec["template"]["spec"]["initContainers"][0]["volumeMounts"]
27572757
== volume_mounts
27582758
)
2759-
print(head_group_spec["template"]["spec"]["volumes"])
2760-
print("----------------")
2761-
print(volumes)
27622759
assert head_group_spec["template"]["spec"]["volumes"] == volumes
27632760

27642761
# 2. workerGroupSpec has the initContainers command to generated TLS cert from the mounted CA cert.

0 commit comments

Comments
 (0)