How to force string value with variable substitution? #1795
-
|
I'm using variable substitution to replace values in the manifests applied by Kustomization (using If I do How do I get |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 4 replies
-
This is super awkward, but I believe this is how it's done. There was a thread on the CNCF slack #flux about this, credit to Ben A for finding the workaround. https://cloud-native.slack.com/archives/CLAJ40HV3/p1623953195127500?thread_ts=1623949464.122200&cid=CLAJ40HV3 |
Beta Was this translation helpful? Give feedback.
-
|
This workaround no longer works. See here for our solution: #1839 (comment) |
Beta Was this translation helpful? Give feedback.
-
|
Is there any workaround when the variable substitution is not done in a helm template, but e.g. for a standard cert-manager certificate resource? apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: "${CERTIFICATE_NAME}"
namespace: edge
spec:
secretName: "${CERTIFICATE_NAME}"
issuerRef:
name: my-cert
kind: ClusterIssuer
dnsNames:
- "${CERTIFICATE_DOMAIN}" |
Beta Was this translation helpful? Give feedback.
-
|
To force the conversion of variables to string see the docs here: https://fluxcd.io/flux/components/kustomize/kustomizations/#post-build-substitution-of-numbers-and-booleans |
Beta Was this translation helpful? Give feedback.
-
|
As a (gruesome) workaround, "protect" a YAML type-tag from earlier passes with Handily this also works to protect truth-ish values by ensuring they also get properly quoted. Example input: kind: fake
metadata:
name: fake
value: '${DELIBERATELY_UNDEFINED:=!!str }${MYVARIABLE:=10000000}'Output of kind: fake
metadata:
name: fake
value: "10000000"Output of kind: fake
metadata:
name: fake
value: "100"Output of kind: fake
metadata:
name: fake
value: string valuedNote that the string value is injected correctly, without unwanted double-double quotes. Note that this trick will emit an unwanted log message like: that there isn't much to be done about. This is related to the way yaml libs like that used by kustomize strip quoting that's not syntactically required at that time; see kubernetes-sigs/kustomize#4845 This is still kind of a code-crime, it's a really ugly workaround for using a text-based substitution that's not fully yaml-aware. Using a fully yaml-aware tool like |
Beta Was this translation helpful? Give feedback.

To force the conversion of variables to string see the docs here: https://fluxcd.io/flux/components/kustomize/kustomizations/#post-build-substitution-of-numbers-and-booleans