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

Simplify provider init #6706

Merged
merged 1 commit into from
Jan 16, 2025
Merged

Simplify provider init #6706

merged 1 commit into from
Jan 16, 2025

Conversation

eysi09
Copy link
Collaborator

@eysi09 eysi09 commented Dec 10, 2024

What this PR does / why we need it:

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.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

@eysi09 eysi09 force-pushed the simplify-provider-init branch 3 times, most recently from bcba85a to 53c8184 Compare December 10, 2024 16:10
@eysi09 eysi09 force-pushed the simplify-provider-init branch 6 times, most recently from 49a4bab to 72b996c Compare January 15, 2025 17:35
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.
@eysi09 eysi09 force-pushed the simplify-provider-init branch from 72b996c to 0c18a0e Compare January 15, 2025 18:13
Copy link
Collaborator

@thsig thsig 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 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)
Copy link
Collaborator

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.

@eysi09 eysi09 changed the title Experimental: Simplify provider init (WIP!) Simplify provider init Jan 16, 2025
@eysi09 eysi09 marked this pull request as ready for review January 16, 2025 10:25
@eysi09 eysi09 enabled auto-merge January 16, 2025 10:29
@eysi09 eysi09 requested a review from thsig January 16, 2025 10:41
@eysi09 eysi09 added this pull request to the merge queue Jan 16, 2025
Merged via the queue into main with commit d629981 Jan 16, 2025
40 checks passed
@eysi09 eysi09 deleted the simplify-provider-init branch January 16, 2025 11:05
eysi09 added a commit that referenced this pull request Feb 6, 2025
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.
eysi09 added a commit that referenced this pull request Feb 6, 2025
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.
eysi09 added a commit that referenced this pull request Feb 6, 2025
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.
github-merge-queue bot pushed a commit that referenced this pull request Feb 8, 2025
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.
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.

2 participants