Skip to content

Discover served MutatingAdmissionPolicy API version at runtime#4837

Open
caseydavenport wants to merge 7 commits into
tigera:masterfrom
caseydavenport:casey-map-v1-discovery
Open

Discover served MutatingAdmissionPolicy API version at runtime#4837
caseydavenport wants to merge 7 commits into
tigera:masterfrom
caseydavenport:casey-map-v1-discovery

Conversation

@caseydavenport
Copy link
Copy Markdown
Member

Description

The operator hardcoded the use of admissionregistration.k8s.io/v1beta1 for MutatingAdmissionPolicy. K8s 1.36 promoted MutatingAdmissionPolicy to v1 and v1beta1 is scheduled for removal in 1.37, so clusters that only serve v1 produced reconcile errors like no matches for kind "MutatingAdmissionPolicy" in version "admissionregistration.k8s.io/v1beta1" (see projectcalico/calico#6412 (comment)).

This PR discovers the served version via the RESTMapper and uses it for parsing, listing, creating, and stale-cleanup. Preference order is v1, then v1beta1. If neither is served the controller reports a degraded condition and skips policy defaulting, same as before.

Split into two commits:

  1. Bump k8s.io/* to v0.36.1 and sigs.k8s.io/controller-runtime to v0.24.1 so the v1 typed import is available.
  2. Add discovery + dual typed paths in pkg/imports/admission and pkg/controller/installation/core_controller.go. The previous static ProvidesMutatingAdmissionPolicyV1Beta1 minor-version check is replaced by RESTMapper-based discovery, which is more accurate across forks and feature gates.
Fix operator reconcile failure on Kubernetes clusters that only serve the v1 (not v1beta1) MutatingAdmissionPolicy API.

K8s 1.36 promotes MutatingAdmissionPolicy to v1; v1beta1 is scheduled for
removal in 1.37. Hardcoding v1beta1 broke operator reconciles on clusters
that only serve v1. Use the RESTMapper to pick the served version (prefer
v1), and parse/list/sync at that version.
Avoid a per-reconcile RESTMapping call by discovering the served version
in main() and threading it through ControllerOptions to the installation
controller.
Generalize one-shot API discovery into a small package that controllers can
query without hitting the cluster. cmd/main.go pre-resolves the set of
GroupKinds we care about and passes a Discovery snapshot through
ControllerOptions; lookups are plain map reads.
Fold the new APIDiscovery type into the existing discovery file rather
than adding a new package next to it. Cluster-shape helpers move from
pkg/controller/utils into pkg/common/discovery alongside the served-API
snapshot.
Comment thread cmd/main.go
ElasticExternal: utils.UseExternalElastic(bootConfig),
ElasticExternal: discovery.UseExternalElastic(bootConfig),
UseV3CRDs: v3CRDs,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Suggested change

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.

2 participants