kustomize-controller
kustomize-controller copied to clipboard
Weird errors when using tab characters in ConfigMap files and having variable substitution turned on
I have an Nginx configuration that is loaded into a config map. I was using variable substitution functionality from Flux Kustomization and this caused weird errors.
It turns out that tab character cause seriously weird behavior in files consumed by configMapGenerator while using Flux Kustomization var substitution. Moreover, the errors are rather non-descriptive as seen below.
apps/production/file.conf (example one)
# \.
This will emit the following error
2021-09-16T11:33:33.501Z error Kustomization/apps.flux-system - Reconciliation failed after 669.431336ms, next try in 1h0m0s var substitution failed for 'apps-configmap-ui-login-nginx-659t4k625b': YAMLToJSON: yaml: line 3: found unknown escape character
apps/production/file.conf (example two)
a
This will emit the following error
2021-09-16T12:19:55.326Z error Kustomization/apps.flux-system - Reconciliation failed after 76.578562ms, next try in 1h0m0s kustomize build failed: yaml: line 2: found a tab character where an indentation space is expected
I would like to be able to use tabs in my configuration files that I load through ConfigMaps while using var substitution. This can be worked around by making sure to only use spaces instead of tabs.
Setup
cluster/prduction/apps.yaml
apiVersion: kustomize.toolkit.fluxcd.io/v1beta1
kind: Kustomization
metadata:
name: apps
namespace: flux-system
spec:
interval: 1h0m0s
sourceRef:
kind: GitRepository
name: flux-system
path: ./apps/production
prune: true
validation: client
postBuild:
substitute:
var: "something"
apps/production/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
configMapGenerator:
- name: example
files:
- file.conf
Yes. Kustomize-controller will replcae the variable begin with $
or ${}
, if you don't want to be replace, you need to label wor annotatied with kustomize.toolkit.fluxcd.io/substitute: disabled
.
According the documentation
Note that if you want to avoid var substitutions in scripts embedded in ConfigMaps or container commands, you must use the format
$var
instead of${var}
. All the undefined variables in the format${var}
will be substituted with string empty, unless a default is provided e.g.${var:=default}
.
Hence I would assume I can freely use $xyz
in my yaml and configmap (from files) that should not be substituted. And this seems to work fine
I just updated the issue to better describe the actual problem.