Merge pull request #114307 from rphillips/promote_probe_termination_grace_period

ProbeTerminationGracePeriod promote to GA
This commit is contained in:
Kubernetes Prow Robot
2023-07-13 13:41:38 -07:00
committed by GitHub
4 changed files with 4 additions and 106 deletions

View File

@@ -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) {
testCases := []struct {
name string