Skip to content

Commit

Permalink
fix(module): only merge relevant variables overrides in config (#5138)
Browse files Browse the repository at this point in the history
* fix(module): only merge relevant variables overrides in config

* chore: add a test
  • Loading branch information
shumailxyz authored Sep 27, 2023
1 parent 106eb72 commit b0d7a47
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
10 changes: 7 additions & 3 deletions core/src/resolve-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import cloneDeep from "fast-copy"
import { isArray, isString, keyBy } from "lodash"
import { isArray, isString, keyBy, keys, pick, union } from "lodash"
import { validateWithPath } from "./config/validation"
import {
getModuleTemplateReferences,
Expand Down Expand Up @@ -691,9 +691,13 @@ export class ModuleResolver {
// Note: We're not implementing the YAML source mapping for modules
source: undefined,
})
const mergedVariables: DeepPrimitiveMap = <any>(
merge(moduleVariables, merge(varfileVars, this.garden.variableOverrides))

// only override the relevant variables
const relevantVariableOverrides = pick(
this.garden.variableOverrides,
union(keys(moduleVariables), keys(varfileVars))
)
const mergedVariables: DeepPrimitiveMap = <any>merge(moduleVariables, merge(varfileVars, relevantVariableOverrides))
return mergedVariables
}
}
Expand Down
24 changes: 24 additions & 0 deletions core/test/unit/src/resolve-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ describe("ModuleResolver", () => {
expect(module.build.dependencies[0].name).to.equal("test-project-a")
})

it("sets the relevant variables in module config from variable overrides", async () => {
const garden = await makeTestGardenA([], {
variableOverrides: {
foo: "override",
bar: "no-override",
},
})

garden.setModuleConfigs([
{
name: "test-project-a",
type: "test",
path: join(garden.projectRoot, "module-a"),
build: { dependencies: [], timeout: DEFAULT_BUILD_TIMEOUT_SEC },
variables: {
foo: "somevalue",
},
},
])

const module = await garden.resolveModule("test-project-a")
expect(module.variables).to.eql({ foo: "override" })
})

it("handles a module template reference in a build dependency name", async () => {
const garden = await makeTestGardenA()

Expand Down

0 comments on commit b0d7a47

Please sign in to comment.