mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
deflake restart count assertions in in-place resize tests (#131055)
This commit is contained in:
parent
047e4c8e56
commit
83bb5d5705
@ -1200,13 +1200,14 @@ func doPodResizeTests() {
|
|||||||
patchedPod, pErr = f.ClientSet.CoreV1().Pods(newPod.Namespace).Patch(ctx, newPod.Name,
|
patchedPod, pErr = f.ClientSet.CoreV1().Pods(newPod.Namespace).Patch(ctx, newPod.Name,
|
||||||
types.StrategicMergePatchType, []byte(patchString), metav1.PatchOptions{}, "resize")
|
types.StrategicMergePatchType, []byte(patchString), metav1.PatchOptions{}, "resize")
|
||||||
framework.ExpectNoError(pErr, fmt.Sprintf("failed to patch pod for %s", opStr))
|
framework.ExpectNoError(pErr, fmt.Sprintf("failed to patch pod for %s", opStr))
|
||||||
|
expected := e2epod.UpdateExpectedContainerRestarts(ctx, patchedPod, expectedContainers)
|
||||||
|
|
||||||
ginkgo.By(fmt.Sprintf("verifying pod patched for %s", opStr))
|
ginkgo.By(fmt.Sprintf("verifying pod patched for %s", opStr))
|
||||||
e2epod.VerifyPodResources(patchedPod, expectedContainers)
|
e2epod.VerifyPodResources(patchedPod, expected)
|
||||||
|
|
||||||
ginkgo.By(fmt.Sprintf("waiting for %s to be actuated", opStr))
|
ginkgo.By(fmt.Sprintf("waiting for %s to be actuated", opStr))
|
||||||
resizedPod := e2epod.WaitForPodResizeActuation(ctx, f, podClient, newPod, expectedContainers)
|
resizedPod := e2epod.WaitForPodResizeActuation(ctx, f, podClient, newPod, expected)
|
||||||
e2epod.ExpectPodResized(ctx, f, resizedPod, expectedContainers)
|
e2epod.ExpectPodResized(ctx, f, resizedPod, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
patchAndVerify(tc.patchString, tc.expected, "resize")
|
patchAndVerify(tc.patchString, tc.expected, "resize")
|
||||||
@ -1219,7 +1220,7 @@ func doPodResizeTests() {
|
|||||||
gomega.Expect(c.Name).To(gomega.Equal(tc.expected[i].Name),
|
gomega.Expect(c.Name).To(gomega.Equal(tc.expected[i].Name),
|
||||||
"test case containers & expectations should be in the same order")
|
"test case containers & expectations should be in the same order")
|
||||||
// Resizes that trigger a restart should trigger a second restart when rolling back.
|
// Resizes that trigger a restart should trigger a second restart when rolling back.
|
||||||
rollbackContainers[i].RestartCount = tc.expected[i].RestartCount * 2
|
rollbackContainers[i].RestartCount = tc.expected[i].RestartCount
|
||||||
}
|
}
|
||||||
|
|
||||||
rbPatchStr, err := e2epod.ResizeContainerPatch(tc.containers)
|
rbPatchStr, err := e2epod.ResizeContainerPatch(tc.containers)
|
||||||
|
@ -505,6 +505,24 @@ func ResizeContainerPatch(containers []ResizableContainerInfo) (string, error) {
|
|||||||
return string(patchBytes), nil
|
return string(patchBytes), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateExpectedContainerRestarts updates the RestartCounts in expectedContainers by
|
||||||
|
// adding them to the existing RestartCounts in the containerStatuses of the provided pod.
|
||||||
|
// This reduces the flakiness of the RestartCount assertions by grabbing the current
|
||||||
|
// restart count right before the resize operation, and verify the expected increment (0 or 1)
|
||||||
|
// rather than the absolute count.
|
||||||
|
func UpdateExpectedContainerRestarts(ctx context.Context, pod *v1.Pod, expectedContainers []ResizableContainerInfo) []ResizableContainerInfo {
|
||||||
|
initialRestarts := make(map[string]int32)
|
||||||
|
newExpectedContainers := []ResizableContainerInfo{}
|
||||||
|
for _, ctr := range pod.Status.ContainerStatuses {
|
||||||
|
initialRestarts[ctr.Name] = ctr.RestartCount
|
||||||
|
}
|
||||||
|
for i, ctr := range expectedContainers {
|
||||||
|
newExpectedContainers = append(newExpectedContainers, expectedContainers[i])
|
||||||
|
newExpectedContainers[i].RestartCount += initialRestarts[ctr.Name]
|
||||||
|
}
|
||||||
|
return newExpectedContainers
|
||||||
|
}
|
||||||
|
|
||||||
func formatErrors(err error) error {
|
func formatErrors(err error) error {
|
||||||
// Put each error on a new line for readability.
|
// Put each error on a new line for readability.
|
||||||
var agg utilerrors.Aggregate
|
var agg utilerrors.Aggregate
|
||||||
|
@ -155,6 +155,7 @@ func doPodResizeAdmissionPluginsTests() {
|
|||||||
patchedPod, pErr := f.ClientSet.CoreV1().Pods(newPods[0].Namespace).Patch(ctx, newPods[0].Name,
|
patchedPod, pErr := f.ClientSet.CoreV1().Pods(newPods[0].Namespace).Patch(ctx, newPods[0].Name,
|
||||||
types.StrategicMergePatchType, []byte(patchString), metav1.PatchOptions{}, "resize")
|
types.StrategicMergePatchType, []byte(patchString), metav1.PatchOptions{}, "resize")
|
||||||
framework.ExpectNoError(pErr, "failed to patch pod for resize")
|
framework.ExpectNoError(pErr, "failed to patch pod for resize")
|
||||||
|
expected = e2epod.UpdateExpectedContainerRestarts(ctx, patchedPod, expected)
|
||||||
|
|
||||||
ginkgo.By("verifying pod patched for resize within resource quota")
|
ginkgo.By("verifying pod patched for resize within resource quota")
|
||||||
e2epod.VerifyPodResources(patchedPod, expected)
|
e2epod.VerifyPodResources(patchedPod, expected)
|
||||||
@ -405,8 +406,9 @@ func doPodResizeSchedulerTests(f *framework.Framework) {
|
|||||||
ginkgo.By(fmt.Sprintf("TEST3: Verify pod '%s' is resized successfully after pod deletion '%s' and '%s", testPod1.Name, testPod2.Name, testPod3.Name))
|
ginkgo.By(fmt.Sprintf("TEST3: Verify pod '%s' is resized successfully after pod deletion '%s' and '%s", testPod1.Name, testPod2.Name, testPod3.Name))
|
||||||
expected := []e2epod.ResizableContainerInfo{
|
expected := []e2epod.ResizableContainerInfo{
|
||||||
{
|
{
|
||||||
Name: "c1",
|
Name: "c1",
|
||||||
Resources: &e2epod.ContainerResources{CPUReq: testPod1CPUQuantity.String(), CPULim: testPod1CPUQuantity.String()},
|
Resources: &e2epod.ContainerResources{CPUReq: testPod1CPUQuantity.String(), CPULim: testPod1CPUQuantity.String()},
|
||||||
|
RestartCount: testPod1.Status.ContainerStatuses[0].RestartCount,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
resizedPod := e2epod.WaitForPodResizeActuation(ctx, f, podClient, testPod1, expected)
|
resizedPod := e2epod.WaitForPodResizeActuation(ctx, f, podClient, testPod1, expected)
|
||||||
|
Loading…
Reference in New Issue
Block a user