Skip to content

Commit 80941e3

Browse files
authored
Merge pull request kubernetes#127643 from Jefftree/set-emulation-integration-test
Allow emulation version to be set in integration test
2 parents 1d26810 + ff13ffc commit 80941e3

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

cmd/kube-apiserver/app/testing/testserver.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4545
utilerrors "k8s.io/apimachinery/pkg/util/errors"
4646
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
47+
"k8s.io/apimachinery/pkg/util/version"
4748
"k8s.io/apimachinery/pkg/util/wait"
4849
serveroptions "k8s.io/apiserver/pkg/server/options"
4950
"k8s.io/apiserver/pkg/storage/storagebackend"
@@ -102,8 +103,11 @@ type TestServerInstanceOptions struct {
102103
// an apiserver version skew scenario where all apiservers use the same proxyCA to verify client connections.
103104
ProxyCA *ProxyCA
104105
// Set the BinaryVersion of server effective version.
105-
// Default to 1.31
106+
// If empty, effective version will default to version.DefaultKubeBinaryVersion.
106107
BinaryVersion string
108+
// Set the EmulationVersion of server effective version.
109+
// If empty, emulation version will default to the effective version.
110+
EmulationVersion string
107111
// Set non-default request timeout in the server.
108112
RequestTimeout time.Duration
109113
}
@@ -194,6 +198,9 @@ func StartTestServer(t ktesting.TB, instanceOptions *TestServerInstanceOptions,
194198
if instanceOptions.BinaryVersion != "" {
195199
effectiveVersion = utilversion.NewEffectiveVersion(instanceOptions.BinaryVersion)
196200
}
201+
if instanceOptions.EmulationVersion != "" {
202+
effectiveVersion.SetEmulationVersion(version.MustParse(instanceOptions.EmulationVersion))
203+
}
197204
// need to call SetFeatureGateEmulationVersionDuringTest to reset the feature gate emulation version at the end of the test.
198205
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, featureGate, effectiveVersion.EmulationVersion())
199206
utilversion.DefaultComponentGlobalsRegistry.Reset()

test/integration/apiserver/cel/validatingadmissionpolicy_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,8 @@ func Test_CostLimitForValidation(t *testing.T) {
22342234
func Test_CostLimitForValidationWithFeatureDisabled(t *testing.T) {
22352235
resetPolicyRefreshInterval := generic.SetPolicyRefreshIntervalForTests(policyRefreshInterval)
22362236
defer resetPolicyRefreshInterval()
2237-
server, err := apiservertesting.StartTestServer(t, nil, []string{
2237+
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.StrictCostEnforcementForVAP, false)
2238+
server, err := apiservertesting.StartTestServer(t, &apiservertesting.TestServerInstanceOptions{EmulationVersion: "1.31"}, []string{
22382239
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
22392240
}, framework.SharedEtcd())
22402241
if err != nil {

0 commit comments

Comments
 (0)