Allow emulation version to be set in integration test

This commit is contained in:
Jefftree 2024-09-25 22:01:15 -04:00
parent 0c5e832aa2
commit dacc2e1f5d
2 changed files with 10 additions and 2 deletions

View File

@ -44,6 +44,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/version"
"k8s.io/apimachinery/pkg/util/wait"
serveroptions "k8s.io/apiserver/pkg/server/options"
"k8s.io/apiserver/pkg/storage/storagebackend"
@ -102,8 +103,11 @@ type TestServerInstanceOptions struct {
// an apiserver version skew scenario where all apiservers use the same proxyCA to verify client connections.
ProxyCA *ProxyCA
// Set the BinaryVersion of server effective version.
// Default to 1.31
// If empty, binary version will be inferred from the build.
BinaryVersion string
// Set the EmulationVersion of server effective version.
// If empty, emulation version will be inferred (equal to) from the binary version.
EmulationVersion string
// Set non-default request timeout in the server.
RequestTimeout time.Duration
}
@ -194,6 +198,9 @@ func StartTestServer(t ktesting.TB, instanceOptions *TestServerInstanceOptions,
if instanceOptions.BinaryVersion != "" {
effectiveVersion = utilversion.NewEffectiveVersion(instanceOptions.BinaryVersion)
}
if instanceOptions.EmulationVersion != "" {
effectiveVersion.SetEmulationVersion(version.MustParse(instanceOptions.EmulationVersion))
}
// need to call SetFeatureGateEmulationVersionDuringTest to reset the feature gate emulation version at the end of the test.
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, featureGate, effectiveVersion.EmulationVersion())
utilversion.DefaultComponentGlobalsRegistry.Reset()

View File

@ -2234,7 +2234,8 @@ func Test_CostLimitForValidation(t *testing.T) {
func Test_CostLimitForValidationWithFeatureDisabled(t *testing.T) {
resetPolicyRefreshInterval := generic.SetPolicyRefreshIntervalForTests(policyRefreshInterval)
defer resetPolicyRefreshInterval()
server, err := apiservertesting.StartTestServer(t, nil, []string{
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.StrictCostEnforcementForVAP, false)
server, err := apiservertesting.StartTestServer(t, &apiservertesting.TestServerInstanceOptions{EmulationVersion: "1.31"}, []string{
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
}, framework.SharedEtcd())
if err != nil {