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(core): ensure task outputs are logged to terminal + fix test #1612

Merged
merged 2 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion garden-service/src/commands/run/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class RunTaskCommand extends Command<Args, Opts> {
log.info("")
// TODO: The command will need to be updated to stream logs: see https://github.com/garden-io/garden/issues/630.
// It's ok with the current providers but the shape might change in the future.
log.info(chalk.white(result.output.outputs.log.trim()))
log.info(chalk.white(result.output.log.trim()))
printFooter(footerLog)
}

Expand Down
4 changes: 2 additions & 2 deletions garden-service/src/plugins/kubernetes/helm/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ export async function runHelmTask(params: RunTaskParams<HelmModule>): Promise<Ru
timeout,
})

const result = {
const result: RunTaskResult = {
...res,
taskName: task.name,
outputs: {
log: res.output || "",
log: res.log || "",
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function runKubernetesTask(params: RunTaskParams<KubernetesModule>)
...res,
taskName: task.name,
outputs: {
log: res.output || "",
log: res.log || "",
},
}

Expand Down
6 changes: 0 additions & 6 deletions garden-service/src/types/plugin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ export interface RunResult {
startedAt: Date
completedAt: Date
log: string
// DEPRECATED
output?: string
}

export const runResultSchema = joi
Expand Down Expand Up @@ -113,10 +111,6 @@ export const runResultSchema = joi
.allow("")
.default("")
.description("The output log from the run."),
output: joi
.string()
.allow("")
.description("[DEPRECATED - use `log` instead] The output log from the run."),
})

export const artifactsPathSchema = joi
Expand Down
4 changes: 0 additions & 4 deletions garden-service/src/types/plugin/task/getTaskResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ export const taskResultSchema = joi
.required()
.allow("")
.description("The output log from the run."),
output: joi
.string()
.allow("")
.description("[DEPRECATED - use `log` instead] The output log from the run."),
outputs: joi
.object()
.pattern(/.+/, joiPrimitive())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,14 @@ describe("kubernetes container module handlers", () => {
version: task.module.version,
})

const key = "task.echo-task"
const result = await garden.processTasks([testTask], { throwOnError: true })

const key = "task.echo-task"
expect(result).to.have.property(key)
expect(result[key]).to.have.property("output")
expect(result[key]!.output.log.trim()).to.equal("ok")
expect(result[key]!.output).to.have.property("outputs")
expect(result[key]!.output.outputs.log.trim()).to.equal("ok")
})

it("should fail if an error occurs, but store the result", async () => {
Expand Down
4 changes: 4 additions & 0 deletions garden-service/test/integ/src/plugins/kubernetes/helm/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ describe("runHelmTask", () => {
expect(result).to.exist
expect(result).to.have.property("output")
expect(result!.output.log.trim()).to.equal("ok")
expect(result!.output).to.have.property("outputs")
expect(result!.output.outputs.log.trim()).to.equal("ok")
})

it("should run a task in a different namespace, if configured", async () => {
Expand All @@ -67,6 +69,8 @@ describe("runHelmTask", () => {
expect(result).to.exist
expect(result).to.have.property("output")
expect(result!.output.log.trim()).to.equal(task.module.spec.namespace)
expect(result!.output).to.have.property("outputs")
expect(result!.output.outputs.log.trim()).to.equal(task.module.spec.namespace)
})

it("should fail if an error occurs, but store the result", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ describe("runKubernetesTask", () => {
expect(result).to.exist
expect(result).to.have.property("output")
expect(result!.output.log.trim()).to.equal("ok")
expect(result!.output).to.have.property("outputs")
expect(result!.output.outputs.log.trim()).to.equal("ok")
})

it("should run a task in a different namespace, if configured", async () => {
Expand All @@ -67,6 +69,8 @@ describe("runKubernetesTask", () => {
expect(result).to.exist
expect(result).to.have.property("output")
expect(result!.output.log.trim()).to.equal(task.module.spec.namespace)
expect(result!.output).to.have.property("outputs")
expect(result!.output.outputs.log.trim()).to.equal(task.module.spec.namespace)
})

it("should fail if an error occurs, but store the result", async () => {
Expand Down
3 changes: 3 additions & 0 deletions garden-service/test/unit/src/plugins/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ describe("exec plugin", () => {

// Task A echoes "task-a-output" and Task B echoes the output from Task A
expect(results["task.task-b"]).to.exist
expect(results["task.task-b"]).to.have.property("output")
expect(results["task.task-b"]!.output.log).to.equal("task-a-output")
expect(results["task.task-b"]!.output).to.have.property("outputs")
expect(results["task.task-b"]!.output.outputs.log).to.equal("task-a-output")
})

Expand Down
2 changes: 2 additions & 0 deletions garden-service/test/unit/src/plugins/terraform/terraform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ describe("Terraform module type", () => {

it("should expose runtime outputs to template contexts", async () => {
const result = await runTestTask()

expect(result["task.test-task"]!.output.log).to.equal("input: foo")
expect(result["task.test-task"]!.output.outputs.log).to.equal("input: foo")
})
})