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

Improve manifest stack application w.r.t. CRDs #4516

Merged
merged 8 commits into from
Jun 11, 2024

Conversation

twz123
Copy link
Member

@twz123 twz123 commented May 29, 2024

Description

Prevent the Applier's resource.Builder to try to get a REST mapping for all the resources from the API server, which will fail in case of custom resources whose CRDs weren't applied yet. The error returned from the builder looked like this:

unable to build resources: resource mapping not found for name: "fooResource" namespace: "default" from "/var/lib/k0s/manifests/foo/resources.yaml": no matches for kind "Foo" in version "example.com/v1"
ensure CRDs are installed first

Collect resource errors when applying stacks: This allows k0s to apply stacks that are not well ordered, i.e. that don't declare dependencies before their dependents. By attempting to apply each resource, the dependencies will eventually be applied, allowing the dependents to be applied on the next retry.

During the stack application, reset the REST mapper each time it can't find a mapping to ensure that the error is not due to out-of-date cached data.

Wait for CRDs to be established after their application: As a result, the Applier requires fewer retries when applying stacks that contain both custom resources and their definitions.

Add an integration test to make sure that stacks that are badly ordered are eventually applied in their entirety.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

  • Manual test
  • Auto test added

Checklist:

  • My code follows the style guidelines of this project
  • My commit messages are signed-off
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

@twz123 twz123 added the bug Something isn't working label May 29, 2024
@twz123 twz123 marked this pull request as ready for review May 29, 2024 14:47
@twz123 twz123 requested a review from a team as a code owner May 29, 2024 14:47
@twz123 twz123 requested review from ncopa and jnummelin May 29, 2024 14:47
@twz123 twz123 force-pushed the try-all-resources branch 2 times, most recently from c8c8dae to d545390 Compare June 5, 2024 11:30
Copy link
Contributor

github-actions bot commented Jun 7, 2024

This pull request has merge conflicts that need to be resolved.

This will prevent the Builder to try to get a REST mapping for all
the resources from the API server, which will fail in case of custom
resources whose CRDs weren't applied yet.

The error returned from the builder looked like this:

> unable to build resources: resource mapping not found for name: "fooResource" namespace: "default" from "/var/lib/k0s/manifests/foo/resources.yaml": no matches for kind "Foo" in version "example.com/v1"
> ensure CRDs are installed first

Signed-off-by: Tom Wieczorek <[email protected]>
This makes it easier to refactor the Applier.

Signed-off-by: Tom Wieczorek <[email protected]>
When applying a stack, the Stack knows best when it makes sense to reset
the RESTMapper. Move the cache invalidation out of the Applier into
the Stack, and trigger it whenever a REST mapping for a given kind was
not found.

Signed-off-by: Tom Wieczorek <[email protected]>
This reduces the boilerplate in the callers and allows for the Stack to
use typed clients, if required.

Signed-off-by: Tom Wieczorek <[email protected]>
Watching CRDs has more and more usages in k0s. Introducing a common
helper makes sense and reduces the amount of copy/pasted type aliases.

Signed-off-by: Tom Wieczorek <[email protected]>
As a result, the Applier requires fewer retries when applying stacks
that contain both custom resources and their definitions.

Signed-off-by: Tom Wieczorek <[email protected]>
This allows k0s to apply stacks that are not well ordered, i.e. that
don't declare dependencies before their dependents. By attempting
to apply each resource, the dependencies will eventually be applied,
allowing the dependents to be applied on the next retry.

Signed-off-by: Tom Wieczorek <[email protected]>
Make sure that stacks that are badly ordered are eventually applied in
their entirety.

Signed-off-by: Tom Wieczorek <[email protected]>
@twz123 twz123 merged commit fd93979 into k0sproject:main Jun 11, 2024
79 checks passed
@twz123 twz123 deleted the try-all-resources branch June 11, 2024 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants