Skip to content

Discover served MutatingAdmissionPolicy API version at runtime#4837

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

Discover served MutatingAdmissionPolicy API version at runtime#4837
caseydavenport wants to merge 11 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 Outdated
@mohag
Copy link
Copy Markdown

mohag commented May 26, 2026

A somewhat tangential note: The v3 CRD chart also have v1beta1 MutatingAdmissionPolicy manifests pulled in from here.

@caseydavenport
Copy link
Copy Markdown
Member Author

@mohag yep, will definitely need to handle those as well (I believe helm can detect API versions and use the correct one, with some tweaks)

Clusters on k8s 1.32-1.33 with the MutatingAdmissionPolicy alpha feature
gate enabled serve only v1alpha1 (v1beta1 doesn't arrive until 1.34). The
MAP types are identical in shape across v1alpha1, v1beta1, and v1, so this
adds the v1alpha1 case to the existing parse/list/kind-check paths. Runtime
discovery already selects v1alpha1 when it's the only served version.
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.

3 participants