Skip to content

Commit

Permalink
Merge branch 'master' into fix-hot-reload
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald authored Sep 20, 2019
2 parents 6d00df4 + 373beeb commit b71a8ab
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 8 deletions.
9 changes: 9 additions & 0 deletions docs/reference/module-types/helm.md
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,14 @@ tests:
key: some-key
```

### `timeout`

Time in seconds to wait for Helm to complete any individual Kubernetes operation (like Jobs for hooks).

| Type | Required | Default |
| -------- | -------- | ------- |
| `number` | No | `300` |

### `version`

The chart version to deploy.
Expand Down Expand Up @@ -785,6 +793,7 @@ tests:
hotReloadArgs:
args:
env: {}
timeout: 300
version:
values: {}
valueFiles: []
Expand Down
8 changes: 7 additions & 1 deletion garden-service/src/plugins/kubernetes/helm/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ export async function getChartResources(ctx: PluginContext, module: Module, log:

const resources = objects
.filter(obj => {
// Don't try to check status of hooks
const helmHook = getAnnotation(obj, "helm.sh/hook")
if (helmHook && helmHook.startsWith("test-")) {
if (helmHook) {
return false
}

// Ephemeral objects should also not be checked
if (obj.kind === "Pod" || obj.kind === "Job") {
return false
}

Expand Down
9 changes: 9 additions & 0 deletions garden-service/src/plugins/kubernetes/helm/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { ContainerModule, ContainerEnvVars, containerEnvVarsSchema, commandExamp
import { baseBuildSpecSchema } from "../../../config/module"
import { ConfigureModuleParams, ConfigureModuleResult } from "../../../types/plugin/module/configure"

export const defaultHelmTimeout = 300

// A Helm Module always maps to a single Service
export type HelmModuleSpec = HelmServiceSpec

Expand Down Expand Up @@ -140,6 +142,7 @@ export interface HelmServiceSpec extends ServiceSpec {
skipDeploy: boolean
tasks: HelmTaskSpec[]
tests: HelmTestSpec[]
timeout: number
version?: string
values: DeepPrimitiveMap
valueFiles: string[]
Expand Down Expand Up @@ -205,6 +208,12 @@ export const helmModuleSpecSchema = joi.object().keys({
.description("The task definitions for this module."),
tests: joiArray(execTestSchema)
.description("The test suite definitions for this module."),
timeout: joi.number()
.integer()
.default(defaultHelmTimeout)
.description(
"Time in seconds to wait for Helm to complete any individual Kubernetes operation (like Jobs for hooks).",
),
version: joi.string()
.description("The chart version to deploy."),
values: joi.object()
Expand Down
15 changes: 9 additions & 6 deletions garden-service/src/plugins/kubernetes/helm/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,26 @@ export async function deployService(

const k8sCtx = <KubernetesPluginContext>ctx
const provider = k8sCtx.provider

const chartPath = await getChartPath(module)
const namespace = await getAppNamespace(k8sCtx, log, provider)
const releaseName = getReleaseName(module)

const releaseStatus = await getReleaseStatus(k8sCtx, releaseName, log)

const commonArgs = [
"--namespace", namespace,
"--timeout", module.spec.timeout.toString(10),
...await getValueFileArgs(module),
]

if (releaseStatus.state === "missing") {
log.silly(`Installing Helm release ${releaseName}`)
const installArgs = [
"install", chartPath,
"--name", releaseName,
"--namespace", namespace,
...await getValueFileArgs(module),
// Make sure chart gets purged if it fails to install
"--atomic",
"--timeout", "600",
...commonArgs,
]
if (force) {
installArgs.push("--replace")
Expand All @@ -70,8 +74,7 @@ export async function deployService(
const upgradeArgs = [
"upgrade", releaseName, chartPath,
"--install",
"--namespace", namespace,
...await getValueFileArgs(module),
...commonArgs,
]
if (force) {
upgradeArgs.push("--force")
Expand Down
1 change: 1 addition & 0 deletions garden-service/src/plugins/openfaas/openfaas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ async function configureProvider(
skipDeploy: false,
tasks: [],
tests: [],
timeout: 900,
version: "4.4.0",
releaseName,
values: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ describe("Helm common functions", () => {
expect(await getChartResources(ctx, module, log)).to.not.throw
})

it("should filter out test pods", async () => {
it("should filter out resources with hooks", async () => {
const module = await graph.getModule("chart-with-test-pod")
const resources = await getChartResources(ctx, module, log)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { deline } from "../../../../../../src/util/string"
import { ModuleConfig } from "../../../../../../src/config/module"
import { apply } from "json-merge-patch"
import { getHelmTestGarden } from "./common"
import { defaultHelmTimeout } from "../../../../../../src/plugins/kubernetes/helm/config"

describe("validateHelmModule", () => {
let garden: TestGarden
Expand Down Expand Up @@ -77,6 +78,7 @@ describe("validateHelmModule", () => {
skipDeploy: false,
tasks: [],
tests: [],
timeout: defaultHelmTimeout,
values: {
image: {
tag: versionString,
Expand Down Expand Up @@ -109,6 +111,7 @@ describe("validateHelmModule", () => {
skipDeploy: false,
tasks: [],
tests: [],
timeout: defaultHelmTimeout,
values: {
image: {
tag: versionString,
Expand Down

0 comments on commit b71a8ab

Please sign in to comment.