carvel-dev / ytt

YAML templating tool that works on YAML structure instead of text
https://carvel.dev/ytt
Apache License 2.0
1.63k stars 137 forks source link

[Question]::Can we replace and Remove yaml keys with single configuration ? #827

Open UPADHYA28 opened 1 year ago

UPADHYA28 commented 1 year ago

Hi Team,

This question might seem very basic, but i am a new user of ytt and still in exploration mode.

I have following templates. Base Template:

`---
apiVersion: 1
specification: 
  versions:
    - name: v1
      schema:
        openAPIV3Schema:
          properties:
            spec:
              myConfiguration:
                description: Customized Configuration
`

Key Replace Template:

`
#@ load("@ytt:overlay", "overlay")
#@ load("@ytt:data", "data")
#@overlay/match by=overlay.all
---
apiVersion: 1
specification: 
  versions:
  #@overlay/match by=overlay.all, expects="1+"
    - schema:
        #@overlay/replace via=lambda left, right: {"properties": right}
        openAPIV3Schema:
            spec:
              new_myConfiguration:
              #@overlay/replace via=lambda left, right: {"properties": right}
                new_description: Modified Configuration
              new_key: avinash
`

Key_Remove_Template:

#@ load("@ytt:overlay", "overlay")
#@ load("@ytt:data", "data")
#@overlay/match by=overlay.all
---
apiVersion: 1
specification: 
  versions:
  #@overlay/match by=overlay.all, missing_ok=True
    - schema:
        openAPIV3Schema:
          properties:
            spec:
              #@overlay/match when=lambda right: data.values.client == "local_client"
              #@overlay/remove
              new_myConfiguration:

So basically i am trying to rename myConfiguration provided client !="local_client", and if then remove myConfiguration altogether.

github-actions[bot] commented 1 year ago

This issue is being marked as stale due to a long period of inactivity and will be closed in 5 days if there is no response.

vmunishwar commented 1 year ago

@UPADHYA28 Sorry for the late response. We would like to know if you are still blocked on this issue or you were able to find the solution. Thanks for reaching out