operator_test: wrap Update() with RetryOnConflict() to prevent flakiness
@@ -54,6 +54,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/rand"
+ "k8s.io/client-go/util/retry"
aggregatorclient "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"
"k8s.io/utils/pointer"
@@ -1125,7 +1126,10 @@ spec:
},
}
+ err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
vc, err = virtClient.AppsV1().Deployments(originalKv.Namespace).Update(context.Background(), vc, metav1.UpdateOptions{})
+ return err
+ })
Expect(err).ToNot(HaveOccurred())
Expect(vc.Spec.Template.Spec.Containers[0].Env[0].Name).To(Equal(envVarDeploymentKeyToUpdate))
},
@@ -1156,7 +1160,10 @@ spec:
vmcrd.Spec.Names.ShortNames = append(vmcrd.Spec.Names.ShortNames, shortNameAdded)
+ err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
vmcrd, err = virtClient.ExtensionsClient().ApiextensionsV1().CustomResourceDefinitions().Update(context.Background(), vmcrd, metav1.UpdateOptions{})
+ return err
+ })
Expect(err).ToNot(HaveOccurred())
Expect(vmcrd.Spec.Names.ShortNames).To(ContainElement(shortNameAdded))
},
@@ -1188,7 +1195,10 @@ spec:
"kubevirt.io": "dne",
}
+ err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
pdb, err = virtClient.PolicyV1beta1().PodDisruptionBudgets(originalKv.Namespace).Update(context.Background(), pdb, metav1.UpdateOptions{})
+ return err
+ })
Expect(err).ToNot(HaveOccurred())
Expect(pdb.Spec.Selector.MatchLabels["kubevirt.io"]).To(Equal("dne"))
},
@@ -1217,7 +1227,10 @@ spec:
},
}
+ err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
vc, err = virtClient.AppsV1().DaemonSets(originalKv.Namespace).Update(context.Background(), vc, metav1.UpdateOptions{})
+ return err
+ })
Expect(err).ToNot(HaveOccurred())
Expect(vc.Spec.Template.Spec.Containers[0].Env[0].Name).To(Equal(envVarDeploymentKeyToUpdate))
},
