-
Notifications
You must be signed in to change notification settings - Fork 273
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
Simplify provider init #6706
Simplify provider init #6706
Conversation
bcba85a
to
53c8184
Compare
49a4bab
to
72b996c
Compare
Previously, Garden would first run the `getEnvironmentStatus` handler and depending on the results, either run the `prepareEnvironment` handler or not. Now we always run the `prepareEnvironment` handler (if the provider status is not cached). The reason for this change is that the previous flow is an unneeded abstraction that doesn't serve any purpose at this point and makes the provider initialisation harder to reason about. The specific motivation is that there's bug in the Kubernetes provider where some resources aren't created when the environment is prepared. It's actually more work to first check the statuses of these resources, return those, and then create them. In particular since we have helpers to create them in an idempotent manner. That's why now we just always call `prepareEnvironment` and have that handler figure out what needs to be done. We still keep the `getEnvironmentStatus` handler for status-only commands but now it doesn't have side effects. Whereas before the status handler would e.g. create a namespace. Plugins can then decide to use that if needed. E.g. the `prepareEnvironment` handler for the Terraform plugins uses `getEnvironmentStatus` to decide what needs to happen. We'll fix the actual bug that prompted this change in a follow up commit.
72b996c
to
0c18a0e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
@@ -72,8 +72,9 @@ export async function getEnvironmentStatus({ | |||
const k8sCtx = <KubernetesPluginContext>ctx | |||
const provider = k8sCtx.provider | |||
const api = await KubeApi.factory(log, ctx, provider) | |||
|
|||
const namespace = await getNamespaceStatus({ ctx: k8sCtx, log, provider: k8sCtx.provider, skipCreate: true }) | |||
// TODO @eysi: Avoid casting (the namespace is ensured though when the provider config is resolved) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this cast might become unnecessary with the changes to provider init that @stefreak and @vvagaytsev have been working on, but I'm not sure.
Before this fix, we were calling Terraform init in the `getStatusHandler` which is an undesired side effect. With this refactor we now call it in the `prepareEnvironment` handler which is were it should be. Also note that in PR #6706 we changed the provider init flow such that we now always call `prepareEnvironment` and the `getStatusHandler` isn't really used any more. That's why I also removed the call to that handler from the `prepareEnvironment` function and instead moved the logic there. It's basically duplicated across both handlers now which is fine because we're removing the status handler in 0.14.
Before this fix, we were calling `terraform init` in the `getStatusHandler` which is an undesired side effect. With this refactor we now call it in the `prepareEnvironment` handler which is were it should be. Also note that in PR #6706 we changed the provider init flow such that we now always call `prepareEnvironment` and the `getStatusHandler` isn't really used any more. That's why I also removed the call to that handler from the `prepareEnvironment` function and instead moved the logic there. It's basically duplicated across both handlers now which is fine because we're removing the status handler in 0.14.
Before this fix, we were calling `terraform init` in the `getStatusHandler` which is an undesired side effect. With this refactor we now call it in the `prepareEnvironment` handler which is were it should be. Also note that in PR #6706 we changed the provider init flow such that we now always call `prepareEnvironment` and the `getStatusHandler` isn't really used any more. That's why I also removed the call to that handler from the `prepareEnvironment` function and instead moved the logic there. It's basically duplicated across both handlers now which is fine because we're removing the status handler in 0.14.
Before this fix, we were calling `terraform init` in the `getStatusHandler` which is an undesired side effect. With this refactor we now call it in the `prepareEnvironment` handler which is were it should be. Also note that in PR #6706 we changed the provider init flow such that we now always call `prepareEnvironment` and the `getStatusHandler` isn't really used any more. That's why I also removed the call to that handler from the `prepareEnvironment` function and instead moved the logic there. It's basically duplicated across both handlers now which is fine because we're removing the status handler in 0.14.
What this PR does / why we need it:
Previously, Garden would first run the
getEnvironmentStatus
handlerand depending on the results, either run the
prepareEnvironment
handler or not.
Now we always run the
prepareEnvironment
handler (if the providerstatus is not cached).
The reason for this change is that the previous flow is an
unneeded abstraction that doesn't serve any purpose at this point and
makes the provider initialisation harder to reason about.
The specific motivation is that there's bug in the Kubernetes
provider where some resources aren't created when the
environment is prepared. It's actually more work to first check
the statuses of these resources, return those, and then create
them. In particular since we have helpers to create them in
an idempotent manner.
That's why now we just always call
prepareEnvironment
and have thathandler figure out what needs to be done.
We still keep the
getEnvironmentStatus
handler for status-onlycommands but now it doesn't have side effects. Whereas before the
status handler would e.g. create a namespace.
Plugins can then decide to use that if needed. E.g. the
prepareEnvironment
handler for the Terraform plugins uses
getEnvironmentStatus
to decidewhat needs to happen.
We'll fix the actual bug that prompted this change in a follow up
commit.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer: