Skip to content

Commit

Permalink
fix: 🐛 load valuefiles from config file location (#6156)
Browse files Browse the repository at this point in the history
* fix: 🐛 load valuefiles from config file location

Signed-off-by: Manuel Ruck <[email protected]>

* refactor: add downwards compatibility

by checking getBuildPath first
and throws an error if both locations does not have the file

Signed-off-by: Manuel Ruck <[email protected]>

* fix: remove throwing error on valueFiles not found

Signed-off-by: Manuel Ruck <[email protected]>

* refactor: check path existence via async functions

* test: 🧪 Helm common functions getValueArgs should allow valueFiles relative to action config

Signed-off-by: Manuel Ruck <[email protected]>

---------

Signed-off-by: Manuel Ruck <[email protected]>
Co-authored-by: Manuel Ruck <[email protected]>
Co-authored-by: Vladimir Vagaytsev <[email protected]>
  • Loading branch information
3 people authored Jun 21, 2024
1 parent 0016c82 commit 52dc2b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
15 changes: 10 additions & 5 deletions core/src/plugins/kubernetes/helm/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { flatten, isPlainObject } from "lodash-es"
import AsyncLock from "async-lock"
import { join, resolve } from "path"
import fsExtra from "fs-extra"

const { pathExists, readFile, remove, writeFile } = fsExtra
import { temporaryWrite } from "tempy"
import cryptoRandomString from "crypto-random-string"
Expand Down Expand Up @@ -292,13 +293,17 @@ export async function getValueArgs({
}) {
// The garden-values.yml file (which is created from the `values` field in the module config) takes precedence,
// so it's added to the end of the list.
const valueFiles = action
.getSpec()
.valueFiles.map((f) => resolve(action.getBuildPath(), f))
.concat([valuesPath])
const valueFiles = await Promise.all(
action.getSpec().valueFiles.map(async (f) => {
const pathViaBuildPath = resolve(action.getBuildPath(), f)
const pathViaEffectiveConfigFileLocation = resolve(action.effectiveConfigFileLocation(), f)

const args = flatten(valueFiles.map((f) => ["--values", f]))
return (await pathExists(pathViaBuildPath)) ? pathViaBuildPath : pathViaEffectiveConfigFileLocation
})
)
valueFiles.push(valuesPath)

const args = flatten(valueFiles.map((f) => ["--values", f]))
return args
}

Expand Down
12 changes: 12 additions & 0 deletions core/test/integ/src/plugins/kubernetes/helm/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,18 @@ ${expectedIngressOutput}
gardenValuesPath,
])
})

it("should allow valueFiles relative to action config", async () => {
const action = await garden.resolveAction<HelmDeployAction>({ action: graph.getDeploy("api"), log, graph })
action["_config"].spec.valueFiles = ["./values.yaml"]

expect(await getValueArgs({ action, valuesPath: gardenValuesPath })).to.eql([
"--values",
resolve(action.effectiveConfigFileLocation(), "./values.yaml"),
"--values",
gardenValuesPath,
])
})
})

describe("getReleaseName", () => {
Expand Down

0 comments on commit 52dc2b1

Please sign in to comment.