applicationset
applicationset copied to clipboard
Cannot template syncPolicy parameters because of applicationset validation
In the optics of self-serve, I would like to let each team specify their "prune" and "selfHeal" parameters from syncPolicy. To do so, I am using the following applicationset:
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: XX-bootstrap
namespace: argocd
annotations:
argocd.argoproj.io/sync-options: Validate=false
spec:
generators:
- git:
repoURL: "somegitrepo"
revision: HEAD
files:
- path: apps/dev/**/config.yaml
template:
metadata:
name: "XX-{{app.name}}"
spec:
project: XX
source:
repoURL: "somegitrepo"
targetRevision: HEAD
path: "{{app.path}}"
destination:
server: https://kubernetes.default.svc
namespace: XX
syncPolicy:
automated:
allowEmpty: true
prune: "{{app.sync.prune}}"
selfHeal: "{{app.sync.selfHeal}}"
The problem arises because "{{app.sync.prune}}" is not a boolean but rather a string:
I also cannot remove the double quotes, since my applicationset passes through kustomize. Therefore using the form {{app.sync.prune}} would result in
Error: map[string]interface {}(nil): yaml: invalid map key: map[string]interface {}{"app.sync.prune":""}
As you can see in the yaml above, I also tried to disable the validation using
annotations:
argocd.argoproj.io/sync-options: Validate=false
however that did not seem to help.
Have you tried omitting the quotes around the templated values? I.e.
prune: {{app.sync.prune}}
selfHeal: {{app.sync.selfHeal}}
Your syntax-checker will probably be red, but it might just work :-)
As mentioned in the original post, I cannot because it will cause problems with kustomize:
I also cannot remove the double quotes, since my applicationset passes through kustomize. Therefore using the form {{app.sync.prune}} would result in Error: map[string]interface {}(nil): yaml: invalid map key: map[string]interface {}{"app.sync.prune":""}
@olvesh
Have you tried omitting the quotes around the templated values?
I even tried this on plain kubectl apply - doesn't work, since it's still being converted to JSON, and during conversion {{anything here}} being failed with error like:
invalid map key: map[interface {}]interface {}{"prune":interface {}(nil)}
Looks like now the only solution is to annotate for non-deletion each separated resource created by the application definition. Here's the doc for it
Is there any plan to support this feature? :( it's a quite common scenario. For example:
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: bookinfo
namespace: argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
generators:
- list:
elements:
- environment: dev
cluster: lab-nonprod
prune: true
selfHeal: true
- environment: qa
cluster: lab-nonprod
prune: true
selfHeal: false
template:
metadata:
name: 'bookinfo-{{environment}}'
spec:
project: "bookinfo"
source:
repoURL: https://myrepo.com/k8s-template-deployment.git
targetRevision: HEAD
path: '.deploy/kustomize/overlays/{{environment}}'
destination:
name: '{{cluster}}'
namespace: 'project-bookinfo-{{environment}}'
syncPolicy:
automated:
prune: '{{prune}}'
selfHeal: '{{selfHeal}}'
syncOptions:
- CreateNamespace=true
is Helm the only clean solution right now?
Any updates this problem??
any update?
Any update on this issue? I need to use a template for rendering boolean values for the skipCrds field.
Any update on this issue? It seems unclear how to manage different syncPolicies for different applications in the same application set?
any updates? i'm still experiencing the same issues with skipCrds key, it expects a bool :(
skipCrds: "{{skipCrds}}"
Any updates on this? I really need to be able to specify dynamic syncPolicy in the app file for appSets.
This is what I did for now until this feature is ready
- Set skipCrds flag to true for all application sets, this will ignore all the CRDs that are placed inside of the crds folder of the chart
- Place the CRDs you want to install inside of the templates directory of the chart, where the skipCrds flag will not have any effect (for more information, check helm docs)
I hope this feature will be ready soon.
I have also encountered this problem, Is there any chance this will be fixed soon? Doesn't Go lang convert string to bool?
I hope this feature will be ready soon
Hi 👋 Any updates on this ?
It seems like the problem here is that ArgoCD first validates YAML, then runs templating engine, not vise-versa. Whatever you do you can not render parts of YAML in this case if it's not a string.