cdk8s-team / cdk8s-core

Define Kubernetes native apps and abstractions using object-oriented programming
Apache License 2.0
67 stars 26 forks source link

FOLDER_PER_CHART_FILE_PER_RESOURCE does not respect dependency order #1239

Open ameyp opened 1 year ago

ameyp commented 1 year ago

Description of the bug:

If I specify the YamlOutputType as FOLDER_PER_CHART_FILE_PER_RESOURCE for synth, I expect the resources in the folder created to be named in such a way as to honor their dependency order. However, the resources are created without an index prefix, and so will be applied in alphabetical order by kubectl/fluxcd/whatever.

I see two options:

Reproduction Steps:

class MyChart extends Chart {
    constructor(scope: Construct, id: string) {
        super(scope, id, {
            namespace: constants.databases.namespace
        });

        const resource1 = // ...create resource here
        const resource2 = // ...create resource here
        resource1.addDependency(resource2)
}

const app = new App({
    yamlOutputType: YamlOutputType.FOLDER_PER_CHART_FILE_PER_RESOURCE
});

const chart = new MyChart(app, 'mychart');
app.synth();

This will generate two files:

Which will be applied in that order, despite resource1 needing resource2 to be applied first.


This is :bug: Bug Report

iliapolo commented 3 months ago

@ameyp thanks for reporting this.

We should prefix the file names with an index, just like we do with charts. Generating a kustomize.yaml file is an option, but I prefer to avoid since it limits the way an application can be deployed.