cdk8s-team / cdk8s-cli

Apache License 2.0
38 stars 23 forks source link

`cdk8s synth -p` fails to insert necessary document start markers #943

Open rassie opened 1 year ago

rassie commented 1 year ago

Description of the bug:

If cdk8s synth -p is used with any other yamlOutputType setting on the app than YamlOutputType.FILE_PER_APP, the YAML being output is missing some document start markers.

Reproduction Steps:

  1. Create a new cdk8s project
  2. Adapt this project as per https://cdk8s.io/docs/latest/getting-started/#importing-constructs-for-the-kubernetes-api
  3. Change const app = new App(); to const app = new App({ yamlOutputType: YamlOutputType.FILE_PER_RESOURCE }); in main.ts
  4. Execute npm run compile && cdk8s synth -p
  5. Observe the following output:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-deployment-c8c7fda7
spec:
  replicas: 2
  selector:
    matchLabels:
      app: hello-k8s
  template:
    metadata:
      labels:
        app: hello-k8s
    spec:
      containers:
        - image: paulbouwer/hello-kubernetes:1.7
          name: hello-kubernetes
          ports:
            - containerPort: 8080
apiVersion: v1
kind: Service
metadata:
  name: hello-service-c8c17160
spec:
  ports:
    - port: 80
      targetPort: 8080
  selector:
    app: hello-k8s
  type: LoadBalancer

As you can see, this output is missing the YAML document start marker --- before the second resource.

Other:

The reason is obviously that synth -p is not outputting documents one by one, but instead it runs synth into a temporary directory and then concatenated the files generated. The document start marker is missing at the exact spot where two files come together. For obvious reasons, this is not a problem with YamlOutputType.FILE_PER_APP.

A simple solution could be adding a document start marker to each file or each resource by default (which is recommended anyway, e.g. in yamllint).


This is :bug: Bug Report

sumupitchayan commented 1 year ago

@rassie is there a reason you are running cdk8s synth with the -p flag in conjunction with setting the yaml output type to YamlOutputType.FILE_PER_RESOURCE? As you mentioned, running cdk8s synth -p with the default yaml output type does not cause this problem.

rassie commented 1 year ago

I'm using cdk8s with Argo-CD, where I rely on -p to output the manifests. However, I do not control every single deployment repository, so it's up to those developers to set the output type correctly and with "per resource" being the default, I would just like to be sure that -p works correctly with every output type.

github-actions[bot] commented 4 months ago

This issue has not received any attention in 1 year and will be closed soon. If you want to keep it open, please leave a comment below @mentioning a maintainer.

rassie commented 4 months ago

@iliapolo should be still valid.