Skip to content

Commit debe026

Browse files
committed
Fix unit tests to work with explicit depndencies
1 parent 36e3a8f commit debe026

8 files changed

Lines changed: 31 additions & 101 deletions

File tree

pkg/api/pod/util_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,6 +3337,8 @@ func TestDropSidecarContainers(t *testing.T) {
33373337
}
33383338

33393339
func TestDropClusterTrustBundleProjectedVolumes(t *testing.T) {
3340+
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ClusterTrustBundle, true)
3341+
33403342
testCases := []struct {
33413343
description string
33423344
clusterTrustBundleProjectionEnabled bool

pkg/apis/core/v1/defaults_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,7 @@ func TestWorkloadDefaults(t *testing.T) {
4949
t.Run("disabled_features", func(t *testing.T) { testWorkloadDefaults(t, false) })
5050
}
5151
func testWorkloadDefaults(t *testing.T, featuresEnabled bool) {
52-
allFeatures := utilfeature.DefaultFeatureGate.DeepCopy().GetAll()
53-
for feature, featureSpec := range allFeatures {
54-
if !featureSpec.LockToDefault {
55-
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, feature, featuresEnabled)
56-
}
57-
}
52+
setAllFeatures(t, featuresEnabled)
5853
// New defaults under PodTemplateSpec are only acceptable if they would not be applied when reading data from a previous release.
5954
// Forbidden: adding a new field `MyField *bool` and defaulting it to a non-nil value
6055
// Forbidden: defaulting an existing field `MyField *bool` when it was previously not defaulted
@@ -240,12 +235,7 @@ func TestPodDefaults(t *testing.T) {
240235
t.Run("disabled_features", func(t *testing.T) { testPodDefaults(t, false) })
241236
}
242237
func testPodDefaults(t *testing.T, featuresEnabled bool) {
243-
features := utilfeature.DefaultFeatureGate.DeepCopy().GetAll()
244-
for feature, featureSpec := range features {
245-
if !featureSpec.LockToDefault {
246-
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, feature, featuresEnabled)
247-
}
248-
}
238+
setAllFeatures(t, featuresEnabled)
249239
pod := &v1.Pod{}
250240
// New defaults under PodSpec are only acceptable if they would not be applied when reading data from a previous release.
251241
// Forbidden: adding a new field `MyField *bool` and defaulting it to a non-nil value
@@ -3395,3 +3385,13 @@ func TestSetDefaults_PodLogOptions(t *testing.T) {
33953385
})
33963386
}
33973387
}
3388+
3389+
func setAllFeatures(t *testing.T, featuresEnabled bool) {
3390+
features := featuregatetesting.FeatureOverrides{}
3391+
for feature, featureSpec := range utilfeature.DefaultFeatureGate.DeepCopy().GetAll() {
3392+
if !featureSpec.LockToDefault {
3393+
features[feature] = featuresEnabled
3394+
}
3395+
}
3396+
featuregatetesting.SetFeatureGatesDuringTest(t, utilfeature.DefaultFeatureGate, features)
3397+
}

pkg/kubelet/apis/config/validation/validation_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,25 @@ func TestValidateKubeletConfiguration(t *testing.T) {
361361
}, {
362362
name: "specify ShutdownGracePeriod without enabling GracefulNodeShutdown",
363363
configure: func(conf *kubeletconfig.KubeletConfiguration) *kubeletconfig.KubeletConfiguration {
364-
conf.FeatureGates = map[string]bool{"GracefulNodeShutdown": false}
364+
conf.FeatureGates = map[string]bool{
365+
"GracefulNodeShutdown": false,
366+
// Disable dependents.
367+
"GracefulNodeShutdownBasedOnPodPriority": false,
368+
"WindowsGracefulNodeShutdown": false,
369+
}
365370
conf.ShutdownGracePeriod = metav1.Duration{Duration: 1 * time.Second}
366371
return conf
367372
},
368373
errMsg: "invalid configuration: specifying shutdownGracePeriod or shutdownGracePeriodCriticalPods requires feature gate GracefulNodeShutdown",
369374
}, {
370375
name: "specify ShutdownGracePeriodCriticalPods without enabling GracefulNodeShutdown",
371376
configure: func(conf *kubeletconfig.KubeletConfiguration) *kubeletconfig.KubeletConfiguration {
372-
conf.FeatureGates = map[string]bool{"GracefulNodeShutdown": false}
377+
conf.FeatureGates = map[string]bool{
378+
"GracefulNodeShutdown": false,
379+
// Disable dependents.
380+
"GracefulNodeShutdownBasedOnPodPriority": false,
381+
"WindowsGracefulNodeShutdown": false,
382+
}
373383
conf.ShutdownGracePeriodCriticalPods = metav1.Duration{Duration: 1 * time.Second}
374384
return conf
375385
},

pkg/registry/core/pod/strategy_test.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,49 +2000,6 @@ func Test_mutateTopologySpreadConstraints(t *testing.T) {
20002000
},
20012001
},
20022002
},
2003-
{
2004-
name: "matchLabelKeys are not merged into labelSelector when MatchLabelKeysInPodTopologySpread is false and MatchLabelKeysInPodTopologySpreadSelectorMerge is true",
2005-
matchLabelKeysEnabled: false,
2006-
matchLabelKeysSelectorMergeEnabled: true,
2007-
pod: &api.Pod{
2008-
ObjectMeta: metav1.ObjectMeta{
2009-
Labels: map[string]string{
2010-
"country": "Japan",
2011-
"city": "Tokyo",
2012-
},
2013-
},
2014-
Spec: api.PodSpec{
2015-
TopologySpreadConstraints: []api.TopologySpreadConstraint{
2016-
{
2017-
MaxSkew: 1,
2018-
TopologyKey: "kubernetes.io/hostname",
2019-
WhenUnsatisfiable: api.DoNotSchedule,
2020-
LabelSelector: &metav1.LabelSelector{},
2021-
MatchLabelKeys: []string{"country", "city"},
2022-
},
2023-
},
2024-
},
2025-
},
2026-
wantPod: &api.Pod{
2027-
ObjectMeta: metav1.ObjectMeta{
2028-
Labels: map[string]string{
2029-
"country": "Japan",
2030-
"city": "Tokyo",
2031-
},
2032-
},
2033-
Spec: api.PodSpec{
2034-
TopologySpreadConstraints: []api.TopologySpreadConstraint{
2035-
{
2036-
MaxSkew: 1,
2037-
TopologyKey: "kubernetes.io/hostname",
2038-
WhenUnsatisfiable: api.DoNotSchedule,
2039-
LabelSelector: &metav1.LabelSelector{},
2040-
MatchLabelKeys: []string{"country", "city"},
2041-
},
2042-
},
2043-
},
2044-
},
2045-
},
20462003
}
20472004

