mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
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:
commit
896cf744cb
@ -1090,7 +1090,7 @@ func TestDropSubPathExpr(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
enabled := true
|
for _, enabled := range []bool{true, false} {
|
||||||
for _, oldPodInfo := range podInfo {
|
for _, oldPodInfo := range podInfo {
|
||||||
for _, newPodInfo := range podInfo {
|
for _, newPodInfo := range podInfo {
|
||||||
oldPodHasSubpaths, oldPod := oldPodInfo.hasSubpaths, oldPodInfo.pod()
|
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) {
|
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
|
var oldPodSpec *api.PodSpec
|
||||||
if oldPod != nil {
|
if oldPod != nil {
|
||||||
@ -1137,15 +1138,18 @@ func TestDropSubPathExpr(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDropProbeGracePeriod(t *testing.T) {
|
func TestDropProbeGracePeriod(t *testing.T) {
|
||||||
gracePeriod := int64(10)
|
|
||||||
probe := api.Probe{TerminationGracePeriodSeconds: &gracePeriod}
|
|
||||||
podWithProbeGracePeriod := func() *api.Pod {
|
podWithProbeGracePeriod := func() *api.Pod {
|
||||||
|
livenessGracePeriod := int64(10)
|
||||||
|
livenessProbe := api.Probe{TerminationGracePeriodSeconds: &livenessGracePeriod}
|
||||||
|
startupGracePeriod := int64(10)
|
||||||
|
startupProbe := api.Probe{TerminationGracePeriodSeconds: &startupGracePeriod}
|
||||||
return &api.Pod{
|
return &api.Pod{
|
||||||
Spec: api.PodSpec{
|
Spec: api.PodSpec{
|
||||||
RestartPolicy: api.RestartPolicyNever,
|
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 _, oldPodInfo := range podInfo {
|
||||||
for _, newPodInfo := range podInfo {
|
for _, newPodInfo := range podInfo {
|
||||||
oldPodHasGracePeriod, oldPod := oldPodInfo.hasGracePeriod, oldPodInfo.pod()
|
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) {
|
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
|
var oldPodSpec *api.PodSpec
|
||||||
if oldPod != nil {
|
if oldPod != nil {
|
||||||
@ -1211,7 +1216,7 @@ func TestDropProbeGracePeriod(t *testing.T) {
|
|||||||
|
|
||||||
switch {
|
switch {
|
||||||
case enabled || oldPodHasGracePeriod:
|
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()) {
|
if !reflect.DeepEqual(newPod, newPodInfo.pod()) {
|
||||||
t.Errorf("new pod changed: %v", cmp.Diff(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()) {
|
if reflect.DeepEqual(newPod, newPodInfo.pod()) {
|
||||||
t.Errorf("new pod was not changed")
|
t.Errorf("new pod was not changed")
|
||||||
}
|
}
|
||||||
// new pod should not have subpaths
|
// new pod should not have terminationGracePeriod
|
||||||
if !reflect.DeepEqual(newPod, podWithoutProbeGracePeriod()) {
|
if !reflect.DeepEqual(newPod, podWithoutProbeGracePeriod()) {
|
||||||
t.Errorf("new pod had probe-level terminationGracePeriod: %v", cmp.Diff(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
|
// helper creates a podStatus with list of PodIPs
|
||||||
func makePodStatus(podIPs []api.PodIP) *api.PodStatus {
|
func makePodStatus(podIPs []api.PodIP) *api.PodStatus {
|
||||||
|
Loading…
Reference in New Issue
Block a user