kustomize: Line breaks on long strings with spaces
When combining helm templates with kustomize overlays, a line break is inserted when the line is very long and contains spaces.
Tested versions: 2.0.1 and 2.0.3 Using test/base.yml:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: test
labels:
app.version: "{{ .Values.services.mariadb.app.version }}"
spec:
template:
spec:
containers:
- name: mariadb
image: "thisIsAReallyLongRepositoryLinkThatResultsInALineBreakWhenBuildingWithKustomize/mariadb:{{ .Values.services.mariadb.image.version }}"
and test/kustomization.yml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- base.yml
results in
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app.version: '{{ .Values.services.mariadb.app.version }}'
name: test
spec:
template:
spec:
containers:
- image: thisIsAReallyLongRepositoryLinkThatResultsInALineBreakWhenBuildingWithKustomize/mariadb:{{
.Values.services.mariadb.image.version }}
name: mariadb
Expected Behavior:
- Line without line break
- Also, the string/quoted value of the image name in base.yml is converted to an unqouted value on build while the
app.versionlabel is enclosed in single quotes. I would expect that either the quotes are not removed at all or the quoting behavior is constant
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 21
- Comments: 43 (24 by maintainers)
Commits related to this issue
- Updated helm charts with the new port Unfortunately this generated a lot of changes because descriptions are no longer word-wrapped - it looks like this was a change made to kustomize last year: htt... — committed to babbageclunk/azure-service-operator by babbageclunk 4 years ago
- Updated helm charts with the new port Unfortunately this generated a lot of changes because descriptions are no longer word-wrapped - it looks like this was a change made to kustomize last year: htt... — committed to babbageclunk/azure-service-operator by babbageclunk 4 years ago
- Update helm charts with AzurePublicIPAddress.ipTags and new kustomize The new version of kustomize no longer word-wraps long text fields like descriptions, which causes a lot of churn in the files. T... — committed to babbageclunk/azure-service-operator by babbageclunk 4 years ago
@kristofferahl, we worked around this by using:
Not sure if this is semantically 100% equal, though. It mitigated the issue in our specific case.
I am still experiencing this with Kustomize version
v4.5.2.Please reopen this issue.
This is still an issue, with latest version of kustomize bundled with Argo CD 2.0.1. I use the kustomized-helm pattern, but kustomize corrupts the following
BEFORE
AFTER
adding
yqin pipeline do fix this yamlcat result.yaml | yq > new.yamlv2 of go-yaml already exposes the option to change this behaviour. In fact, it was temporarily the default in v2.3 of that library, but the change was reverted at the request of the Kubernetes project in v2.4: https://github.com/go-yaml/yaml/pull/670. This repo deliberately opted not to set it by default: https://github.com/kubernetes-sigs/yaml/pull/62#discussion_r713015836. Consumers who want the behaviour change should call
yaml.FutureLineWrap(). Changing the default in kubernetes-sigs/yaml would not be possible without a major version bump IMO.Reading through the history here and on related issues, it sounds like Kustomize in particular has already thrashed on the wrapping behaviour. Indeed, we used the go-yaml version with the changed default between https://github.com/kubernetes-sigs/kustomize/pull/2679 and https://github.com/kubernetes-sigs/kustomize/pull/3667, which means v3.7.0 to v4.0.5 had no line limit set, and both before and after did. The revert was apparently specifically requested because of the kubectl integration, and we knew it would thrash the line length limit: https://github.com/kubernetes-sigs/kustomize/issues/3664.
Even if on the Kustomize side we could consider the wrapping to be purely a bug (such that we could accept the change in output as non-breaking and release without a major version bump), we would still have the problem of how to do it. Unfortunately
yaml.FutureLineWrap()is a global toggle, so we cannot set it in code thatkubectlwill pull in, i.e. the relevant code–we already know that change is unacceptable in kubectl. So perhaps what we can do with our upcoming fork is not “fix” the wrapping (we can’t change it by default), but rather expose the flag on a per-encoding basis instead of globally, so thatkustomizeandkubectl kustomizecould make the change without affecting the rest ofkubectl.This problem is extremely annoying. Is there any updates?
Unfortunately the following workaround not works in all cases:
This construction adds a
\nin the end of the line and not in all cases app is able to just ignore this\n. There’re|-and>-syntax, but unfortunately values created with them are still having line break in the middle of the lineThere’s a fix in gopkg.in/yaml.v2, now released as v2.3.0 - I’ll make a PR to update kustomize to this version. (basically, if the string doesn’t have newline literals in it, v2.3.0 won’t split the string over multiple lines when encoding things - previously it would wrap before 80 characters)
@laverya: You can’t reopen an issue/PR unless you authored it or you are a collaborator.
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
I think if https://github.com/go-yaml/yaml/pull/455 gets merged that might be the signal to migrate to yaml.v3, and unlimited line lengths…