diff --git a/pkg/api/pod/util_test.go b/pkg/api/pod/util_test.go index 4f6b5c80e4a..acb6305a02e 100644 --- a/pkg/api/pod/util_test.go +++ b/pkg/api/pod/util_test.go @@ -4114,12 +4114,14 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) { testCases := []struct { name string podSpec *api.PodSpec + featureEnabled bool expectAllowPodLifecycleSleepActionZeroValue bool }{ { - name: "no lifecycle hooks", - podSpec: &api.PodSpec{}, - expectAllowPodLifecycleSleepActionZeroValue: false, + name: "no lifecycle hooks", + podSpec: &api.PodSpec{}, + featureEnabled: true, + expectAllowPodLifecycleSleepActionZeroValue: true, }, { name: "Prestop with non-zero second duration", @@ -4136,7 +4138,8 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) { }, }, }, - expectAllowPodLifecycleSleepActionZeroValue: false, + featureEnabled: true, + expectAllowPodLifecycleSleepActionZeroValue: true, }, { name: "PostStart with non-zero second duration", @@ -4153,7 +4156,8 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) { }, }, }, - expectAllowPodLifecycleSleepActionZeroValue: false, + featureEnabled: true, + expectAllowPodLifecycleSleepActionZeroValue: true, }, { name: "PreStop with zero seconds", @@ -4170,6 +4174,7 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) { }, }, }, + featureEnabled: true, expectAllowPodLifecycleSleepActionZeroValue: true, }, { @@ -4187,12 +4192,93 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) { }, }, }, + featureEnabled: true, + expectAllowPodLifecycleSleepActionZeroValue: true, + }, + { + name: "no lifecycle hooks with feature gate disabled", + podSpec: &api.PodSpec{}, + featureEnabled: false, + expectAllowPodLifecycleSleepActionZeroValue: false, + }, + { + name: "Prestop with non-zero second duration with feature gate disabled", + podSpec: &api.PodSpec{ + Containers: []api.Container{ + { + Lifecycle: &api.Lifecycle{ + PreStop: &api.LifecycleHandler{ + Sleep: &api.SleepAction{ + Seconds: 1, + }, + }, + }, + }, + }, + }, + featureEnabled: false, + expectAllowPodLifecycleSleepActionZeroValue: false, + }, + { + name: "PostStart with non-zero second duration with feature gate disabled", + podSpec: &api.PodSpec{ + Containers: []api.Container{ + { + Lifecycle: &api.Lifecycle{ + PostStart: &api.LifecycleHandler{ + Sleep: &api.SleepAction{ + Seconds: 1, + }, + }, + }, + }, + }, + }, + featureEnabled: false, + expectAllowPodLifecycleSleepActionZeroValue: false, + }, + { + name: "PreStop with zero seconds with feature gate disabled", + podSpec: &api.PodSpec{ + Containers: []api.Container{ + { + Lifecycle: &api.Lifecycle{ + PreStop: &api.LifecycleHandler{ + Sleep: &api.SleepAction{ + Seconds: 0, + }, + }, + }, + }, + }, + }, + featureEnabled: false, + expectAllowPodLifecycleSleepActionZeroValue: true, + }, + { + name: "PostStart with zero seconds with feature gate disabled", + podSpec: &api.PodSpec{ + Containers: []api.Container{ + { + Lifecycle: &api.Lifecycle{ + PostStart: &api.LifecycleHandler{ + Sleep: &api.SleepAction{ + Seconds: 0, + }, + }, + }, + }, + }, + }, + featureEnabled: false, expectAllowPodLifecycleSleepActionZeroValue: true, }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodLifecycleSleepActionAllowZero, tc.featureEnabled) + gotOptions := GetValidationOptionsFromPodSpecAndMeta(&api.PodSpec{}, tc.podSpec, nil, nil) assert.Equal(t, tc.expectAllowPodLifecycleSleepActionZeroValue, gotOptions.AllowPodLifecycleSleepActionZeroValue, "AllowPodLifecycleSleepActionZeroValue") }) diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index e871a53c1d3..ec9a8d2fd68 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -1558,6 +1558,7 @@ var defaultVersionedKubernetesFeatureGates = map[featuregate.Feature]featuregate PodLifecycleSleepActionAllowZero: { {Version: version.MustParse("1.32"), Default: false, PreRelease: featuregate.Alpha}, + {Version: version.MustParse("1.33"), Default: true, PreRelease: featuregate.Beta}, }, PodObservedGenerationTracking: { diff --git a/test/compatibility_lifecycle/reference/versioned_feature_list.yaml b/test/compatibility_lifecycle/reference/versioned_feature_list.yaml index 8b5a0456f10..dd0ad06e1fc 100644 --- a/test/compatibility_lifecycle/reference/versioned_feature_list.yaml +++ b/test/compatibility_lifecycle/reference/versioned_feature_list.yaml @@ -1035,6 +1035,10 @@ lockToDefault: false preRelease: Alpha version: "1.32" + - default: true + lockToDefault: false + preRelease: Beta + version: "1.33" - name: PodLogsQuerySplitStreams versionedSpecs: - default: false