Skip to content

Commit

Permalink
fix(core): prevent null outputContent (#1134)
Browse files Browse the repository at this point in the history
* test(core): demonstrate current behavior of JobExecutorLocal with empty output

This test currently fails.  The next commit fixes it.

* fix(core): prevent null outputContent

in the BakeStatus that JobExecutorLocal.updateStatus returns.

Before this change, if the output of e.g. helm template is an empty string, the BakeStatus object that JobExecutorLocal.updateStatus returns is null, and HelmTemplateUtils.removeTestsDirectoryTemplates throws a NullPointerException.

HelmBakeManifestService.bake calls BakeManifestService.doBake which calls JobExecutorLocal.updateStatus, and then HelmBakeManifestService.bake calls HelmTemplateUtils.removeTestsDirectoryTemplates with the resulting String.

With this change, removeTestsDirectoryTemplates gets an empty string, and so the bake manifest endpoint (e.g. POST /api/v2/manifest/bake/helm) returns an empty Artifact.

Without a corresponding change to clouddriver to handle a null KubernetesManifest, there's still a clouddriver crash in a deploy manifest that consumes the output of this bake, but it's progress.
  • Loading branch information
dbyron-sf authored Jan 23, 2025
1 parent 2a1d914 commit 9032907
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ class JobExecutorLocal implements JobExecutor {
bakeStatus.state = BakeStatus.State.RUNNING
}

if (outputContent) {
bakeStatus.outputContent = outputContent
}
bakeStatus.outputContent = outputContent

if (logsContent) {
bakeStatus.logsContent = logsContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,29 @@ Final output
true | COMBINED_OUTPUT | COMBINED_OUTPUT
false | EXPECTED_OUTPUT | EXPECTED_LOGS
}

void 'job executor handles empty output'() {
def jobRequest = new JobRequest(
tokenizedCommand: ["true"],
jobId: SOME_JOB_ID,
combineStdOutAndErr: false)

@Subject
def jobExecutorLocal = new JobExecutorLocal(
registry: new DefaultRegistry(),
timeoutMinutes: 1)

when:
def jobId = jobExecutorLocal.startJob(jobRequest)
// Give the script time to run + 100 ms fudge factor
sleep(3000)
def bakeStatus = jobExecutorLocal.updateJob(jobId)

then:
bakeStatus != null
bakeStatus.state == BakeStatus.State.COMPLETED
bakeStatus.result == BakeStatus.Result.SUCCESS
bakeStatus.outputContent == ""
bakeStatus.logsContent == "No output from command."
}
}

0 comments on commit 9032907

Please sign in to comment.