Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(util): correct logging for synth #1634

Open
wants to merge 9 commits into
base: 2.x
Choose a base branch
from
12 changes: 7 additions & 5 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ export async function mkdtemp(closure: (dir: string) => Promise<void>) {
}

export async function synthApp(command: string, outdir: string, stdout: boolean, metadata: boolean): Promise<SynthesizedApp> {
if (!await fs.pathExists(outdir)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting this here means that this warning will always be printed because the outdir is expected to be created further down (in the await shell call).

console.log('WARNING: specified outdir does not exist, synth command could fail')
}

if (!stdout) {
console.log('Synthesizing application');
}

await shell(command, [], {
shell: true,
env: {
Expand All @@ -58,11 +63,6 @@ export async function synthApp(command: string, outdir: string, stdout: boolean,
},
});

if (!await fs.pathExists(outdir)) {
console.error(`ERROR: synthesis failed, app expected to create "${outdir}"`);
process.exit(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand where your coming from with having synth not fail in this case (because manifests were actually created). However, from the CLIs perspective, synthesis is not only creating manifests, there are additional CLI features (like validations) that rely on the fact this directory exists, and so from its POV, synthesis is not successful. This does unfortunately mean that, if you define outdir in your app, you must also change the output property in the cdk8s.yaml configuration file.

Note that if you do it the other way around, i.e set output: out in cdk8s.yaml, and leave the App instance with its defaults, everything will work as expected.

}

let found = false;
const yamlFiles = await findManifests(outdir);
if (yamlFiles?.length) {
Expand All @@ -76,6 +76,8 @@ export async function synthApp(command: string, outdir: string, stdout: boolean,

if (!found) {
console.error('No manifests synthesized');
} else {
console.log('Manifests synthesized!')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this necessary though. If we found manifests, then we print their path already, indicating a successful synthesis.

}

const constructMetadata = findConstructMetadata(outdir);
Expand Down