Closed zimmertr closed 1 year ago
Turns out Argo can use Go Text Templating and this can be done like this instead!
destination:
name: '{{ ternary "bar-bar-foo-foo-management-cluster" (printf "foo-foo-bar-bar-%s-cluster" (.path.basenameNormalized) (eq .path.basenameNormalized "management" ) }}'
Summary:
When using a generator with an ApplicationSet, for example
git
, one may wish to conditionally set theDestination
of the generated Applications. Jinja2 conditionals normally enable this logic. Argo's usage of Jinja2 conditionals does not support it, however. Consider the following example:Current Behavior:
Imagine you have Argo deploying Applications to a handful of clusters using an ApplicationSet. We'll name these clusters:
You could then create an Kustomize overlay in your git repository named after the cluster:
And configure your ApplicationSet to reference them with a wildcard:
And then you can reference the destination cluster by name easily using the ApplicationSet's built in
path
parameter:Now imagine you have a handful of clusters that follow varying naming conventions. Worse yet, imagine their names are long. (Like even longer than these) For example:
If you created overlays for them in your repository it would look like this:
You can still use the same
path
parameter to reference them:However, each of your overlays in your git repository must also be long and repetitive. If Argo ApplicationSets supported Jinja Conditionals, this could be cleaned up a lot. For example, your overlays could instead be named:
And you could assemble the cluster name using a conditional in your ApplicationSet:
Which would make your git repository have less redundancy and appear more legible. I tried to use a Jinja Conditional as expressed above, And Argo returned the following error: