Skip to content

Commit

Permalink
feat(k8s): add timeout parameter to helm module type
Browse files Browse the repository at this point in the history
Closes #1200
  • Loading branch information
edvald committed Sep 19, 2019
1 parent ca6462c commit 373beeb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 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
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 @@ -45,22 +45,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 @@ -71,8 +75,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 @@ -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 373beeb

Please sign in to comment.