Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: re-initialize providers changing environments #3481

Merged
merged 6 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions core/src/tasks/resolve-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ export class ResolveProviderTask extends BaseTask {
return getProviderStatusCachePath({
gardenDirPath: this.garden.gardenDirPath,
pluginName: this.plugin.name,
environmentName: this.garden.environmentName,
})
}

Expand Down Expand Up @@ -381,11 +380,9 @@ export class ResolveProviderTask extends BaseTask {
export function getProviderStatusCachePath({
gardenDirPath,
pluginName,
environmentName,
}: {
gardenDirPath: string
pluginName: string
environmentName: string
}) {
return join(gardenDirPath, "cache", "provider-statuses", `${pluginName}.${environmentName}.json`)
return join(gardenDirPath, "cache", "provider-statuses", `${pluginName}.json`)
}
1 change: 1 addition & 0 deletions core/test/data/exec-provider-cache/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theFile
8 changes: 8 additions & 0 deletions core/test/data/exec-provider-cache/project.garden.yml
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"
61 changes: 61 additions & 0 deletions core/test/integ/src/plugins/exec/resolve.ts
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")
Walther marked this conversation as resolved.
Show resolved Hide resolved
})

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")
})
})
1 change: 0 additions & 1 deletion plugins/terraform/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ function makeRootCommand(commandName: string) {
const cachePath = getProviderStatusCachePath({
gardenDirPath: ctx.gardenDirPath,
pluginName: provider.name,
environmentName: ctx.environmentName,
})
await remove(cachePath)

Expand Down