mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 03:33:56 +00:00
Merge pull request #114307 from rphillips/promote_probe_termination_grace_period
ProbeTerminationGracePeriod promote to GA
This commit is contained in:
commit
a9e40bd7c6
@ -462,7 +462,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
|
// 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 {
|
VisitContainers(podSpec, AllContainers, func(c *api.Container, containerType ContainerType) bool {
|
||||||
if c.LivenessProbe != nil {
|
if c.LivenessProbe != nil {
|
||||||
|
@ -949,107 +949,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) {
|
func TestValidatePodDeletionCostOption(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -6522,8 +6522,6 @@ func TestValidateProbe(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_validateProbe(t *testing.T) {
|
func Test_validateProbe(t *testing.T) {
|
||||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ProbeTerminationGracePeriod, true)()
|
|
||||||
|
|
||||||
fldPath := field.NewPath("test")
|
fldPath := field.NewPath("test")
|
||||||
type args struct {
|
type args struct {
|
||||||
probe *core.Probe
|
probe *core.Probe
|
||||||
|
@ -618,9 +618,10 @@ const (
|
|||||||
// Enable users to specify when a Pod is ready for scheduling.
|
// Enable users to specify when a Pod is ready for scheduling.
|
||||||
PodSchedulingReadiness featuregate.Feature = "PodSchedulingReadiness"
|
PodSchedulingReadiness featuregate.Feature = "PodSchedulingReadiness"
|
||||||
|
|
||||||
// owner: @ehashman
|
// owner: @rphillips
|
||||||
// alpha: v1.21
|
// alpha: v1.21
|
||||||
// beta: v1.22
|
// beta: v1.22
|
||||||
|
// ga: v1.28
|
||||||
//
|
//
|
||||||
// Allows user to override pod-level terminationGracePeriod for probes
|
// Allows user to override pod-level terminationGracePeriod for probes
|
||||||
ProbeTerminationGracePeriod featuregate.Feature = "ProbeTerminationGracePeriod"
|
ProbeTerminationGracePeriod featuregate.Feature = "ProbeTerminationGracePeriod"
|
||||||
@ -1022,7 +1023,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS
|
|||||||
|
|
||||||
PodSchedulingReadiness: {Default: true, PreRelease: featuregate.Beta},
|
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},
|
ProcMountType: {Default: false, PreRelease: featuregate.Alpha},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user