From ae08fe1e1994a259f69f33197f17cfc040528801 Mon Sep 17 00:00:00 2001 From: Ryan Phillips Date: Tue, 6 Dec 2022 09:18:47 -0600 Subject: [PATCH] ProbeTerminationGracePeriod promote to GA --- pkg/api/pod/util.go | 2 +- pkg/api/pod/util_test.go | 101 -------------------- pkg/apis/core/validation/validation_test.go | 2 - pkg/features/kube_features.go | 5 +- 4 files changed, 4 insertions(+), 106 deletions(-) diff --git a/pkg/api/pod/util.go b/pkg/api/pod/util.go index 7370a7b13fd..65d5cae2b57 100644 --- a/pkg/api/pod/util.go +++ b/pkg/api/pod/util.go @@ -495,7 +495,7 @@ func dropDisabledFields( } } - if !utilfeature.DefaultFeatureGate.Enabled(features.ProbeTerminationGracePeriod) && !probeGracePeriodInUse(oldPodSpec) { + if !probeGracePeriodInUse(oldPodSpec) { // Set pod-level terminationGracePeriodSeconds to nil if the feature is disabled and it is not used VisitContainers(podSpec, AllContainers, func(c *api.Container, containerType ContainerType) bool { if c.LivenessProbe != nil { diff --git a/pkg/api/pod/util_test.go b/pkg/api/pod/util_test.go index f63802c5717..8ea9874492d 100644 --- a/pkg/api/pod/util_test.go +++ b/pkg/api/pod/util_test.go @@ -944,107 +944,6 @@ func TestDropDynamicResourceAllocation(t *testing.T) { } } -func TestDropProbeGracePeriod(t *testing.T) { - podWithProbeGracePeriod := func() *api.Pod { - livenessGracePeriod := int64(10) - livenessProbe := api.Probe{TerminationGracePeriodSeconds: &livenessGracePeriod} - startupGracePeriod := int64(10) - startupProbe := api.Probe{TerminationGracePeriodSeconds: &startupGracePeriod} - return &api.Pod{ - Spec: api.PodSpec{ - RestartPolicy: api.RestartPolicyNever, - Containers: []api.Container{{Name: "container1", Image: "testimage", LivenessProbe: &livenessProbe, StartupProbe: &startupProbe}}, - }, - } - } - podWithoutProbeGracePeriod := func() *api.Pod { - p := podWithProbeGracePeriod() - p.Spec.Containers[0].LivenessProbe.TerminationGracePeriodSeconds = nil - p.Spec.Containers[0].StartupProbe.TerminationGracePeriodSeconds = nil - return p - } - - podInfo := []struct { - description string - hasGracePeriod bool - pod func() *api.Pod - }{ - { - description: "has probe-level terminationGracePeriod", - hasGracePeriod: true, - pod: podWithProbeGracePeriod, - }, - { - description: "does not have probe-level terminationGracePeriod", - hasGracePeriod: false, - pod: podWithoutProbeGracePeriod, - }, - { - description: "only has liveness probe-level terminationGracePeriod", - hasGracePeriod: true, - pod: func() *api.Pod { - p := podWithProbeGracePeriod() - p.Spec.Containers[0].StartupProbe.TerminationGracePeriodSeconds = nil - return p - }, - }, - { - description: "is nil", - hasGracePeriod: false, - pod: func() *api.Pod { return nil }, - }, - } - - for _, enabled := range []bool{true, false} { - for _, oldPodInfo := range podInfo { - for _, newPodInfo := range podInfo { - oldPodHasGracePeriod, oldPod := oldPodInfo.hasGracePeriod, oldPodInfo.pod() - newPodHasGracePeriod, newPod := newPodInfo.hasGracePeriod, newPodInfo.pod() - if newPod == nil { - continue - } - - t.Run(fmt.Sprintf("feature enabled=%v, old pod %v, new pod %v", enabled, oldPodInfo.description, newPodInfo.description), func(t *testing.T) { - defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ProbeTerminationGracePeriod, enabled)() - - var oldPodSpec *api.PodSpec - if oldPod != nil { - oldPodSpec = &oldPod.Spec - } - dropDisabledFields(&newPod.Spec, nil, oldPodSpec, nil) - - // old pod should never be changed - if !reflect.DeepEqual(oldPod, oldPodInfo.pod()) { - t.Errorf("old pod changed: %v", cmp.Diff(oldPod, oldPodInfo.pod())) - } - - switch { - case enabled || oldPodHasGracePeriod: - // new pod should not be changed if the feature is enabled, or if the old pod had terminationGracePeriod - if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) - } - case newPodHasGracePeriod: - // new pod should be changed - if reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod was not changed") - } - // new pod should not have terminationGracePeriod - if !reflect.DeepEqual(newPod, podWithoutProbeGracePeriod()) { - t.Errorf("new pod had probe-level terminationGracePeriod: %v", cmp.Diff(newPod, podWithoutProbeGracePeriod())) - } - default: - // new pod should not need to be changed - if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) - } - } - }) - } - } - } -} - func TestValidatePodDeletionCostOption(t *testing.T) { testCases := []struct { name string diff --git a/pkg/apis/core/validation/validation_test.go b/pkg/apis/core/validation/validation_test.go index 5caae4e1354..8f9b2e54a57 100644 --- a/pkg/apis/core/validation/validation_test.go +++ b/pkg/apis/core/validation/validation_test.go @@ -6554,8 +6554,6 @@ func TestValidateProbe(t *testing.T) { } func Test_validateProbe(t *testing.T) { - defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ProbeTerminationGracePeriod, true)() - fldPath := field.NewPath("test") type args struct { probe *core.Probe diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index 92f1abffab1..21426df3e25 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -627,9 +627,10 @@ const ( // Enable users to specify when a Pod is ready for scheduling. PodSchedulingReadiness featuregate.Feature = "PodSchedulingReadiness" - // owner: @ehashman + // owner: @rphillips // alpha: v1.21 // beta: v1.22 + // ga: v1.28 // // Allows user to override pod-level terminationGracePeriod for probes ProbeTerminationGracePeriod featuregate.Feature = "ProbeTerminationGracePeriod" @@ -1021,7 +1022,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS PodSchedulingReadiness: {Default: true, PreRelease: featuregate.Beta}, - ProbeTerminationGracePeriod: {Default: true, PreRelease: featuregate.Beta}, // Default to true in beta 1.25 + ProbeTerminationGracePeriod: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.29 ProcMountType: {Default: false, PreRelease: featuregate.Alpha},