-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dev): fix reload error when using templates (#5329)
* fix(dev): fix reload error when using templates Before this fix, changing a Garden config during a `dev` command session and running two subsequent commands would result in the first command succeeding but the second failing with an error like: "Build foo references template <some-template> which cannot be found. Vailable templates: <None>" This was because the config templates scanned by the first subcommand after the config was changed weren't propagated to the parent Garden instance, which was then cloned and passed to the second command (which then had action configs, but no templates). This was fixed by making the relevant instance variables on the Garden class readonly (since reassignments in a child instance prevent newly scanned configs from propagating to the parent via the shared data structure) and emptying the maps before rescanning instead. Also added a unit test case that checks this whole flow. * chore(test): disable config clearing by default The call to `this.clearConfig()` in `Garden#scanAndAddConfigs` had started breaking certain test cases that manually set action configs before calling `garden.getConfigGraph` (which would scan and add configs, thus discarding the manually set configs). While it's not great that we're adding more tweaks to the `TestGarden` class, we're almost never interested in explicitly testing the post-edit config reloading (outside of tests that test interactive / dev command funcftionality).
- Loading branch information
Showing
11 changed files
with
225 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
core/test/data/test-projects/config-template-reloading/actions.garden.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
kind: RenderTemplate | ||
template: combo | ||
name: foo | ||
inputs: | ||
name: test | ||
# Resolvable at parse time | ||
envName: ${environment.name} | ||
# Resolvable later | ||
providerKey: ${providers.test-plugin.outputs.testKey} |
7 changes: 7 additions & 0 deletions
7
core/test/data/test-projects/config-template-reloading/project.garden.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: garden.io/v1 | ||
kind: Project | ||
name: config-templates | ||
environments: | ||
- name: local | ||
providers: | ||
- name: test-plugin |
14 changes: 14 additions & 0 deletions
14
core/test/data/test-projects/config-template-reloading/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"envName": { | ||
"type": "string" | ||
}, | ||
"providerKey": { | ||
"type": "string" | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
core/test/data/test-projects/config-template-reloading/templates.garden.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
kind: ConfigTemplate | ||
name: combo | ||
inputsSchemaPath: schema.json | ||
configs: | ||
- kind: Build | ||
type: test | ||
name: ${parent.name}-${inputs.name} | ||
include: [] | ||
spec: | ||
command: [echo, "echo-prefix", "${inputs.name}"] | ||
- kind: Deploy | ||
type: test | ||
name: ${parent.name}-${inputs.name} | ||
build: ${parent.name}-${inputs.name} | ||
- kind: Test | ||
type: test | ||
name: ${parent.name}-${inputs.name} | ||
dependencies: ["build.${parent.name}-${inputs.name}"] | ||
spec: | ||
command: [echo, "${inputs.envName}", "${inputs.providerKey}"] | ||
|
||
--- | ||
|
||
kind: ConfigTemplate | ||
name: workflows | ||
configs: | ||
- kind: Workflow | ||
name: ${parent.name}-${inputs.name} | ||
steps: | ||
- script: echo "${inputs.envName}" |
6 changes: 6 additions & 0 deletions
6
core/test/data/test-projects/config-template-reloading/workflows.garden.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: RenderTemplate | ||
template: workflows | ||
name: foo | ||
inputs: | ||
name: test | ||
envName: ${environment.name} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters