Skip to content

Commit 6e86719

Browse files
committed
e2e: Should ignore conflict when updating resources
Signed-off-by: zhzhuang-zju <[email protected]>
1 parent d15f6a0 commit 6e86719

File tree

6 files changed

+58
-38
lines changed

6 files changed

+58
-38
lines changed

test/e2e/framework/clusterpropagationpolicy.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,29 @@ func PatchClusterPropagationPolicy(client karmada.Interface, name string, patch
6161
// UpdateClusterPropagationPolicyWithSpec update PropagationSpec with karmada client.
6262
func UpdateClusterPropagationPolicyWithSpec(client karmada.Interface, name string, policySpec policyv1alpha1.PropagationSpec) {
6363
ginkgo.By(fmt.Sprintf("Updating ClusterPropagationPolicy(%s) spec", name), func() {
64-
newPolicy, err := client.PolicyV1alpha1().ClusterPropagationPolicies().Get(context.TODO(), name, metav1.GetOptions{})
65-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
66-
67-
newPolicy.Spec = policySpec
68-
_, err = client.PolicyV1alpha1().ClusterPropagationPolicies().Update(context.TODO(), newPolicy, metav1.UpdateOptions{})
69-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
64+
gomega.Eventually(func() error {
65+
newPolicy, err := client.PolicyV1alpha1().ClusterPropagationPolicies().Get(context.TODO(), name, metav1.GetOptions{})
66+
if err != nil {
67+
return err
68+
}
69+
newPolicy.Spec = policySpec
70+
_, err = client.PolicyV1alpha1().ClusterPropagationPolicies().Update(context.TODO(), newPolicy, metav1.UpdateOptions{})
71+
return err
72+
}, PollTimeout, PollInterval).ShouldNot(gomega.HaveOccurred())
7073
})
7174
}
7275

7376
// UpdateClusterPropagationPolicy update ClusterPropagationPolicy resourceSelectors with karmada client.
7477
func UpdateClusterPropagationPolicy(client karmada.Interface, name string, resourceSelectors []policyv1alpha1.ResourceSelector) {
7578
ginkgo.By(fmt.Sprintf("Updating ClusterPropagationPolicy(%s)", name), func() {
76-
newPolicy, err := client.PolicyV1alpha1().ClusterPropagationPolicies().Get(context.TODO(), name, metav1.GetOptions{})
77-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
78-
79-
newPolicy.Spec.ResourceSelectors = resourceSelectors
80-
_, err = client.PolicyV1alpha1().ClusterPropagationPolicies().Update(context.TODO(), newPolicy, metav1.UpdateOptions{})
81-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
79+
gomega.Eventually(func() error {
80+
newPolicy, err := client.PolicyV1alpha1().ClusterPropagationPolicies().Get(context.TODO(), name, metav1.GetOptions{})
81+
if err != nil {
82+
return err
83+
}
84+
newPolicy.Spec.ResourceSelectors = resourceSelectors
85+
_, err = client.PolicyV1alpha1().ClusterPropagationPolicies().Update(context.TODO(), newPolicy, metav1.UpdateOptions{})
86+
return err
87+
}, PollTimeout, PollInterval).ShouldNot(gomega.HaveOccurred())
8288
})
8389
}

test/e2e/framework/cronfederatedhpa.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ func RemoveCronFederatedHPA(client karmada.Interface, namespace, name string) {
4747
// UpdateCronFederatedHPAWithRule update CronFederatedHPA with karmada client.
4848
func UpdateCronFederatedHPAWithRule(client karmada.Interface, namespace, name string, rule []autoscalingv1alpha1.CronFederatedHPARule) {
4949
ginkgo.By(fmt.Sprintf("Updating CronFederatedHPA(%s/%s)", namespace, name), func() {
50-
newCronFederatedHPA, err := client.AutoscalingV1alpha1().CronFederatedHPAs(namespace).Get(context.TODO(), name, metav1.GetOptions{})
51-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
52-
53-
newCronFederatedHPA.Spec.Rules = rule
54-
_, err = client.AutoscalingV1alpha1().CronFederatedHPAs(namespace).Update(context.TODO(), newCronFederatedHPA, metav1.UpdateOptions{})
55-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
50+
gomega.Eventually(func() error {
51+
newCronFederatedHPA, err := client.AutoscalingV1alpha1().CronFederatedHPAs(namespace).Get(context.TODO(), name, metav1.GetOptions{})
52+
if err != nil {
53+
return err
54+
}
55+
newCronFederatedHPA.Spec.Rules = rule
56+
_, err = client.AutoscalingV1alpha1().CronFederatedHPAs(namespace).Update(context.TODO(), newCronFederatedHPA, metav1.UpdateOptions{})
57+
return err
58+
}, PollTimeout, PollInterval).ShouldNot(gomega.HaveOccurred())
5659
})
5760
}

test/e2e/framework/hpa.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ func RemoveHPA(client kubernetes.Interface, namespace, name string) {
4646
// UpdateHPAWithMinReplicas update HPA with replicas.
4747
func UpdateHPAWithMinReplicas(client kubernetes.Interface, namespace, name string, minReplicas int32) {
4848
ginkgo.By(fmt.Sprintf("Updating HPA(%s/%s)", namespace, name), func() {
49-
newHPA, err := client.AutoscalingV2().HorizontalPodAutoscalers(namespace).Get(context.TODO(), name, metav1.GetOptions{})
50-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
51-
52-
newHPA.Spec.MinReplicas = &minReplicas
53-
_, err = client.AutoscalingV2().HorizontalPodAutoscalers(namespace).Update(context.TODO(), newHPA, metav1.UpdateOptions{})
54-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
49+
gomega.Eventually(func() error {
50+
newHPA, err := client.AutoscalingV2().HorizontalPodAutoscalers(namespace).Get(context.TODO(), name, metav1.GetOptions{})
51+
if err != nil {
52+
return err
53+
}
54+
newHPA.Spec.MinReplicas = &minReplicas
55+
_, err = client.AutoscalingV2().HorizontalPodAutoscalers(namespace).Update(context.TODO(), newHPA, metav1.UpdateOptions{})
56+
return err
57+
}, PollTimeout, PollInterval).ShouldNot(gomega.HaveOccurred())
5558
})
5659
}

test/e2e/framework/propagationpolicy.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,15 @@ func PatchPropagationPolicy(client karmada.Interface, namespace, name string, pa
7878
// UpdatePropagationPolicyWithSpec update PropagationSpec with karmada client.
7979
func UpdatePropagationPolicyWithSpec(client karmada.Interface, namespace, name string, policySpec policyv1alpha1.PropagationSpec) {
8080
ginkgo.By(fmt.Sprintf("Updating PropagationPolicy(%s/%s) spec", namespace, name), func() {
81-
newPolicy, err := client.PolicyV1alpha1().PropagationPolicies(namespace).Get(context.TODO(), name, metav1.GetOptions{})
82-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
83-
84-
newPolicy.Spec = policySpec
85-
_, err = client.PolicyV1alpha1().PropagationPolicies(newPolicy.Namespace).Update(context.TODO(), newPolicy, metav1.UpdateOptions{})
86-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
81+
gomega.Eventually(func() error {
82+
newPolicy, err := client.PolicyV1alpha1().PropagationPolicies(namespace).Get(context.TODO(), name, metav1.GetOptions{})
83+
if err != nil {
84+
return err
85+
}
86+
newPolicy.Spec = policySpec
87+
_, err = client.PolicyV1alpha1().PropagationPolicies(newPolicy.Namespace).Update(context.TODO(), newPolicy, metav1.UpdateOptions{})
88+
return err
89+
}, PollTimeout, PollInterval).ShouldNot(gomega.HaveOccurred())
8790
})
8891
}
8992

test/e2e/framework/resource/operator/karmada.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,15 @@ func CreateKarmadaInstance(operatorClient operator.Interface, karmada *operatorv
6767
// UpdateKarmadaInstanceWithSpec updates karmada instance with spec.
6868
func UpdateKarmadaInstanceWithSpec(client operator.Interface, namespace, name string, karmadaSpec operatorv1alpha1.KarmadaSpec) {
6969
ginkgo.By(fmt.Sprintf("Updating Karmada(%s/%s) spec", namespace, name), func() {
70-
karmada, err := client.OperatorV1alpha1().Karmadas(namespace).Get(context.TODO(), name, metav1.GetOptions{})
71-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
72-
73-
karmada.Spec = karmadaSpec
74-
_, err = client.OperatorV1alpha1().Karmadas(namespace).Update(context.TODO(), karmada, metav1.UpdateOptions{})
75-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
70+
gomega.Eventually(func() error {
71+
karmada, err := client.OperatorV1alpha1().Karmadas(namespace).Get(context.TODO(), name, metav1.GetOptions{})
72+
if err != nil {
73+
return err
74+
}
75+
karmada.Spec = karmadaSpec
76+
_, err = client.OperatorV1alpha1().Karmadas(namespace).Update(context.TODO(), karmada, metav1.UpdateOptions{})
77+
return err
78+
}, framework.PollTimeout, framework.PollInterval).ShouldNot(gomega.HaveOccurred())
7679
})
7780
}
7881

test/e2e/framework/resourceregistry.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ func RemoveResourceRegistry(client karmada.Interface, name string) {
4747
// UpdateResourceRegistry patch ResourceRegistry with karmada client.
4848
func UpdateResourceRegistry(client karmada.Interface, rr *searchv1alpha1.ResourceRegistry) {
4949
ginkgo.By(fmt.Sprintf("Update ResourceRegistry(%s)", rr.Name), func() {
50-
_, err := client.SearchV1alpha1().ResourceRegistries().Update(context.TODO(), rr, metav1.UpdateOptions{})
51-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
50+
gomega.Eventually(func() error {
51+
_, err := client.SearchV1alpha1().ResourceRegistries().Update(context.TODO(), rr, metav1.UpdateOptions{})
52+
return err
53+
}, PollTimeout, PollInterval).ShouldNot(gomega.HaveOccurred())
5254
})
5355
}

0 commit comments

Comments
 (0)