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.
This commit is contained in:
Your Name
2026-02-17 22:35:42 +00:00
parent 0af21eae1e
commit 66a7bd6de6
2 changed files with 8 additions and 7 deletions

View File

@@ -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"),

View File

@@ -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
}