Skip to content

Commit

Permalink
fix(k8s): helm status check now compares Garden version
Browse files Browse the repository at this point in the history
Turns out `helm status` doesn't do any meaningful comparison checks
on its own (in hindsight I really don't why I thought it did), so
updates to `helm` modules would get ignored without the `--force` flag.

We can rely on our version hash for comparison, however, since it
includes hashes of all the templates and the config passed to the
template.
  • Loading branch information
edvald committed Nov 13, 2019
1 parent 959f735 commit 28c5987
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
7 changes: 7 additions & 0 deletions garden-service/src/plugins/kubernetes/helm/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export async function buildHelmModule({ ctx, module, log }: BuildModuleParams<He
// Merge with the base module's values, if applicable
const specValues = baseModule ? jsonMerge(baseModule.spec.values, module.spec.values) : module.spec.values

// Add Garden metadata
specValues[".garden"] = {
moduleName: module.name,
projectName: ctx.projectName,
version: module.version.versionString,
}

const valuesPath = getGardenValuesPath(chartPath)
log.silly(`Writing chart values to ${valuesPath}`)
await dumpYaml(valuesPath, specValues)
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/plugins/kubernetes/helm/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function deployService({
const chartPath = await getChartPath(module)
const namespace = await getAppNamespace(k8sCtx, log, provider)
const releaseName = getReleaseName(module)
const releaseStatus = await getReleaseStatus(k8sCtx, releaseName, log)
const releaseStatus = await getReleaseStatus(k8sCtx, module, releaseName, log)

const commonArgs = [
"--namespace",
Expand Down
23 changes: 21 additions & 2 deletions garden-service/src/plugins/kubernetes/helm/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function getServiceStatus({
} else {
// Otherwise we trust Helm to report the status of the chart.
try {
const helmStatus = await getReleaseStatus(k8sCtx, releaseName, log)
const helmStatus = await getReleaseStatus(k8sCtx, module, releaseName, log)
state = helmStatus.state
} catch (err) {
state = "missing"
Expand All @@ -101,15 +101,34 @@ export async function getServiceStatus({

export async function getReleaseStatus(
ctx: KubernetesPluginContext,
module: HelmModule,
releaseName: string,
log: LogEntry
): Promise<ServiceStatus> {
try {
log.silly(`Getting the release status for ${releaseName}`)
const res = JSON.parse(await helm({ ctx, log, args: ["status", releaseName, "--output", "json"] }))
const statusCode = res.info.status.code
let state = helmStatusCodeMap[statusCode]

if (state === "ready") {
// Make sure the right version is deployed
const deployedValues = JSON.parse(
await helm({
ctx,
log,
args: ["get", "values", releaseName, "--output", "json"],
})
)
const deployedVersion = deployedValues[".garden"] && deployedValues[".garden"].version

if (!deployedVersion || deployedVersion !== module.version.versionString) {
state = "outdated"
}
}

return {
state: helmStatusCodeMap[statusCode],
state,
detail: res,
}
} catch (_) {
Expand Down

0 comments on commit 28c5987

Please sign in to comment.