Skip to content

Commit

Permalink
fix(helm): disable --atomic by default in Helm modules (#5968)
Browse files Browse the repository at this point in the history
To align the behaviour with the Helm deploy action.
  • Loading branch information
vvagaytsev authored Apr 25, 2024
1 parent a333a9e commit 5f76a73
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
12 changes: 5 additions & 7 deletions core/src/plugins/kubernetes/helm/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { DeployAction, DeployActionConfig } from "../../../actions/deploy.j
import { dedent, deline } from "../../../util/string.js"
import type { KubernetesLocalModeSpec } from "../local-mode.js"
import { kubernetesLocalModeSchema } from "../local-mode.js"
import type { RunActionConfig, RunAction } from "../../../actions/run.js"
import type { RunAction, RunActionConfig } from "../../../actions/run.js"
import type { TestAction, TestActionConfig } from "../../../actions/test.js"
import type { ObjectSchema } from "@hapi/joi"
import type { KubernetesRunOutputs } from "../kubernetes-type/config.js"
Expand Down Expand Up @@ -165,17 +165,15 @@ const helmChartSpecSchema = () =>
`
)

export const defaultHelmAtomicFlag = false
export const defaultHelmAtomicFlagDesc = `Whether to set the --atomic flag during installs and upgrades. Set to true if you'd like the changes applied to be reverted on failure. Set to false if e.g. you want to see more information about failures and then manually roll back, instead of having Helm do it automatically on failure.`

export const helmDeploySchema = () =>
joi
.object()
.keys({
...helmCommonSchemaKeys(),
atomic: joi
.boolean()
.default(false)
.description(
"Whether to set the --atomic flag during installs and upgrades. Set to true if you'd like the changes applied to be reverted on failure."
),
atomic: joi.boolean().default(defaultHelmAtomicFlag).description(defaultHelmAtomicFlagDesc),
chart: helmChartSpecSchema(),
defaultTarget: defaultTargetSchema(),
sync: kubernetesDeploySyncSchema(),
Expand Down
17 changes: 10 additions & 7 deletions core/src/plugins/kubernetes/helm/module-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ import { runPodSpecIncludeFields } from "../run.js"
import { omit } from "lodash-es"
import type { KubernetesModuleDevModeSpec } from "../sync.js"
import { kubernetesModuleSyncSchema } from "../sync.js"
import { helmChartNameSchema, helmChartRepoSchema, helmChartVersionSchema, helmCommonSchemaKeys } from "./config.js"
import {
defaultHelmAtomicFlag,
defaultHelmAtomicFlagDesc,
helmChartNameSchema,
helmChartRepoSchema,
helmChartVersionSchema,
helmCommonSchemaKeys,
} from "./config.js"
import fsExtra from "fs-extra"

const { pathExists } = fsExtra
import { helmChartYamlFilename } from "./common.js"
import type { KubernetesLocalModeSpec } from "../local-mode.js"
Expand Down Expand Up @@ -128,12 +136,7 @@ export const helmModuleSpecSchema = () =>
.object()
.keys({
...helmCommonSchemaKeys(),
atomicInstall: joi
.boolean()
.default(true)
.description(
"Whether to set the --atomic flag during installs and upgrades. Set to false if e.g. you want to see more information about failures and then manually roll back, instead of having Helm do it automatically on failure."
),
atomicInstall: joi.boolean().default(defaultHelmAtomicFlag).description(defaultHelmAtomicFlagDesc),
base: joiUserIdentifier()
.description(
deline`The name of another \`helm\` module to use as a base for this one. Use this to re-use a Helm chart across
Expand Down
12 changes: 6 additions & 6 deletions core/test/integ/src/plugins/kubernetes/helm/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
GardenApiVersion,
} from "../../../../../../src/constants.js"
import { ValidateCommand } from "../../../../../../src/commands/validate.js"
import { defaultHelmAtomicFlag } from "../../../../../../src/plugins/kubernetes/helm/config.js"

describe("configureHelmModule", () => {
let garden: TestGarden
Expand All @@ -52,11 +53,10 @@ describe("configureHelmModule", () => {
const module = await garden.resolveModule("api-module")
const graph = await garden.getConfigGraph({ log: garden.log, emit: false })
const imageModule = graph.getModule("api-image")

const imageVersion = imageModule.version.versionString

const spec = {
atomicInstall: true,
const expectedSpec = {
atomicInstall: defaultHelmAtomicFlag,
build: {
dependencies: [],
timeout: DEFAULT_BUILD_TIMEOUT_SEC,
Expand Down Expand Up @@ -115,18 +115,18 @@ describe("configureHelmModule", () => {
name: "api-module",
path: resolve(ctx.projectRoot, "api"),
repositoryUrl: undefined,
buildConfig: omit(spec, ["atomicInstall", "serviceResource", "skipDeploy", "tasks", "tests"]),
buildConfig: omit(expectedSpec, ["atomicInstall", "serviceResource", "skipDeploy", "tasks", "tests"]),
serviceConfigs: [
{
name: "api-module",
dependencies: [],
disabled: false,
sourceModuleName: "api-image",
timeout: DEFAULT_DEPLOY_TIMEOUT_SEC,
spec,
spec: expectedSpec,
},
],
spec,
spec: expectedSpec,
testConfigs: [],
type: "helm",
taskConfigs: [],
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/action-types/Deploy/helm.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ this action config's directory.

[spec](#spec) > atomic

Whether to set the --atomic flag during installs and upgrades. Set to true if you'd like the changes applied to be reverted on failure.
Whether to set the --atomic flag during installs and upgrades. Set to true if you'd like the changes applied to be reverted on failure. Set to false if e.g. you want to see more information about failures and then manually roll back, instead of having Helm do it automatically on failure.

| Type | Default | Required |
| --------- | ------- | -------- |
Expand Down
11 changes: 6 additions & 5 deletions docs/reference/module-types/helm.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ values: {}
# this action config's directory.
valueFiles: []

# Whether to set the --atomic flag during installs and upgrades. Set to false if e.g. you want to see more information
# about failures and then manually roll back, instead of having Helm do it automatically on failure.
atomicInstall: true
# Whether to set the --atomic flag during installs and upgrades. Set to true if you'd like the changes applied to be
# reverted on failure. Set to false if e.g. you want to see more information about failures and then manually roll
# back, instead of having Helm do it automatically on failure.
atomicInstall: false

# The name of another `helm` module to use as a base for this one. Use this to re-use a Helm chart across multiple
# services. For example, you might have an organization-wide base chart for certain types of services.
Expand Down Expand Up @@ -1037,11 +1038,11 @@ this action config's directory.

### `atomicInstall`

Whether to set the --atomic flag during installs and upgrades. Set to false if e.g. you want to see more information about failures and then manually roll back, instead of having Helm do it automatically on failure.
Whether to set the --atomic flag during installs and upgrades. Set to true if you'd like the changes applied to be reverted on failure. Set to false if e.g. you want to see more information about failures and then manually roll back, instead of having Helm do it automatically on failure.

| Type | Default | Required |
| --------- | ------- | -------- |
| `boolean` | `true` | No |
| `boolean` | `false` | No |

### `base`

Expand Down

0 comments on commit 5f76a73

Please sign in to comment.