fierce-market-67222
02/21/2022, 1:21 PMdef set_deployment_env_var(obj, opts):
if obj["kind"] == "Deployment":
obj["spec"]["template"]["spec"]["containers[0]"] = [
{
"env": [
{
"name": "RELEASE_DATE",
"value": "....."
},
]
}
]
prehistoric-activity-61023
02/21/2022, 2:45 PMobj["spec"]["template"]["spec"]["containers[0]"]
looks suspicious to me at the first glanceobj["spec"]["template"]["spec"]["containers"][0]["env"] = ...
I strongly doubt something in the middle converts containers
array so it’s accessible under containers[X]
-like keysfrom typing import List, Dict
...
def overwrite_env(envs: List[Dict], name: str, new_value: str) -> bool:
for env in envs:
if env["name"] == name:
env["value"] = new_value
return True
return False
...
def set_deployment_env_var(obj, opts):
if obj["kind"] == "Deployment":
envs = obj["spec"]["template"]["spec"]["containers"][0]["env"]
overwrite_env(envs, "RELASE_DATE", "my-new-value-as-string")
fierce-market-67222
02/21/2022, 9:00 PM