-
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: re-initialize providers changing environments (#3481)
* fix: re-initialize providers changing environments When users change environments, we need to re-initialize providers. Let's consider the following example: User has a provider config like so: ``` providers: - name: exec initScript: echo ${environment.name} > someFile ``` If user runs a garden command with --env foo, and then with --env bar, and then again with --env foo we would expect `someFile` to contain `foo`. But the file actually contains bar. Reason for this is that garden skipped executing the initScript in the foo env, because it has already been executed. But the cache logic is not aware that the last command that ran was in the bar env. This commit fixes that problem. * improvement: remove unnecessary check for env name Reasoning is that when the env name changes and that is relevant, the provider config changes too (assuming that we do not implicitly pass additional information like the environment name using env variables) * tests: add an integration test Co-authored-by: srihas-g <[email protected]> Co-authored-by: Walther <[email protected]>
- Loading branch information
1 parent
470eef3
commit f93c8f8
Showing
5 changed files
with
71 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
theFile |
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,8 @@ | ||
kind: Project | ||
name: incident-repro | ||
environments: | ||
- name: one | ||
- name: two | ||
providers: | ||
- name: exec | ||
initScript: "echo '${environment.name}' > theFile" |
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,61 @@ | ||
/* | ||
* Copyright (C) 2018-2022 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { expect } from "chai" | ||
import { readFile } from "fs-extra" | ||
import { join } from "node:path" | ||
import { getDataDir, makeTestGarden, TestGarden } from "../../../../helpers" | ||
|
||
describe("exec provider initialization cache behaviour", () => { | ||
let gardenOne: TestGarden | ||
let tmpDir: string | ||
let fileLocation: string | ||
|
||
beforeEach(async () => { | ||
gardenOne = await makeTestGarden(getDataDir("exec-provider-cache"), { environmentName: "one" }) | ||
|
||
tmpDir = join(await gardenOne.getRepoRoot(), "project") | ||
fileLocation = join(tmpDir, "theFile") | ||
|
||
await gardenOne.resolveProvider(gardenOne.log, "exec") | ||
}) | ||
|
||
it("writes the environment name to theFile as configured in the initScript", async () => { | ||
const contents = await readFile(fileLocation, { encoding: "utf-8" }) | ||
|
||
expect(contents).equal("one\n") | ||
}) | ||
|
||
it("overwrites theFile when changing environments", async () => { | ||
let contents = await readFile(fileLocation, { encoding: "utf-8" }) | ||
expect(contents).equal("one\n") | ||
|
||
const gardenTwo = await makeTestGarden(tmpDir, { environmentName: "two", noTempDir: true }) | ||
await gardenTwo.resolveProvider(gardenTwo.log, "exec") | ||
|
||
contents = await readFile(fileLocation, { encoding: "utf-8" }) | ||
expect(contents).equal("two\n") | ||
}) | ||
|
||
it("still overwrites theFile when changing environments back", async () => { | ||
let contents = await readFile(fileLocation, { encoding: "utf-8" }) | ||
expect(contents).equal("one\n") | ||
|
||
const gardenTwo = await makeTestGarden(tmpDir, { environmentName: "two", noTempDir: true }) | ||
await gardenTwo.resolveProvider(gardenTwo.log, "exec") | ||
|
||
contents = await readFile(fileLocation, { encoding: "utf-8" }) | ||
expect(contents).equal("two\n") | ||
|
||
const gardenOneAgain = await makeTestGarden(tmpDir, { environmentName: "one", noTempDir: true }) | ||
await gardenOneAgain.resolveProvider(gardenOneAgain.log, "exec") | ||
|
||
contents = await readFile(fileLocation, { encoding: "utf-8" }) | ||
expect(contents).equal("one\n") | ||
}) | ||
}) |
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