Skip to content

Commit 23848b3

Browse files
authored
Merge pull request #6453 from zhzhuang-zju/flakey
flakey test: Retry on failed deployment update
2 parents 0714abb + 7b54c00 commit 23848b3

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

test/e2e/framework/deployment.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package framework
1919
import (
2020
"context"
2121
"fmt"
22+
"reflect"
2223

2324
"github.com/onsi/ginkgo/v2"
2425
"github.com/onsi/gomega"
@@ -53,15 +54,23 @@ func UpdateDeploymentPaused(client kubernetes.Interface, deployment *appsv1.Depl
5354
})
5455
}
5556

56-
// UpdateDeploymentWithSpec update deployment with the given spec.
57-
func UpdateDeploymentWithSpec(client kubernetes.Interface, namespace, name string, spec appsv1.DeploymentSpec) {
57+
// UpdateDeploymentWith update deployment with the given mutate function.
58+
func UpdateDeploymentWith(client kubernetes.Interface, namespace, name string, mutateFunc func(deploy *appsv1.Deployment)) {
5859
ginkgo.By(fmt.Sprintf("Update Deployment(%s/%s)", namespace, name), func() {
59-
newDeployment, err := client.AppsV1().Deployments(namespace).Get(context.TODO(), name, metav1.GetOptions{})
60-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
60+
gomega.Eventually(func() error {
61+
deploy, err := client.AppsV1().Deployments(namespace).Get(context.TODO(), name, metav1.GetOptions{})
62+
if err != nil {
63+
return err
64+
}
6165

62-
newDeployment.Spec = spec
63-
_, err = client.AppsV1().Deployments(namespace).Update(context.TODO(), newDeployment, metav1.UpdateOptions{})
64-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
66+
deployCopy := deploy.DeepCopy()
67+
mutateFunc(deployCopy)
68+
if reflect.DeepEqual(deploy, deployCopy) {
69+
return nil
70+
}
71+
_, err = client.AppsV1().Deployments(namespace).Update(context.TODO(), deployCopy, metav1.UpdateOptions{})
72+
return err
73+
}, PollTimeout, PollInterval).ShouldNot(gomega.HaveOccurred())
6574
})
6675
}
6776

test/e2e/suites/base/federatedresourcequota_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,13 @@ var _ = ginkgo.Describe("FederatedResourceQuota enforcement testing", func() {
350350

351351
ginkgo.It("Intercept update requests for requirements if they exceed the quota.", func() {
352352
ginkgo.By("update the requirements of the deployment", func() {
353-
newSpec := deployment.Spec.DeepCopy()
354-
newSpec.Template.Spec.Containers[0].Resources.Requests = corev1.ResourceList{
355-
"cpu": resource.MustParse("20m"),
353+
mutateFunc := func(deploy *appsv1.Deployment) {
354+
deploy.Spec.Template.Spec.Containers[0].Resources.Requests = corev1.ResourceList{
355+
"cpu": resource.MustParse("20m"),
356+
}
356357
}
357358

358-
framework.UpdateDeploymentWithSpec(kubeClient, deploymentNamespace, deploymentName, *newSpec)
359+
framework.UpdateDeploymentWith(kubeClient, deploymentNamespace, deploymentName, mutateFunc)
359360
})
360361

361362
ginkgo.By("The quota has been exceeded, so the update request for the requirements in resourcebinding will be intercepted.", func() {

0 commit comments

Comments
 (0)