Skip to content

Commit 9fe41b6

Browse files
authored
Merge pull request kubernetes#128046 from AxeZhan/ga3960
Graduate PodLifecycleSleepAction to GA
2 parents 97c79df + 200a61b commit 9fe41b6

File tree

7 files changed

+31
-18
lines changed

7 files changed

+31
-18
lines changed

pkg/api/pod/util_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
"k8s.io/apimachinery/pkg/util/sets"
3535
"k8s.io/apimachinery/pkg/util/validation/field"
36+
"k8s.io/apimachinery/pkg/util/version"
3637
utilfeature "k8s.io/apiserver/pkg/util/feature"
3738
featuregatetesting "k8s.io/component-base/featuregate/testing"
3839
api "k8s.io/kubernetes/pkg/apis/core"
@@ -3550,6 +3551,7 @@ func TestDropPodLifecycleSleepAction(t *testing.T) {
35503551

35513552
for i, tc := range testCases {
35523553
t.Run(fmt.Sprintf("test_%d", i), func(t *testing.T) {
3554+
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, utilfeature.DefaultFeatureGate, version.MustParse("1.31"))
35533555
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodLifecycleSleepAction, tc.gateEnabled)
35543556

35553557
// preStop

pkg/features/versioned_kube_features.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ var defaultVersionedKubernetesFeatureGates = map[featuregate.Feature]featuregate
565565
PodLifecycleSleepAction: {
566566
{Version: version.MustParse("1.29"), Default: false, PreRelease: featuregate.Alpha},
567567
{Version: version.MustParse("1.30"), Default: true, PreRelease: featuregate.Beta},
568+
{Version: version.MustParse("1.32"), Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.35 when this version cannot be emulated any longer
568569
},
569570
PodReadyToStartContainersCondition: {
570571
{Version: version.MustParse("1.28"), Default: false, PreRelease: featuregate.Alpha},

pkg/kubelet/lifecycle/handlers_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ import (
3232
v1 "k8s.io/api/core/v1"
3333
"k8s.io/apimachinery/pkg/types"
3434
"k8s.io/apimachinery/pkg/util/intstr"
35-
utilfeature "k8s.io/apiserver/pkg/util/feature"
3635
"k8s.io/client-go/tools/record"
37-
featuregatetesting "k8s.io/component-base/featuregate/testing"
3836
"k8s.io/component-base/metrics/legacyregistry"
3937
"k8s.io/component-base/metrics/testutil"
40-
"k8s.io/kubernetes/pkg/features"
4138
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
4239
"k8s.io/kubernetes/pkg/kubelet/metrics"
4340
"k8s.io/kubernetes/pkg/kubelet/util/format"
@@ -859,8 +856,6 @@ func TestRunSleepHandler(t *testing.T) {
859856

860857
for _, tt := range tests {
861858
t.Run(tt.name, func(t *testing.T) {
862-
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodLifecycleSleepAction, true)
863-
864859
pod.Spec.Containers[0].Lifecycle.PreStop.Sleep = &v1.SleepAction{Seconds: tt.sleepSeconds}
865860
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(tt.terminationGracePeriodSeconds)*time.Second)
866861
defer cancel()

pkg/registry/core/pod/strategy_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"k8s.io/apimachinery/pkg/labels"
3737
"k8s.io/apimachinery/pkg/runtime"
3838
"k8s.io/apimachinery/pkg/types"
39+
"k8s.io/apimachinery/pkg/util/version"
3940
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
4041
utilfeature "k8s.io/apiserver/pkg/util/feature"
4142
"k8s.io/apiserver/pkg/warning"
@@ -1869,6 +1870,7 @@ func TestPodLifecycleSleepActionEnablement(t *testing.T) {
18691870

18701871
for _, tc := range testCases {
18711872
t.Run(tc.description, func(t *testing.T) {
1873+
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, utilfeature.DefaultFeatureGate, version.MustParse("1.31"))
18721874
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodLifecycleSleepAction, tc.gateEnabled)
18731875

18741876
newPod := tc.newPod

test/e2e/common/node/lifecycle_hook.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ func validDuration(duration time.Duration, low, high int64) bool {
551551
return duration >= time.Second*time.Duration(low) && duration <= time.Second*time.Duration(high)
552552
}
553553

554-
var _ = SIGDescribe(feature.PodLifecycleSleepAction, func() {
554+
var _ = SIGDescribe("Lifecycle Sleep Hook", framework.WithNodeConformance(), func() {
555555
f := framework.NewDefaultFramework("pod-lifecycle-sleep-action")
556556
f.NamespacePodSecurityLevel = admissionapi.LevelBaseline
557557
var podClient *e2epod.PodClient
@@ -560,6 +560,11 @@ var _ = SIGDescribe(feature.PodLifecycleSleepAction, func() {
560560
ginkgo.BeforeEach(func(ctx context.Context) {
561561
podClient = e2epod.NewPodClient(f)
562562
})
563+
/*
564+
Release : v1.32
565+
Testname: Pod Lifecycle, prestop sleep hook
566+
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.
567+
*/
563568
ginkgo.It("valid prestop hook using sleep action", func(ctx context.Context) {
564569
lifecycle := &v1.Lifecycle{
565570
PreStop: &v1.LifecycleHandler{
@@ -580,32 +585,40 @@ var _ = SIGDescribe(feature.PodLifecycleSleepAction, func() {
580585
framework.Failf("unexpected delay duration before killing the pod, cost = %v", cost)
581586
}
582587
})
583-
588+
/*
589+
Release : v1.32
590+
Testname: Pod Lifecycle, prestop sleep hook with low gracePeriodSeconds
591+
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.
592+
*/
584593
ginkgo.It("reduce GracePeriodSeconds during runtime", func(ctx context.Context) {
585594
lifecycle := &v1.Lifecycle{
586595
PreStop: &v1.LifecycleHandler{
587-
Sleep: &v1.SleepAction{Seconds: 15},
596+
Sleep: &v1.SleepAction{Seconds: 30},
588597
},
589598
}
590599
podWithHook := getPodWithHook("pod-with-prestop-sleep-hook", imageutils.GetPauseImageName(), lifecycle)
591600
ginkgo.By("create the pod with lifecycle hook using sleep action")
592601
podClient.CreateSync(ctx, podWithHook)
593602
ginkgo.By("delete the pod with lifecycle hook using sleep action")
594603
start := time.Now()
595-
podClient.DeleteSync(ctx, podWithHook.Name, *metav1.NewDeleteOptions(2), e2epod.DefaultPodDeletionTimeout)
604+
podClient.DeleteSync(ctx, podWithHook.Name, *metav1.NewDeleteOptions(5), e2epod.DefaultPodDeletionTimeout)
596605
cost := time.Since(start)
597606
// cost should be
598-
// longer than 2 seconds (we change gracePeriodSeconds to 2 seconds here, and it's less than sleep action)
607+
// longer than 5 seconds (we change gracePeriodSeconds to 5 seconds here, and it's less than sleep action)
599608
// shorter than sleep action (to make sure it doesn't take effect)
600-
if !validDuration(cost, 2, 15) {
609+
if !validDuration(cost, 5, 15) {
601610
framework.Failf("unexpected delay duration before killing the pod, cost = %v", cost)
602611
}
603612
})
604-
613+
/*
614+
Release : v1.32
615+
Testname: Pod Lifecycle, prestop sleep hook with erroneous startup command
616+
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.
617+
*/
605618
ginkgo.It("ignore terminated container", func(ctx context.Context) {
606619
lifecycle := &v1.Lifecycle{
607620
PreStop: &v1.LifecycleHandler{
608-
Sleep: &v1.SleepAction{Seconds: 20},
621+
Sleep: &v1.SleepAction{Seconds: 25},
609622
},
610623
}
611624
name := "pod-with-prestop-sleep-hook"
@@ -622,11 +635,10 @@ var _ = SIGDescribe(feature.PodLifecycleSleepAction, func() {
622635
cost := time.Since(start)
623636
// cost should be
624637
// shorter than sleep action (container is terminated and sleep action should be ignored)
625-
if !validDuration(cost, 0, 15) {
638+
if !validDuration(cost, 0, 25) {
626639
framework.Failf("unexpected delay duration before killing the pod, cost = %v", cost)
627640
}
628641
})
629-
630642
})
631643
})
632644

test/e2e/feature/feature.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,6 @@ var (
264264
// TODO: document the feature (owning SIG, when to use this feature for a test)
265265
PodGarbageCollector = framework.WithFeature(framework.ValidFeatures.Add("PodGarbageCollector"))
266266

267-
// TODO: document the feature (owning SIG, when to use this feature for a test)
268-
PodLifecycleSleepAction = framework.WithFeature(framework.ValidFeatures.Add("PodLifecycleSleepAction"))
269-
270267
// Owner: sig-node
271268
// Marks a single test that tests Pod Lifecycle Sleep action with zero duration. Requires feature gate PodLifecycleSleepActionAllowZero to be enabled.
272269
PodLifecycleSleepActionAllowZero = framework.WithFeature(framework.ValidFeatures.Add("PodLifecycleSleepActionAllowZero"))

test/featuregates_linter/test_data/versioned_feature_list.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,10 @@
898898
lockToDefault: false
899899
preRelease: Beta
900900
version: "1.30"
901+
- default: true
902+
lockToDefault: true
903+
preRelease: GA
904+
version: "1.32"
901905
- name: PodLifecycleSleepActionAllowZero
902906
versionedSpecs:
903907
- default: false

0 commit comments

Comments
 (0)