From 66a7bd6de607798daad108d5554ac42ababff507 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 17 Feb 2026 22:35:42 +0000 Subject: [PATCH] Fix TestEtcdStoragePath for MutatingAdmissionPolicy emulation This commit fixes a failure in TestEtcdStoragePath when emulating version 1.34. The test failure was caused by the removal of alpha versions from the test data during emulation, which prevented 'storageVersionAtEmulationVersion' from correctly resolving the storage version for MutatingAdmissionPolicy (which relies on v1alpha1 in this compatibility mode). Changes: - Updated GetEtcdStorageDataServedAt in test/integration/etcd/data.go to pass a full copy of etcdStorageData (including alpha versions) to storageVersionAtEmulationVersion. - Added ExpectedGVK to MutatingAdmissionPolicy and MutatingAdmissionPolicyBinding in test/integration/etcd/data.go to ensure correct version resolution during tests. - Removed explicit storage version overrides for MutatingAdmissionPolicy in pkg/kubeapiserver/default_storage_factory_builder.go as part of the graduation process. --- pkg/kubeapiserver/default_storage_factory_builder.go | 3 --- test/integration/etcd/data.go | 12 ++++++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/kubeapiserver/default_storage_factory_builder.go b/pkg/kubeapiserver/default_storage_factory_builder.go index 638da2c1e4d..1eb6208cacf 100644 --- a/pkg/kubeapiserver/default_storage_factory_builder.go +++ b/pkg/kubeapiserver/default_storage_factory_builder.go @@ -28,7 +28,6 @@ import ( "k8s.io/apiserver/pkg/util/compatibility" basecompatibility "k8s.io/component-base/compatibility" "k8s.io/kubernetes/pkg/api/legacyscheme" - "k8s.io/kubernetes/pkg/apis/admissionregistration" "k8s.io/kubernetes/pkg/apis/apps" "k8s.io/kubernetes/pkg/apis/certificates" "k8s.io/kubernetes/pkg/apis/coordination" @@ -81,8 +80,6 @@ func NewStorageFactoryConfigEffectiveVersion(effectiveVersion basecompatibility. // TODO (https://github.com/kubernetes/kubernetes/issues/108451): remove the override in 1.25. // apisstorage.Resource("csistoragecapacities").WithVersion("v1beta1"), coordination.Resource("leasecandidates").WithVersion("v1beta1"), - admissionregistration.Resource("mutatingadmissionpolicies").WithVersion("v1beta1"), - admissionregistration.Resource("mutatingadmissionpolicybindings").WithVersion("v1beta1"), certificates.Resource("clustertrustbundles").WithVersion("v1beta1"), certificates.Resource("podcertificaterequests").WithVersion("v1beta1"), storagemigration.Resource("storagemigrations").WithVersion("v1beta1"), diff --git a/test/integration/etcd/data.go b/test/integration/etcd/data.go index 72a3eadd261..4f4252a2922 100644 --- a/test/integration/etcd/data.go +++ b/test/integration/etcd/data.go @@ -18,6 +18,7 @@ package etcd import ( "fmt" + "maps" "strings" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" @@ -492,12 +493,14 @@ func GetEtcdStorageDataForNamespaceServedAt(namespace string, v string, isEmulat gvr("admissionregistration.k8s.io", "v1beta1", "mutatingadmissionpolicies"): { Stub: `{"metadata":{"name":"map1b1"},"spec":{"paramKind":{"apiVersion":"test.example.com/v1","kind":"Example"},"matchConstraints":{"resourceRules": [{"resourceNames": ["fakeName"], "apiGroups":["apps"],"apiVersions":["v1"],"operations":["CREATE", "UPDATE"], "resources":["deployments"]}]},"reinvocationPolicy": "IfNeeded","mutations":[{"applyConfiguration": {"expression":"Object{metadata: Object.metadata{labels: {'example':'true'}}}"}, "patchType":"ApplyConfiguration"}]}}`, ExpectedEtcdPath: "/registry/mutatingadmissionpolicies/map1b1", + ExpectedGVK: gvkP("admissionregistration.k8s.io", "v1beta1", "MutatingAdmissionPolicy"), IntroducedVersion: "1.34", RemovedVersion: "1.40", }, gvr("admissionregistration.k8s.io", "v1beta1", "mutatingadmissionpolicybindings"): { Stub: `{"metadata":{"name":"mpb1b1"},"spec":{"policyName":"replicalimit-policy.example.com","paramRef":{"name":"replica-limit-test.example.com", "parameterNotFoundAction": "Allow"}}}`, ExpectedEtcdPath: "/registry/mutatingadmissionpolicybindings/mpb1b1", + ExpectedGVK: gvkP("admissionregistration.k8s.io", "v1beta1", "MutatingAdmissionPolicyBinding"), IntroducedVersion: "1.34", RemovedVersion: "1.40", }, @@ -749,16 +752,17 @@ func GetEtcdStorageDataForNamespaceServedAt(namespace string, v string, isEmulat } if isEmulation { + fullEtcdStorageData := maps.Clone(etcdStorageData) + for key := range etcdStorageData { if strings.Contains(key.Version, "alpha") { delete(etcdStorageData, key) } } - } - // match the resource to the correct storage version for emulated version - if isEmulation { + + // match the resource to the correct storage version for emulated version for key, data := range etcdStorageData { - storageVersion := storageVersionAtEmulationVersion(key, data.ExpectedGVK, v, etcdStorageData) + storageVersion := storageVersionAtEmulationVersion(key, data.ExpectedGVK, v, fullEtcdStorageData) if storageVersion == "" { continue }