mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
add RetryOnConflict to pod status updates
This commit is contained in:
parent
8ac5d4d6a9
commit
b1f34ea205
@ -22,6 +22,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"k8s.io/client-go/util/retry"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -948,6 +949,10 @@ var _ = SIGDescribe("Pods", func() {
|
|||||||
framework.Logf("Observed event: %+v", event.Object)
|
framework.Logf("Observed event: %+v", event.Object)
|
||||||
return false, nil
|
return false, nil
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
p, _ := f.ClientSet.CoreV1().Pods(testNamespaceName).Get(context.TODO(), testPodName, metav1.GetOptions{})
|
||||||
|
framework.Logf("Pod: %+v", p)
|
||||||
|
}
|
||||||
framework.ExpectNoError(err, "failed to see Pod %v in namespace %v running", testPod.ObjectMeta.Name, testNamespaceName)
|
framework.ExpectNoError(err, "failed to see Pod %v in namespace %v running", testPod.ObjectMeta.Name, testNamespaceName)
|
||||||
|
|
||||||
ginkgo.By("patching the Pod with a new Label and updated data")
|
ginkgo.By("patching the Pod with a new Label and updated data")
|
||||||
@ -989,32 +994,35 @@ var _ = SIGDescribe("Pods", func() {
|
|||||||
framework.ExpectEqual(pod.ObjectMeta.Labels["test-pod"], "patched", "failed to patch Pod - missing label")
|
framework.ExpectEqual(pod.ObjectMeta.Labels["test-pod"], "patched", "failed to patch Pod - missing label")
|
||||||
framework.ExpectEqual(pod.Spec.Containers[0].Image, testPodImage2, "failed to patch Pod - wrong image")
|
framework.ExpectEqual(pod.Spec.Containers[0].Image, testPodImage2, "failed to patch Pod - wrong image")
|
||||||
|
|
||||||
ginkgo.By("getting the PodStatus")
|
|
||||||
podStatusUnstructured, err := dc.Resource(podResource).Namespace(testNamespaceName).Get(context.TODO(), testPodName, metav1.GetOptions{}, "status")
|
|
||||||
framework.ExpectNoError(err, "failed to fetch PodStatus of Pod %s in namespace %s", testPodName, testNamespaceName)
|
|
||||||
podStatusBytes, err := json.Marshal(podStatusUnstructured)
|
|
||||||
framework.ExpectNoError(err, "failed to marshal unstructured response")
|
|
||||||
var podStatus v1.Pod
|
|
||||||
err = json.Unmarshal(podStatusBytes, &podStatus)
|
|
||||||
framework.ExpectNoError(err, "failed to unmarshal JSON bytes to a Pod object type")
|
|
||||||
|
|
||||||
ginkgo.By("replacing the Pod's status Ready condition to False")
|
ginkgo.By("replacing the Pod's status Ready condition to False")
|
||||||
podStatusUpdated := podStatus
|
var podStatusUpdate *v1.Pod
|
||||||
podStatusFieldPatchCount := 0
|
|
||||||
podStatusFieldPatchCountTotal := 2
|
err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
|
||||||
for pos, cond := range podStatusUpdated.Status.Conditions {
|
podStatusUnstructured, err := dc.Resource(podResource).Namespace(testNamespaceName).Get(context.TODO(), testPodName, metav1.GetOptions{}, "status")
|
||||||
if (cond.Type == v1.PodReady && cond.Status == v1.ConditionTrue) || (cond.Type == v1.ContainersReady && cond.Status == v1.ConditionTrue) {
|
framework.ExpectNoError(err, "failed to fetch PodStatus of Pod %s in namespace %s", testPodName, testNamespaceName)
|
||||||
podStatusUpdated.Status.Conditions[pos].Status = v1.ConditionFalse
|
podStatusBytes, err := json.Marshal(podStatusUnstructured)
|
||||||
podStatusFieldPatchCount++
|
framework.ExpectNoError(err, "failed to marshal unstructured response")
|
||||||
|
var podStatus v1.Pod
|
||||||
|
err = json.Unmarshal(podStatusBytes, &podStatus)
|
||||||
|
framework.ExpectNoError(err, "failed to unmarshal JSON bytes to a Pod object type")
|
||||||
|
podStatusUpdated := podStatus
|
||||||
|
podStatusFieldPatchCount := 0
|
||||||
|
podStatusFieldPatchCountTotal := 2
|
||||||
|
for pos, cond := range podStatusUpdated.Status.Conditions {
|
||||||
|
if (cond.Type == v1.PodReady && cond.Status == v1.ConditionTrue) || (cond.Type == v1.ContainersReady && cond.Status == v1.ConditionTrue) {
|
||||||
|
podStatusUpdated.Status.Conditions[pos].Status = v1.ConditionFalse
|
||||||
|
podStatusFieldPatchCount++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
framework.ExpectEqual(podStatusFieldPatchCount, podStatusFieldPatchCountTotal, "failed to patch all relevant Pod conditions")
|
||||||
framework.ExpectEqual(podStatusFieldPatchCount, podStatusFieldPatchCountTotal, "failed to patch all relevant Pod conditions")
|
podStatusUpdate, err = f.ClientSet.CoreV1().Pods(testNamespaceName).UpdateStatus(context.TODO(), &podStatusUpdated, metav1.UpdateOptions{})
|
||||||
podStatusUpdate, err := f.ClientSet.CoreV1().Pods(testNamespaceName).UpdateStatus(context.TODO(), &podStatusUpdated, metav1.UpdateOptions{})
|
return err
|
||||||
|
})
|
||||||
framework.ExpectNoError(err, "failed to update PodStatus of Pod %s in namespace %s", testPodName, testNamespaceName)
|
framework.ExpectNoError(err, "failed to update PodStatus of Pod %s in namespace %s", testPodName, testNamespaceName)
|
||||||
|
|
||||||
ginkgo.By("check the Pod again to ensure its Ready conditions are False")
|
ginkgo.By("check the Pod again to ensure its Ready conditions are False")
|
||||||
podStatusFieldPatchCount = 0
|
podStatusFieldPatchCount := 0
|
||||||
podStatusFieldPatchCountTotal = 2
|
podStatusFieldPatchCountTotal := 2
|
||||||
for _, cond := range podStatusUpdate.Status.Conditions {
|
for _, cond := range podStatusUpdate.Status.Conditions {
|
||||||
if (cond.Type == v1.PodReady && cond.Status == v1.ConditionFalse) || (cond.Type == v1.ContainersReady && cond.Status == v1.ConditionFalse) {
|
if (cond.Type == v1.PodReady && cond.Status == v1.ConditionFalse) || (cond.Type == v1.ContainersReady && cond.Status == v1.ConditionFalse) {
|
||||||
podStatusFieldPatchCount++
|
podStatusFieldPatchCount++
|
||||||
|
Loading…
Reference in New Issue
Block a user