vfarcic / crossplane-sql

8 stars 6 forks source link

Pushsecret wont work if using argoCD #16

Open tm-nadavsh opened 6 months ago

tm-nadavsh commented 6 months ago

After watching the video, tried to implement the pushSecret part in my own code via argoCD, when doing so i wasnt able to actually render the secret values at:

template:
  data:
    endpoint: |
      {
        "endpoint": "{{ .endpoint }}",
        "port": "{{ .port }}",
        "username": "{{ .username }}",
        "password": "{{ .password }}"[[ range .observed.composite.resource.spec.parameters.databases ]],
        "conn-[[ . ]]": "host={{ .endpoint }} user={{ .username }} password={{ .password }} port={{ .port }} connect_timeout=10 database=[[ . ]]"[[ end ]]
      }

after some investigation i understood that the issue is that this is a template and in argoCD i also template a helm chart, so if using just curly brackets it will render during the initial rendering of helm and then when the pushSecret Object is actually created it will have something like:

{
        "endpoint": "",
        "port": "",
        "username": "", 
rest of code ...
}

The solution is to escape the curly brackets with another curly brackets like so:

{
  "endpoint": "{{`{{ .endpoint }}`}}",
  "port": "{{`{{ .port }}`}}",
  "username": "{{`{{ .username }}`}}",
 ... rest of code
}

This was after the helm template we will still have the desired values in the pushSecret object.

IDK if this fix should be in the code but i think it should be at least mentioned some where as it took me a good amount of time to find the issue and it could save time for other developers

vfarcic commented 6 months ago

I'm assuming that Go Template function code. If that's the case, you can use delims.left and delims.right to specify different delimitators. I, for example, tended to use [[ and ]] instead.

As a side note, after using Go Template, CUE, and KCL functions for, more or less, the same outcome, I settled on KCL.