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(k8s): handle AEC-paused resources properly #5122

Merged
merged 14 commits into from Sep 25, 2023
Merged

Conversation

vvagaytsev
Copy link
Collaborator

@vvagaytsev vvagaytsev commented Sep 21, 2023

What this PR does / why we need it:
A follow-up fix for #4846 to address @stefreak 's comment on the AEC.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:
The commit-by-commit review might be easier :)

@vvagaytsev vvagaytsev changed the title Fix/k8s action type aec @vvagaytsev fix(k8s): handle AEC-paused resources properly Sep 21, 2023
@vvagaytsev vvagaytsev changed the title @vvagaytsev fix(k8s): handle AEC-paused resources properly fix(k8s): handle AEC-paused resources properly Sep 21, 2023
Copy link
Collaborator

@twelvemo twelvemo left a comment

Choose a reason for hiding this comment

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

Overall looks good, but i think we might be using the wrong annotation key.

@twelvemo twelvemo self-requested a review September 21, 2023 12:33
shumailxyz
shumailxyz previously approved these changes Sep 21, 2023
@shumailxyz
Copy link
Contributor

e2e-run-actions is failing but i think it's a flake

twelvemo
twelvemo previously approved these changes Sep 21, 2023
Copy link
Collaborator

@twelvemo twelvemo left a comment

Choose a reason for hiding this comment

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

Super quick turnaround!

@vvagaytsev vvagaytsev added this pull request to the merge queue Sep 21, 2023
@stefreak stefreak removed this pull request from the merge queue due to a manual request Sep 21, 2023
@vvagaytsev vvagaytsev marked this pull request as draft September 21, 2023 14:49
@shumailxyz shumailxyz self-requested a review September 22, 2023 08:24
vvagaytsev referenced this pull request Sep 25, 2023
* refactor: extract named function for manifest post-processing

* refactor: split manifest reading and post-processing

* fix(k8s): correctly resolve manifests when `build` is set

* fix(k8s): quickfix to avoid resetting `outdated` state to `ready`

* test: fix tests

* refactor(test): move helper to the upper-level scope

It will be used by other test contexts.

* refactor(test): introduce one more convenience helper

* refactor(test): introduce and rename some local vars

* refactor(test): use helpers to avoid code duplication

* chore: re-arranged code

Keep all helpers close to each other for simpler navigation.

* chore(test): rename some tests and variables

To avoid usage of the old glossary.

* refactor(test): helper function to deploy in namespaces

* DRY to avoid repetition and too complex local state
* Less shared global state between different test contexts
* Avoid dependencies between tests and reliance on the execution order
* Ability to run individual tests locally

* refactor(test): convert lambdas to functions

* test: ensure all resources are deleted by `deleteKubernetesDeploy`

A metadata `ConfigMap` describing what was last deployed must be deleted too.

* test: restore initial module config state after each test

To avoid unexpected pollution of the Garden instance's state.
Multiple test can define temporary custom module config.
Such config changes should not affect the other tests.

* refactor(k8s): helper to compose k8s deploy status

* refactor(k8s): return deploy status immediately on "missing" state

* refactor: unwrap unnecessary else-block

* chore: variable scoping

* refactor: extract helper to check if deploy is outdated

* refactor: move input args check into `getForwardablePorts`

* chore: remove unnecessary code and comments

Local mode checks were moved to `getForwardablePorts` in #5022.

* chore: remove unnecessary try/catch

Function `getForwardablePorts` does not call any potentially unsafe operations.
It's not wrapped into try/catch in the other code places.

* chore: remove unused local var

* refactor: use SRP in status calculation

Split individual resource status retrieval and overall state calculation.

* refactor: simplified code

Minimized mutability of the local vars.
More straightforward and linear processing flow.

* test: fix test setup to cover the original bug

* chore: post-merge corrections

* refactor: remove unnecessary function call

The value has already been calculated as an immutable value.

* chore: typos and wording

Got rid of old-fashioned term "service". Replaced it with "deploy".

---------

Co-authored-by: Jon Edvald <edvald@gmail.com>
@vvagaytsev vvagaytsev dismissed stale reviews from twelvemo and shumailxyz via b483afc September 25, 2023 09:33
@vvagaytsev vvagaytsev force-pushed the fix/k8s-action-type-aec branch 2 times, most recently from b483afc to 4569244 Compare September 25, 2023 09:35
This is a follow-up quickfix for #4846.
It reads a specific annotation and checks if it has a special value set by Cloud.
This needs to be changed to reply on a more generic and reliable way of k8s resource comparison.
To avoid repetitive creation of the same immutable string.
@vvagaytsev vvagaytsev marked this pull request as ready for review September 25, 2023 10:04
stefreak
stefreak previously approved these changes Sep 25, 2023
Copy link
Member

@stefreak stefreak left a comment

Choose a reason for hiding this comment

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

Great work! 👍

I think we need to still make sure that deploy -f always deploys even when the deploy is ready already; But that can be done in a separate PR.

@shumailxyz
Copy link
Contributor

@vvagaytsev Some of the tests are failing. I wonder if those are due to the manifest hash check you added.

@vvagaytsev
Copy link
Collaborator Author

@shumailxyz thanks! I see, that's because of the annotation change. The tests share the same in-cluster resource. After the new test is executed, I'll ensure that everything is reverted back to the normal state.

@stefreak thanks! Yes, let's address the --force flag in a separate PR/

} finally {
// Redeploy the resource to restore the original value of `k8sManifestHashAnnotationKey` annotation,
// because the remote resource state is used by the other tests.
await kubernetesDeploy(deployParams)
Copy link
Member

Choose a reason for hiding this comment

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

I understand if that's a bigger change and you want to do it separately; But would it be better to run kubernetesDeploy in a beforeEach in a group for all the tests that rely on it being deployed?

Copy link
Member

Choose a reason for hiding this comment

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

seeing try {} finally {} in a test is strange when mocha provides before and after primitives for these kinds of things

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That requires more changes and re-grouping of the tests. We can do it later if we have more tests that modify remote resources that should be re-deployed on the test completion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a dedicated config for this test case in 75c1b24.
Now we don't need to restore the remote resource state used by the other tests.

To avoid unwanted modifications of the remote resources used by the other tests.
stefreak
stefreak previously approved these changes Sep 25, 2023
Copy link
Member

@stefreak stefreak left a comment

Choose a reason for hiding this comment

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

👍

@vvagaytsev vvagaytsev added this pull request to the merge queue Sep 25, 2023
shumailxyz
shumailxyz previously approved these changes Sep 25, 2023
Copy link
Contributor

@shumailxyz shumailxyz left a comment

Choose a reason for hiding this comment

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

Awesome 💯

Just a typo that i found.

@vvagaytsev vvagaytsev removed this pull request from the merge queue due to a manual request Sep 25, 2023
@vvagaytsev vvagaytsev dismissed stale reviews from shumailxyz and stefreak via 07d32c6 September 25, 2023 14:33
Co-authored-by: Shumail Mohyuddin <shumailmohyuddin@gmail.com>
@vvagaytsev vvagaytsev added this pull request to the merge queue Sep 25, 2023
Merged via the queue into main with commit ed87cfd Sep 25, 2023
42 checks passed
@vvagaytsev vvagaytsev deleted the fix/k8s-action-type-aec branch September 25, 2023 15:39
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.

None yet

4 participants