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

Conversation

stefreak
Copy link
Member

@stefreak stefreak commented Jan 2, 2023

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.

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

@stefreak stefreak force-pushed the fix-resolve-provider branch from 28529eb to 69afab8 Compare January 2, 2023 17:37
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.

co-authored-by: srihas-g <[email protected]>
@stefreak stefreak force-pushed the fix-resolve-provider branch from 69afab8 to dbf2df4 Compare January 2, 2023 17:38
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)
@stefreak stefreak requested review from edvald and Orzelius January 3, 2023 14:53
@stefreak stefreak force-pushed the fix-resolve-provider branch from 654fbd0 to bc1372c Compare January 3, 2023 14:56
@stefreak stefreak force-pushed the fix-resolve-provider branch from bc1372c to d0032f0 Compare January 3, 2023 14:56
@stefreak stefreak marked this pull request as ready for review January 3, 2023 14:58
@stefreak stefreak force-pushed the fix-resolve-provider branch from 005af72 to f8cbe7a Compare January 3, 2023 15:19
@stefreak
Copy link
Member Author

stefreak commented Jan 3, 2023

I wonder if the new test will just run on circleci, or if I have to change the circleci yaml to include the new exec integration test somehow?

Copy link
Contributor

@Orzelius Orzelius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! The integ test is very easy to understand.

@edvald
Copy link
Collaborator

edvald commented Jan 3, 2023

The integ test should just run, along with the rest of the integ test suite. You should be able to confirm by looking at the vm test logs.

@stefreak stefreak merged commit 0290380 into main Jan 4, 2023
@stefreak stefreak deleted the fix-resolve-provider branch January 4, 2023 10:28
stefreak added a commit that referenced this pull request Jan 4, 2023
* 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]>
edvald pushed a commit that referenced this pull request Jan 7, 2023
* 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]>
This was referenced May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants