Check and update nested values in yaml with Helm

40 views Asked by At

I have a yaml value file that looks like below

authorization:
  allow:
    enabled: true
    name: microservice-authz
    rules:
      - to:
          - operation:
              methods: ["GET"]
        from:
          - source:
              principals:
                - "service-account-a"
          - source:
              principals:
                - "service-account-c"
          - source:
              namespaces:
                - document

In my helm template I want to check:

In each authorization.allow.rules, if "service-account-a" exists in any of the from.source.principals , add "service-account-b" to the existing principals, while keeping the other source such as "namespaces" unchanged, so the output yaml should be sth like:

authorization:
 allow:
   enabled: true
   name: microservice-authz
   rules:
     - to:
         - operation:
             methods: ["GET"]
       from:
         - source:
             principals:
               - "service-account-a"
               - "service-account-b"
         - source:
             principals:
               - "service-account-c"
         - source:
             namespaces:
               - document

Appreciate any recommendation on how to approach this cleanly, so far I tried to convert the input to a json object using the helm toJson function, but I still cannot directly manipulate that object

0

There are 0 answers