mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Merge pull request #128046 from AxeZhan/ga3960
Graduate PodLifecycleSleepAction to GA
This commit is contained in:
		@@ -33,6 +33,7 @@ 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"
 | 
			
		||||
@@ -3550,6 +3551,7 @@ 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
 | 
			
		||||
 
 | 
			
		||||
@@ -565,6 +565,7 @@ 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},
 | 
			
		||||
 
 | 
			
		||||
@@ -32,12 +32,9 @@ 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"
 | 
			
		||||
@@ -859,8 +856,6 @@ 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()
 | 
			
		||||
 
 | 
			
		||||
@@ -36,6 +36,7 @@ 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"
 | 
			
		||||
@@ -1869,6 +1870,7 @@ 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
 | 
			
		||||
 
 | 
			
		||||
@@ -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(feature.PodLifecycleSleepAction, func() {
 | 
			
		||||
var _ = SIGDescribe("Lifecycle Sleep Hook", framework.WithNodeConformance(), func() {
 | 
			
		||||
	f := framework.NewDefaultFramework("pod-lifecycle-sleep-action")
 | 
			
		||||
	f.NamespacePodSecurityLevel = admissionapi.LevelBaseline
 | 
			
		||||
	var podClient *e2epod.PodClient
 | 
			
		||||
@@ -560,6 +560,11 @@ var _ = SIGDescribe(feature.PodLifecycleSleepAction, func() {
 | 
			
		||||
		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{
 | 
			
		||||
@@ -580,11 +585,15 @@ var _ = SIGDescribe(feature.PodLifecycleSleepAction, func() {
 | 
			
		||||
				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: 15},
 | 
			
		||||
					Sleep: &v1.SleepAction{Seconds: 30},
 | 
			
		||||
				},
 | 
			
		||||
			}
 | 
			
		||||
			podWithHook := getPodWithHook("pod-with-prestop-sleep-hook", imageutils.GetPauseImageName(), lifecycle)
 | 
			
		||||
@@ -592,20 +601,24 @@ var _ = SIGDescribe(feature.PodLifecycleSleepAction, func() {
 | 
			
		||||
			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(2), e2epod.DefaultPodDeletionTimeout)
 | 
			
		||||
			podClient.DeleteSync(ctx, podWithHook.Name, *metav1.NewDeleteOptions(5), e2epod.DefaultPodDeletionTimeout)
 | 
			
		||||
			cost := time.Since(start)
 | 
			
		||||
			// cost should be
 | 
			
		||||
			// longer than 2 seconds (we change gracePeriodSeconds to 2 seconds here, and it's less than sleep action)
 | 
			
		||||
			// longer than 5 seconds (we change gracePeriodSeconds to 5 seconds here, and it's less than sleep action)
 | 
			
		||||
			// shorter than sleep action (to make sure it doesn't take effect)
 | 
			
		||||
			if !validDuration(cost, 2, 15) {
 | 
			
		||||
			if !validDuration(cost, 5, 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: 20},
 | 
			
		||||
					Sleep: &v1.SleepAction{Seconds: 25},
 | 
			
		||||
				},
 | 
			
		||||
			}
 | 
			
		||||
			name := "pod-with-prestop-sleep-hook"
 | 
			
		||||
@@ -622,11 +635,10 @@ var _ = SIGDescribe(feature.PodLifecycleSleepAction, func() {
 | 
			
		||||
			cost := time.Since(start)
 | 
			
		||||
			// cost should be
 | 
			
		||||
			// shorter than sleep action (container is terminated and sleep action should be ignored)
 | 
			
		||||
			if !validDuration(cost, 0, 15) {
 | 
			
		||||
			if !validDuration(cost, 0, 25) {
 | 
			
		||||
				framework.Failf("unexpected delay duration before killing the pod, cost = %v", cost)
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
 | 
			
		||||
	})
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -264,9 +264,6 @@ 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"))
 | 
			
		||||
 
 | 
			
		||||
@@ -898,6 +898,10 @@
 | 
			
		||||
    lockToDefault: false
 | 
			
		||||
    preRelease: Beta
 | 
			
		||||
    version: "1.30"
 | 
			
		||||
  - default: true
 | 
			
		||||
    lockToDefault: true
 | 
			
		||||
    preRelease: GA
 | 
			
		||||
    version: "1.32"
 | 
			
		||||
- name: PodLifecycleSleepActionAllowZero
 | 
			
		||||
  versionedSpecs:
 | 
			
		||||
  - default: false
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user