I have the below test.yaml file where I am trying to update the revision number using python but it mess up the values, any idea how to fix it?
spec:
source:
helm:
valueFiles:
- ../secrets/secrets.yaml
values: |
custom:
address:
domain: services-uat.com
port: "80"
revision: 1.0.1
Python code:
version = "1.0.2"
resource_file = yaml.safe_load(open('test.yaml'))
source_exist = resource_file["spec"]["source"].get("helm")
VERSION_MATCHSTR = r"\s*revision\s*:\s*(\d+\.\d+\.\d+)"
revision_to_replace = re.search(VERSION_MATCHSTR, source_exist["values"]).group(
1
)
logger.info(f"Revision {revision_to_replace} will be replaced with {version}")
values_with_updated_version = source_exist["values"].replace(
revision_to_replace, f"{version}"
)
resource_file["spec"]["source"]["helm"].update(
{"values": values_with_updated_version}
)
with open('test.yaml', "w") as file:
yaml.safe_dump(resource_file, file)
Output:
spec:
source:
helm:
valueFiles:
- ../secrets/secrets.yaml
values: "custom:\n address:\n domain: services-uat.com\n\
\ port: \"80\"\nrevision: 1.0.2\n"