Merge pull request #103420 from raisaat/pods-api-test-fix

Fix pkg/api/pod/util tests to ensure feature gate is set
This commit is contained in:
Kubernetes Prow Robot 2021-07-07 10:43:53 -07:00 committed by GitHub
commit 896cf744cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1090,7 +1090,7 @@ func TestDropSubPathExpr(t *testing.T) {
},
}
enabled := true
for _, enabled := range []bool{true, false} {
for _, oldPodInfo := range podInfo {
for _, newPodInfo := range podInfo {
oldPodHasSubpaths, oldPod := oldPodInfo.hasSubpaths, oldPodInfo.pod()
@ -1100,6 +1100,7 @@ func TestDropSubPathExpr(t *testing.T) {
}
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.VolumeSubpath, enabled)()
var oldPodSpec *api.PodSpec
if oldPod != nil {
@ -1137,15 +1138,18 @@ func TestDropSubPathExpr(t *testing.T) {
}
}
}
}
func TestDropProbeGracePeriod(t *testing.T) {
gracePeriod := int64(10)
probe := api.Probe{TerminationGracePeriodSeconds: &gracePeriod}
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: &probe, StartupProbe: &probe}},
Containers: []api.Container{{Name: "container1", Image: "testimage", LivenessProbe: &livenessProbe, StartupProbe: &startupProbe}},
},
}
}
@ -1187,7 +1191,7 @@ func TestDropProbeGracePeriod(t *testing.T) {
},
}
enabled := true
for _, enabled := range []bool{true, false} {
for _, oldPodInfo := range podInfo {
for _, newPodInfo := range podInfo {
oldPodHasGracePeriod, oldPod := oldPodInfo.hasGracePeriod, oldPodInfo.pod()
@ -1197,6 +1201,7 @@ func TestDropProbeGracePeriod(t *testing.T) {
}
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 {
@ -1211,7 +1216,7 @@ func TestDropProbeGracePeriod(t *testing.T) {
switch {
case enabled || oldPodHasGracePeriod:
// new pod should not be changed if the feature is enabled, or if the old pod had subpaths
// 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()))
}
@ -1220,7 +1225,7 @@ func TestDropProbeGracePeriod(t *testing.T) {
if reflect.DeepEqual(newPod, newPodInfo.pod()) {
t.Errorf("new pod was not changed")
}
// new pod should not have subpaths
// new pod should not have terminationGracePeriod
if !reflect.DeepEqual(newPod, podWithoutProbeGracePeriod()) {
t.Errorf("new pod had probe-level terminationGracePeriod: %v", cmp.Diff(newPod, podWithoutProbeGracePeriod()))
}
@ -1234,6 +1239,7 @@ func TestDropProbeGracePeriod(t *testing.T) {
}
}
}
}
// helper creates a podStatus with list of PodIPs
func makePodStatus(podIPs []api.PodIP) *api.PodStatus {