Hello i want to overwrite an env_var in a helm cha...
# python
f
Hello i want to overwrite an env_var in a helm chart via transformations, the code is below, any ideea how can i get this done? Thank you
Copy code
def set_deployment_env_var(obj, opts):
    if obj["kind"] == "Deployment":
        obj["spec"]["template"]["spec"]["containers[0]"] = [
            {
                "env": [
                    {
                        "name": "RELEASE_DATE",
                        "value": "....."
                    },
                ]
            }
        ]
p
hmm, does it work for you?
the part
obj["spec"]["template"]["spec"]["containers[0]"]
looks suspicious to me at the first glance
I haven’t tested that but I’d write:
Copy code
obj["spec"]["template"]["spec"]["containers"][0]["env"] = ...
I strongly doubt something in the middle converts
containers
array so it’s accessible under
containers[X]
-like keys
If you ask how to overwrite an entry within a list in python, you can do something like that:
Copy code
from 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")
f
thank you worked like a charm 😄
🙌 1