kustomize: Namespace generated is missing document separator

When stacking multiple kustomize outputs together it becomes apparent that the emitted namespace is missing the ---.

Also, when a namespace is included and added to resources, it has the document separator removed.

This is preventing doing e.g.

for i in *
do
kustomize build $i
done | kubectl apply -f -
$ kustomize build .
apiVersion: v1
kind: Namespace
metadata:
  name: x
---
apiVersion: v1
data:
  druid_segmentCache_locations: '[{"path": "var/druid/segment-cache", "maxSize": 32000000000,
    "freeSpacePercent": 1.0, "blahblahblah":"9999999999"}]'
kind: ConfigMap
metadata:
  name: foo-b66gf6d7t6
  namespace: X
$ cat kustomization.yaml 
namespace: X

resources:
  - namespace.yaml

configMapGenerator:
  - name: foo
    literals:
      - 'druid_segmentCache_locations=[{"path": "var/druid/segment-cache", "maxSize": 32000000000, "freeSpacePercent": 1.0, "blahblahblah":"9999999999"}]'
don@cube[gke-noctest]:y
$ cat namespace.yaml 
---
apiVersion: v1
kind: Namespace
metadata:
  name: x

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 22 (11 by maintainers)

Most upvoted comments

/reopen

There’s no good reason not to add --- at the top of the yaml document Kustomize generates.

Is it possible to revisit this issue? It seems like an easy fix unless prepending --- to the yaml output of kustomize build is breaking some convention.

can this be reopened please?

I wanted to create my output with

mkdir build
kustomize build . --output build

and am trying to deploy the output via

cat build/* | ssh NODE kubectl apply -f -

This does not work because of the missing separator

I think this is a reasonable ask. Appending the output from kustomize to a file or stream seems like a fairly common workflow and it could be enabled by ensuring that the output always starts with a document separator.

Looking at the EncodeAsYaml function, writing a leading document separator is explicitly avoided but I am not sure I understand the reasoning for that. https://github.com/kubernetes-sigs/kustomize/blob/master/pkg/resmap/resmap.go#L66-L73