From d46050aa5d364606cabecc7e508f27cfdf3d4aac Mon Sep 17 00:00:00 2001 From: Sreeram Date: Wed, 26 Feb 2025 12:15:30 +0530 Subject: [PATCH 1/4] PodLifecycleSleepActionAllowZero to Beta --- .../reference/versioned_feature_list.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/compatibility_lifecycle/reference/versioned_feature_list.yaml b/test/compatibility_lifecycle/reference/versioned_feature_list.yaml index e6bf4c342fa..062c7861345 100644 --- a/test/compatibility_lifecycle/reference/versioned_feature_list.yaml +++ b/test/compatibility_lifecycle/reference/versioned_feature_list.yaml @@ -1027,6 +1027,10 @@ lockToDefault: false preRelease: Alpha version: "1.32" + - default: true + lockToDefault: false + preRelease: Beta + version: "1.33" - name: PodLogsQuerySplitStreams versionedSpecs: - default: false From c0a1489bc86775363c2befa378e44016c92ab4b2 Mon Sep 17 00:00:00 2001 From: Sreeram Date: Fri, 7 Mar 2025 23:01:16 +0530 Subject: [PATCH 2/4] Fix unit tests --- pkg/api/pod/util_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/api/pod/util_test.go b/pkg/api/pod/util_test.go index 4ffb44b4ad0..df0f4eae8d5 100644 --- a/pkg/api/pod/util_test.go +++ b/pkg/api/pod/util_test.go @@ -4115,7 +4115,7 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) { { name: "no lifecycle hooks", podSpec: &api.PodSpec{}, - expectAllowPodLifecycleSleepActionZeroValue: false, + expectAllowPodLifecycleSleepActionZeroValue: true, }, { name: "Prestop with non-zero second duration", @@ -4132,7 +4132,7 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) { }, }, }, - expectAllowPodLifecycleSleepActionZeroValue: false, + expectAllowPodLifecycleSleepActionZeroValue: true, }, { name: "PostStart with non-zero second duration", @@ -4149,7 +4149,7 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) { }, }, }, - expectAllowPodLifecycleSleepActionZeroValue: false, + expectAllowPodLifecycleSleepActionZeroValue: true, }, { name: "PreStop with zero seconds", From 3043fbc3dafc9d5c8305dc97bf59489b70f3f6a3 Mon Sep 17 00:00:00 2001 From: Sreeram Date: Wed, 19 Mar 2025 23:09:41 +0530 Subject: [PATCH 3/4] Added feature gate to unit test --- pkg/api/pod/util_test.go | 90 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 2 deletions(-) diff --git a/pkg/api/pod/util_test.go b/pkg/api/pod/util_test.go index df0f4eae8d5..db5bee74306 100644 --- a/pkg/api/pod/util_test.go +++ b/pkg/api/pod/util_test.go @@ -4110,11 +4110,13 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) { testCases := []struct { name string podSpec *api.PodSpec + featureEnabled bool expectAllowPodLifecycleSleepActionZeroValue bool }{ { - name: "no lifecycle hooks", - podSpec: &api.PodSpec{}, + name: "no lifecycle hooks", + podSpec: &api.PodSpec{}, + featureEnabled: true, expectAllowPodLifecycleSleepActionZeroValue: true, }, { @@ -4132,6 +4134,7 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) { }, }, }, + featureEnabled: true, expectAllowPodLifecycleSleepActionZeroValue: true, }, { @@ -4149,6 +4152,7 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) { }, }, }, + featureEnabled: true, expectAllowPodLifecycleSleepActionZeroValue: true, }, { @@ -4166,6 +4170,7 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) { }, }, }, + featureEnabled: true, expectAllowPodLifecycleSleepActionZeroValue: true, }, { @@ -4183,12 +4188,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") }) From 323d55e67f9031ee98cbcba1f5f9c870f43e42a2 Mon Sep 17 00:00:00 2001 From: Sreeram Date: Thu, 20 Mar 2025 21:12:45 +0530 Subject: [PATCH 4/4] Rerun update-featuregates.sh --- pkg/features/kube_features.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index 3c6e9614d98..ba0acbcba1c 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -1556,6 +1556,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: {