vumdao
vumdao

Reputation: 621

Separate output files of cdk8s synth

The following code will create one yaml file dist/clusterip.k8s.yaml contains all my defines of deployment and statefulset, is there way to separate different files in output such as dist/clusterip.k8s.yaml and dist/statefulset.k8s.yaml?

class MyChart(Chart):
    def __init__(self, scope: Construct, id: str):
        super().__init__(scope, id)
        ClusterIp(self, 'clusterip')
        StateFulSet(self, 'statefulset')

app = App()
MyChart(app, "clusterip")

Upvotes: 0

Views: 559

Answers (2)

onin
onin

Reputation: 5760

Yes there is.

It has been implemented in this commit: https://github.com/cdk8s-team/cdk8s-core/commit/474e373c1b86a57a3568cca0f9629e038266f2d5

From https://github.com/cdk8s-team/cdk8s-core/blob/d00d2de5816106ea8bb7259e4ee5da907bc83e2a/src/app.ts:

/** The method to divide YAML output into files */
export enum YamlOutputType {
  /** All resources are output into a single YAML file */
  FILE_PER_APP,
  /** Resources are split into seperate files by chart */
  FILE_PER_CHART,
  /** Each resource is output to its own file */
  FILE_PER_RESOURCE,
  /** Each chart in its own folder and each resource in its own file */
  FOLDER_PER_CHART_FILE_PER_RESOURCE,
}

export interface AppProps {
  /**
   * The directory to output Kubernetes manifests.
   *
   * @default - CDK8S_OUTDIR if defined, otherwise "dist"
   */
  readonly outdir?: string;
  /**
   *  The file extension to use for rendered YAML files
   * @default .k8s.yaml
   */
  readonly outputFileExtension?: string;
  /**
   *  How to divide the YAML output into files
   * @default YamlOutputType.FILE_PER_CHART
   */
  readonly yamlOutputType?: YamlOutputType;
}

Upvotes: 0

Thomas Steinbach
Thomas Steinbach

Reputation: 1081

Maybe not exactly what you want to hear but cdk8s creates one output file per chart. So you could split resources over multiple charts within your app.

As your personal workaround you also could split the yaml documents per file on your own. When you already have started using Python, that should be simple as yaml.safe_load the output file, loop over all documents and yaml.safe_dump them again. Between load and dump you can organize things as you wish.

Upvotes: 0

Related Questions