From 350b0d2b93c534eef61120d6aa6b92bae58f2de3 Mon Sep 17 00:00:00 2001 From: Kevin Hannon Date: Wed, 6 Nov 2024 16:29:19 -0500 Subject: [PATCH] Revert "Graduate PodLifecycleSleepAction to GA" --- pkg/api/pod/util_test.go | 2 -- pkg/features/versioned_kube_features.go | 1 - pkg/kubelet/lifecycle/handlers_test.go | 5 +++ pkg/registry/core/pod/strategy_test.go | 2 -- test/e2e/common/node/lifecycle_hook.go | 32 ++++++------------- test/e2e/feature/feature.go | 3 ++ .../test_data/versioned_feature_list.yaml | 4 --- 7 files changed, 18 insertions(+), 31 deletions(-) diff --git a/pkg/api/pod/util_test.go b/pkg/api/pod/util_test.go index 3d799d24b15..67ab805b7a6 100644 --- a/pkg/api/pod/util_test.go +++ b/pkg/api/pod/util_test.go @@ -33,7 +33,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/validation/field" - "k8s.io/apimachinery/pkg/util/version" utilfeature "k8s.io/apiserver/pkg/util/feature" featuregatetesting "k8s.io/component-base/featuregate/testing" api "k8s.io/kubernetes/pkg/apis/core" @@ -3402,7 +3401,6 @@ func TestDropPodLifecycleSleepAction(t *testing.T) { for i, tc := range testCases { t.Run(fmt.Sprintf("test_%d", i), func(t *testing.T) { - featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, utilfeature.DefaultFeatureGate, version.MustParse("1.31")) featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodLifecycleSleepAction, tc.gateEnabled) // preStop diff --git a/pkg/features/versioned_kube_features.go b/pkg/features/versioned_kube_features.go index 1c99433aaa7..fbc7404916b 100644 --- a/pkg/features/versioned_kube_features.go +++ b/pkg/features/versioned_kube_features.go @@ -572,7 +572,6 @@ var defaultVersionedKubernetesFeatureGates = map[featuregate.Feature]featuregate PodLifecycleSleepAction: { {Version: version.MustParse("1.29"), Default: false, PreRelease: featuregate.Alpha}, {Version: version.MustParse("1.30"), Default: true, PreRelease: featuregate.Beta}, - {Version: version.MustParse("1.32"), Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.35 when this version cannot be emulated any longer }, PodReadyToStartContainersCondition: { {Version: version.MustParse("1.28"), Default: false, PreRelease: featuregate.Alpha}, diff --git a/pkg/kubelet/lifecycle/handlers_test.go b/pkg/kubelet/lifecycle/handlers_test.go index af4a3b612f7..218e86d4e3a 100644 --- a/pkg/kubelet/lifecycle/handlers_test.go +++ b/pkg/kubelet/lifecycle/handlers_test.go @@ -32,9 +32,12 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/intstr" + utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/client-go/tools/record" + featuregatetesting "k8s.io/component-base/featuregate/testing" "k8s.io/component-base/metrics/legacyregistry" "k8s.io/component-base/metrics/testutil" + "k8s.io/kubernetes/pkg/features" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" "k8s.io/kubernetes/pkg/kubelet/metrics" "k8s.io/kubernetes/pkg/kubelet/util/format" @@ -856,6 +859,8 @@ func TestRunSleepHandler(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodLifecycleSleepAction, true) + pod.Spec.Containers[0].Lifecycle.PreStop.Sleep = &v1.SleepAction{Seconds: tt.sleepSeconds} ctx, cancel := context.WithTimeout(context.Background(), time.Duration(tt.terminationGracePeriodSeconds)*time.Second) defer cancel() diff --git a/pkg/registry/core/pod/strategy_test.go b/pkg/registry/core/pod/strategy_test.go index 068ff294cc3..1b29c4cdc31 100644 --- a/pkg/registry/core/pod/strategy_test.go +++ b/pkg/registry/core/pod/strategy_test.go @@ -36,7 +36,6 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/version" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/apiserver/pkg/warning" @@ -1870,7 +1869,6 @@ func TestPodLifecycleSleepActionEnablement(t *testing.T) { for _, tc := range testCases { t.Run(tc.description, func(t *testing.T) { - featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, utilfeature.DefaultFeatureGate, version.MustParse("1.31")) featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodLifecycleSleepAction, tc.gateEnabled) newPod := tc.newPod diff --git a/test/e2e/common/node/lifecycle_hook.go b/test/e2e/common/node/lifecycle_hook.go index fd278da0698..a6de625f36b 100644 --- a/test/e2e/common/node/lifecycle_hook.go +++ b/test/e2e/common/node/lifecycle_hook.go @@ -551,7 +551,7 @@ func validDuration(duration time.Duration, low, high int64) bool { return duration >= time.Second*time.Duration(low) && duration <= time.Second*time.Duration(high) } -var _ = SIGDescribe("Lifecycle Sleep Hook", framework.WithNodeConformance(), func() { +var _ = SIGDescribe(feature.PodLifecycleSleepAction, func() { f := framework.NewDefaultFramework("pod-lifecycle-sleep-action") f.NamespacePodSecurityLevel = admissionapi.LevelBaseline var podClient *e2epod.PodClient @@ -560,11 +560,6 @@ var _ = SIGDescribe("Lifecycle Sleep Hook", framework.WithNodeConformance(), fun ginkgo.BeforeEach(func(ctx context.Context) { podClient = e2epod.NewPodClient(f) }) - /* - Release : v1.32 - Testname: Pod Lifecycle, prestop sleep hook - Description: When a pre-stop handler is specified in the container lifecycle using a 'Sleep' action, then the handler MUST be invoked before the container is terminated. A test pod will be created to verify if its termination time aligns with the sleep time specified when it is terminated. - */ ginkgo.It("valid prestop hook using sleep action", func(ctx context.Context) { lifecycle := &v1.Lifecycle{ PreStop: &v1.LifecycleHandler{ @@ -585,15 +580,11 @@ var _ = SIGDescribe("Lifecycle Sleep Hook", framework.WithNodeConformance(), fun framework.Failf("unexpected delay duration before killing the pod, cost = %v", cost) } }) - /* - Release : v1.32 - Testname: Pod Lifecycle, prestop sleep hook with low gracePeriodSeconds - Description: When a pre-stop handler is specified in the container lifecycle using a 'Sleep' action, then the handler MUST be invoked before the container is terminated. A test pod will be created, and its `gracePeriodSeconds` will be modified to a value less than the sleep time before termination. The termination time will then be checked to ensure it aligns with the `gracePeriodSeconds` value. - */ + ginkgo.It("reduce GracePeriodSeconds during runtime", func(ctx context.Context) { lifecycle := &v1.Lifecycle{ PreStop: &v1.LifecycleHandler{ - Sleep: &v1.SleepAction{Seconds: 30}, + Sleep: &v1.SleepAction{Seconds: 15}, }, } podWithHook := getPodWithHook("pod-with-prestop-sleep-hook", imageutils.GetPauseImageName(), lifecycle) @@ -601,24 +592,20 @@ var _ = SIGDescribe("Lifecycle Sleep Hook", framework.WithNodeConformance(), fun podClient.CreateSync(ctx, podWithHook) ginkgo.By("delete the pod with lifecycle hook using sleep action") start := time.Now() - podClient.DeleteSync(ctx, podWithHook.Name, *metav1.NewDeleteOptions(5), e2epod.DefaultPodDeletionTimeout) + podClient.DeleteSync(ctx, podWithHook.Name, *metav1.NewDeleteOptions(2), e2epod.DefaultPodDeletionTimeout) cost := time.Since(start) // cost should be - // longer than 5 seconds (we change gracePeriodSeconds to 5 seconds here, and it's less than sleep action) + // longer than 2 seconds (we change gracePeriodSeconds to 2 seconds here, and it's less than sleep action) // shorter than sleep action (to make sure it doesn't take effect) - if !validDuration(cost, 5, 15) { + if !validDuration(cost, 2, 15) { framework.Failf("unexpected delay duration before killing the pod, cost = %v", cost) } }) - /* - Release : v1.32 - Testname: Pod Lifecycle, prestop sleep hook with erroneous startup command - Description: When a pre-stop handler is specified in the container lifecycle using a 'Sleep' action, then the handler MUST be invoked before the container is terminated. A test pod with an erroneous startup command will be created, and upon termination, it will be checked whether it ignored the sleep time. - */ + ginkgo.It("ignore terminated container", func(ctx context.Context) { lifecycle := &v1.Lifecycle{ PreStop: &v1.LifecycleHandler{ - Sleep: &v1.SleepAction{Seconds: 25}, + Sleep: &v1.SleepAction{Seconds: 20}, }, } name := "pod-with-prestop-sleep-hook" @@ -635,10 +622,11 @@ var _ = SIGDescribe("Lifecycle Sleep Hook", framework.WithNodeConformance(), fun cost := time.Since(start) // cost should be // shorter than sleep action (container is terminated and sleep action should be ignored) - if !validDuration(cost, 0, 25) { + if !validDuration(cost, 0, 15) { framework.Failf("unexpected delay duration before killing the pod, cost = %v", cost) } }) + }) }) diff --git a/test/e2e/feature/feature.go b/test/e2e/feature/feature.go index bb3e0a56400..557d0930cee 100644 --- a/test/e2e/feature/feature.go +++ b/test/e2e/feature/feature.go @@ -264,6 +264,9 @@ var ( // TODO: document the feature (owning SIG, when to use this feature for a test) PodGarbageCollector = framework.WithFeature(framework.ValidFeatures.Add("PodGarbageCollector")) + // TODO: document the feature (owning SIG, when to use this feature for a test) + PodLifecycleSleepAction = framework.WithFeature(framework.ValidFeatures.Add("PodLifecycleSleepAction")) + // Owner: sig-node // Marks a single test that tests Pod Lifecycle Sleep action with zero duration. Requires feature gate PodLifecycleSleepActionAllowZero to be enabled. PodLifecycleSleepActionAllowZero = framework.WithFeature(framework.ValidFeatures.Add("PodLifecycleSleepActionAllowZero")) diff --git a/test/featuregates_linter/test_data/versioned_feature_list.yaml b/test/featuregates_linter/test_data/versioned_feature_list.yaml index 44a83763c55..dc0704d20f2 100644 --- a/test/featuregates_linter/test_data/versioned_feature_list.yaml +++ b/test/featuregates_linter/test_data/versioned_feature_list.yaml @@ -906,10 +906,6 @@ lockToDefault: false preRelease: Beta version: "1.30" - - default: true - lockToDefault: true - preRelease: GA - version: "1.32" - name: PodLifecycleSleepActionAllowZero versionedSpecs: - default: false