20482005
for _, tc := range tests {

pkg/registry/resource/resourceclaim/strategy_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,18 +1129,6 @@ func TestStatusStrategyUpdate(t *testing.T) {
11291129
bindingConditions: false,
11301130
deviceStatusFeatureGate: true,
11311131
},
1132-
"drop-fields-binding-conditions-disable-device-status-feature-gate": {
1133-
oldObj: objWithStatus,
1134-
newObj: objWithDeviceBindingConditions,
1135-
expectObj: objWithStatus,
1136-
verify: func(t *testing.T, as []testclient.Action) {
1137-
if len(as) != 0 {
1138-
t.Errorf("expected no action to be taken")
1139-
}
1140-
},
1141-
bindingConditions: true,
1142-
deviceStatusFeatureGate: false,
1143-
},
11441132
"keep-fields-consumable-capacity-with-device-status": {
11451133
oldObj: func() *resource.ResourceClaim {
11461134
obj := obj.DeepCopy()

pkg/registry/resource/resourceslice/strategy_test.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,6 @@ func TestResourceSliceStrategyCreate(t *testing.T) {
258258
return obj
259259
}(),
260260
},
261-
"drop-fields-binding-conditions-with-device-status": {
262-
obj: sliceWithBindingConditions,
263-
bindingConditions: true,
264-
deviceStatus: false,
265-
expectObj: func() *resource.ResourceSlice {
266-
obj := slice.DeepCopy()
267-
obj.Generation = 1
268-
return obj
269-
}(),
270-
},
271261
"drop-fields-binding-conditions-with-binding-conditions": {
272262
obj: sliceWithBindingConditions,
273263
bindingConditions: false,
@@ -530,22 +520,6 @@ func TestResourceSliceStrategyUpdate(t *testing.T) {
530520
bindingConditions: false,
531521
deviceStatus: false,
532522
},
533-
"drop-fields-binding-conditions-with-device-status": {
534-
oldObj: slice,
535-
newObj: func() *resource.ResourceSlice {
536-
obj := sliceWithBindingConditions.DeepCopy()
537-
obj.ResourceVersion = "4"
538-
return obj
539-
}(),
540-
expectObj: func() *resource.ResourceSlice {
541-
obj := slice.DeepCopy()
542-
obj.ResourceVersion = "4"
543-
obj.Generation = 1
544-
return obj
545-
}(),
546-
bindingConditions: true,
547-
deviceStatus: false,
548-
},
549523
"drop-fields-binding-conditions-with-binding-conditions": {
550524
oldObj: slice,
551525
newObj: func() *resource.ResourceSlice {

pkg/scheduler/scheduler_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,12 +1006,15 @@ func Test_UnionedGVKs(t *testing.T) {
10061006
t.Run(tt.name, func(t *testing.T) {
10071007
pluginConfig := defaults.PluginConfigsV1
10081008

1009+
if !tt.enableSchedulerQueueingHints {
1010+
// Set emulated version before setting other feature gates, since it can impact feature dependencies.
1011+
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, utilfeature.DefaultFeatureGate, version.MustParse("1.33"))
1012+
}
10091013
featuregatetesting.SetFeatureGatesDuringTest(t, utilfeature.DefaultFeatureGate, featuregatetesting.FeatureOverrides{
10101014
features.InPlacePodVerticalScaling: tt.enableInPlacePodVerticalScaling,
10111015
features.DynamicResourceAllocation: tt.enableDynamicResourceAllocation,
10121016
})
10131017
if !tt.enableSchedulerQueueingHints {
1014-
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, utilfeature.DefaultFeatureGate, version.MustParse("1.33"))
10151018
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.SchedulerQueueingHints, false)
10161019
// The test uses defaults.PluginConfigsV1, which contains the filter timeout.
10171020
// With emulation of 1.33, the DRASchedulerFilterTimeout feature gets disabled

test/integration/scheduler_perf/scheduler_perf.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,11 +1117,7 @@ func setupTestCase(t testing.TB, tc *testCase, featureGates map[featuregate.Feat
11171117
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, utilfeature.DefaultFeatureGate, version.MustParse("1.33"))
11181118
}
11191119

1120-
// Iterate by sorted feature name, to make it deterministic and put AllAlpha/Beta first to enable
1121-
// overriding that choice.
1122-
for _, name := range slices.Sorted(maps.Keys(featureGates)) {
1123-
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, name, featureGates[name])
1124-
}
1120+
featuregatetesting.SetFeatureGatesDuringTest(t, utilfeature.DefaultFeatureGate, featureGates)
11251121

11261122
// 30 minutes should be plenty enough even for the 5000-node tests.
11271123
timeout := 30 * time.Minute

0 commit comments

Comments
 (0)