mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Fix pkg/api/pod/util tests to ensure feature gate is set
Fixing this led to finding a bug in how the TestDropProbeGracePeriod unit tests were written, so this patch also includes a fix for that. Co-Authored-By: Elana Hashman <ehashman@redhat.com>
This commit is contained in:
parent
3a07d96d25
commit
68dadd40d6
@ -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 {
|
||||
@ -1136,16 +1137,19 @@ 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()))
|
||||
}
|
||||
@ -1233,6 +1238,7 @@ func TestDropProbeGracePeriod(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// helper creates a podStatus with list of PodIPs
|
||||
|
Loading…
Reference in New Issue
Block a user