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

[EV-3914] Set the controller manager cache RESTMapper back to the DynamicRESTMapper (default changed on k8s upgrade) #2861

Conversation

Brian-McM
Copy link
Contributor

The controller runtime adding this kubernetes-sigs/controller-runtime@b38c4a5 which changes how the cache builder and the controller cache options are combined.

Previously if the cache builders REST Mapper was nil, it would default to the controllers rest mapper, which defaults to the DynamicRESTMapper. This rest mapper is not a static mapper, it looks up types that were previously missing when consulted, like the Tier or Licence types.

With the commit mentioned, if the Mapper in the cache builder config is nil that code defaults it to the DiscoveryRESTMapper, which does not look up types that were previously missing. We use the cache builder here https://github.com/tigera/operator/blob/master/main.go#L232 to do some special things for tiers, so the upgrade from controller runtime 0.13 to 0.14 switched the mapper. This is why removing the custom cache fixes the issue, since it means the default is changed back to the DynamicRestMapper.

This should probably be fixed upstream, but for now we can just set the Mapper in the builder to the DynamicRESTMapper as I've done in this commit.

Description

For PR author

  • Tests for change.
  • If changing pkg/apis/, run make gen-files
  • If changing versions, run make gen-versions

For PR reviewers

A note for code reviewers - all pull requests must have the following:

  • Milestone set according to targeted release.
  • Appropriate labels:
    • kind/bug if this is a bugfix.
    • kind/enhancement if this is a a new feature.
    • enterprise if this PR applies to Calico Enterprise only.

@Brian-McM Brian-McM requested a review from a team as a code owner September 8, 2023 23:25
@marvin-tigera marvin-tigera added this to the v1.32.0 milestone Sep 8, 2023
@Brian-McM Brian-McM changed the title Set the controller manager cache RESTMapper back to the DynamicRESTMapper (default changed on k8s upgrade) [EV-3914] Set the controller manager cache RESTMapper back to the DynamicRESTMapper (default changed on k8s upgrade) Sep 8, 2023
main.go Outdated Show resolved Hide resolved
Copy link
Member

@rene-dekker rene-dekker left a comment

Choose a reason for hiding this comment

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

lgtm

@Brian-McM Brian-McM force-pushed the bm-fix-rest-mapper-when-cache-builder-is-used branch from e1f42bc to 771f42f Compare September 8, 2023 23:33
Copy link
Member

@tmjd tmjd left a comment

Choose a reason for hiding this comment

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

LGTM, the real test for me will be if downstream CI stays clean, but it certainly seems very reasonable that the RESTMapper change was the issue.

@Brian-McM Brian-McM force-pushed the bm-fix-rest-mapper-when-cache-builder-is-used branch 3 times, most recently from c820b53 to 5253b7a Compare September 11, 2023 18:47
…pper (default changed on k8s upgrade)

The controller runtime adding this kubernetes-sigs/controller-runtime@b38c4a5 which changes how the cache builder and the controller cache options are combined.

Previously if the cache builders REST Mapper was nil, it would default to the controllers rest mapper, which defaults to the DynamicRESTMapper. This rest mapper is not a static mapper, it looks up types that were previously missing when consulted, like the Tier or Licence types.

With the commit mentioned, if the Mapper in the cache builder config is nil that code defaults it to the DiscoveryRESTMapper, which does not look up types that were previously missing. We use the cache builder here https://github.com/tigera/operator/blob/master/main.go#L232 to do some special things for tiers, so the upgrade from controller runtime 0.13 to 0.14 switched the mapper. This is why removing the custom cache fixes the issue, since it means the default is changed back to the DynamicRestMapper.

This should probably be fixed upstream, but for now we can just set the Mapper in the builder to the DynamicRESTMapper as I've done in this commit.
@Brian-McM Brian-McM force-pushed the bm-fix-rest-mapper-when-cache-builder-is-used branch from 5253b7a to 6159242 Compare September 11, 2023 18:56
@Brian-McM Brian-McM merged commit 0c1c706 into tigera:master Sep 11, 2023
3 checks passed
@Brian-McM Brian-McM deleted the bm-fix-rest-mapper-when-cache-builder-is-used branch September 11, 2023 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants