Skip to content

Commit

Permalink
fix(k8s): env vars weren't passed to services with garden run service
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald authored and 10ko committed Nov 29, 2019
1 parent d26595f commit 8d66f8a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
4 changes: 3 additions & 1 deletion garden-service/src/plugins/kubernetes/container/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export async function runContainerService({
timeout,
log,
}: RunServiceParams<ContainerModule>): Promise<RunResult> {
const { command, args } = service.spec
const { command, args, env } = service.spec

runtimeContext.envVars = { ...runtimeContext.envVars, ...env }

return runContainerModule({
ctx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ kind: Module
name: simple
type: container
image: busybox
services:
- name: echo-service
command: [sh, -c, "echo ok"]
- name: env-service
command: [sh, -c, "echo $ENV_VAR"]
env:
ENV_VAR: foo
tasks:
- name: echo-task
command: [sh, -c, "echo ok"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { TaskTask } from "../../../../../../src/tasks/task"
import { runAndCopy } from "../../../../../../src/plugins/kubernetes/run"
import { Provider } from "../../../../../../src/config/provider"
import { containerHelpers } from "../../../../../../src/plugins/container/helpers"
import { runContainerService } from "../../../../../../src/plugins/kubernetes/container/run"
import { prepareRuntimeContext } from "../../../../../../src/runtime-context"

describe("kubernetes container module handlers", () => {
let garden: Garden
Expand Down Expand Up @@ -234,6 +236,66 @@ describe("kubernetes container module handlers", () => {
})
})

describe("runContainerService", () => {
it("should run a service", async () => {
const service = await graph.getService("echo-service")

const runtimeContext = await prepareRuntimeContext({
garden,
graph,
dependencies: {
build: [],
service: [],
task: [],
test: [],
},
module: service.module,
serviceStatuses: {},
taskResults: {},
})

const result = await runContainerService({
ctx: garden.getPluginContext(provider),
log: garden.log,
service,
module: service.module,
interactive: false,
runtimeContext,
})

expect(result.log.trim()).to.eql("ok")
})

it("should add configured env vars to the runtime context", async () => {
const service = await graph.getService("env-service")

const runtimeContext = await prepareRuntimeContext({
garden,
graph,
dependencies: {
build: [],
service: [],
task: [],
test: [],
},
module: service.module,
serviceStatuses: {},
taskResults: {},
})

const result = await runContainerService({
ctx: garden.getPluginContext(provider),
log: garden.log,
service,
module: service.module,
interactive: false,
runtimeContext,
})

expect(result.log.trim()).to.eql("foo")
})
})

describe("runContainerTask", () => {
it("should run a basic task", async () => {
const task = await graph.getTask("echo-task")
Expand Down
1 change: 0 additions & 1 deletion garden-service/test/unit/src/tasks/get-service-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Garden } from "../../../../src/garden"
import { GardenPlugin } from "../../../../src/types/plugin/plugin"
import { joi } from "../../../../src/config/common"
import { ServiceState } from "../../../../src/types/service"
import { DeployServiceParams } from "../../../../src/types/plugin/service/deployService"
import { RunTaskParams } from "../../../../src/types/plugin/task/runTask"
import { expect } from "chai"
import { GetServiceStatusTask } from "../../../../src/tasks/get-service-status"
Expand Down

0 comments on commit 8d66f8a

Please sign in to comment.