kustomize: Long lines are broken with space in them
Describe the bug
When upgrading to the 4.0.5+ from 4.0.4 longs lines with spaces in the yaml are broken. Looks similiar to #947 but that was fixed in older versions (this wasn’t an issue in 3.8.x+).
Files that can reproduce the issue Example:
kustomization.yaml
resources:
- test.yaml
test.yaml
apiVersion: controlplane.cluster.x-k8s.io/v1alpha4
kind: KubeadmControlPlane
metadata:
name: ${CLUSTER_NAME}-control-plane
namespace: default
spec:
kubeadmConfigSpec:
postKubeadmCommands:
- sed -i '\#--listen-client-urls#s#$#,https://127.0.0.1:2379#' /etc/kubernetes/manifests/etcd.yaml
- echo "DNSStubListener=no" >> /etc/systemd/resolved.conf
- mv /etc/resolv.conf /etc/resolv.conf.OLD && ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
- systemctl restart systemd-resolved
Expected output
apiVersion: controlplane.cluster.x-k8s.io/v1alpha4
kind: KubeadmControlPlane
metadata:
name: ${CLUSTER_NAME}-control-plane
namespace: default
spec:
kubeadmConfigSpec:
postKubeadmCommands:
- sed -i '\#--listen-client-urls#s#$#,https://127.0.0.1:2379#' /etc/kubernetes/manifests/etcd.yaml
- echo "DNSStubListener=no" >> /etc/systemd/resolved.conf
- mv /etc/resolv.conf /etc/resolv.conf.OLD && ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
- systemctl restart systemd-resolved
Actual output
apiVersion: controlplane.cluster.x-k8s.io/v1alpha4
kind: KubeadmControlPlane
metadata:
name: ${CLUSTER_NAME}-control-plane
namespace: default
spec:
kubeadmConfigSpec:
postKubeadmCommands:
- sed -i '\#--listen-client-urls#s#$#,https://127.0.0.1:2379#' /etc/kubernetes/manifests/etcd.yaml
- echo "DNSStubListener=no" >> /etc/systemd/resolved.conf
- mv /etc/resolv.conf /etc/resolv.conf.OLD && ln -s /run/systemd/resolve/resolv.conf
/etc/resolv.conf
- systemctl restart systemd-resolved
Kustomize version 4.0.5+ including 4.1.x
Platform linux
Additional context
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 17 (7 by maintainers)
Commits related to this issue
- Work around https://github.com/kubernetes-sigs/kustomize/issues/3969 — committed to orikami-nl/pulsar-helm-chart by alamont 3 years ago
Ok so I finally figured it out.
The direct references to go-yaml don’t play any role whatsoever.
sigs.k8s.io/yamlis the key. This needs to be at version 1.3.0 so that go-yaml is at 2.4.0 (not 2.3.0, that isn’t actually needed).This right here is where the magic happens: https://github.com/kubernetes-sigs/yaml/blob/v1.3.0/yaml.go#L82.
To have this work without line breaks you just need to call
yaml.FutureLineWrap()(i.e. this right here https://github.com/go-yaml/yaml/blob/v2.4.0/yaml.go#L476) somewhere (for example within the JSONtoYaml function or as an init when calling kustomize).If it really is as simple as this, could we get this as command line arg?