Skip to content

Commit

Permalink
fix(core): ensure task outputs are logged to terminal + fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
eysi09 committed Feb 16, 2020
1 parent 869c310 commit 28c2c88
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 15 deletions.
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
5 changes: 5 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 @@ -14,6 +14,7 @@ import { getHelmTestGarden } from "./common"
import { TaskTask } from "../../../../../../src/tasks/task"
import { emptyDir, pathExists } from "fs-extra"
import { join } from "path"
import { RunTaskResult } from "../../../../../../src/types/plugin/task/runTask"

describe("runHelmTask", () => {
let garden: TestGarden
Expand Down Expand Up @@ -46,6 +47,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 +70,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")
})
})

0 comments on commit 28c2c88

Please sign in to comment.