Skip to content

Commit

Permalink
add retry in func UpdateEgressGateway
Browse files Browse the repository at this point in the history
Signed-off-by: bzsuni <[email protected]>
  • Loading branch information
bzsuni committed Aug 1, 2023
1 parent 3324215 commit d2ece79
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
17 changes: 15 additions & 2 deletions test/e2e/common/egressgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,21 @@ func DeleteEgressGateway(f *framework.Framework, gateway *egressv1beta1.EgressGa
return f.DeleteResource(gateway, opts...)
}

func UpdateEgressGateway(f *framework.Framework, gateway *egressv1beta1.EgressGateway, opts ...client.UpdateOption) error {
return f.UpdateResource(gateway, opts...)
func UpdateEgressGateway(f *framework.Framework, gateway *egressv1beta1.EgressGateway, retry int, opts ...client.UpdateOption) error {
eg := new(egressv1beta1.EgressGateway)
for i := 0; i < retry; i++ {
err := GetEgressGateway(f, gateway.Name, eg)
if err != nil {
return err
}
gateway.ResourceVersion = eg.ResourceVersion
err = f.UpdateResource(gateway, opts...)
if err == nil {
return nil
}
time.Sleep(time.Second)
}
return ERR_TIMEOUT
}

// DeleteEgressGatewayIfExists delete egressGateway if its exists
Expand Down
12 changes: 4 additions & 8 deletions test/e2e/egressgateway/egressgateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,40 +178,36 @@ var _ = Describe("Operate egressGateway", Label("egressGateway"), func() {
}
},
Entry("Failed when add invalid `IP` to `Ippools`", Label("G00009"), false, func() error {
Expect(common.GetEgressGateway(f, name, eg)).NotTo(HaveOccurred())
if enableV4 {
eg.Spec.Ippools.IPv4 = append(eg.Spec.Ippools.IPv4, invalidIPv4)
}
if enableV6 {
eg.Spec.Ippools.IPv6 = append(eg.Spec.Ippools.IPv6, invalidIPv6)
}
return common.UpdateEgressGateway(f, eg)
return common.UpdateEgressGateway(f, eg, 3)
}),
Entry("Succeeded when add valid `IP` to `Ippools`", Label("G00012", "G00013"), true, func() error {
Expect(common.GetEgressGateway(f, name, eg)).NotTo(HaveOccurred())
if enableV4 {
eg.Spec.Ippools.IPv4 = append(eg.Spec.Ippools.IPv4, singleIpv4Pool...)
}
if enableV6 {
eg.Spec.Ippools.IPv6 = append(eg.Spec.Ippools.IPv6, singleIpv6Pool...)
}
return common.UpdateEgressGateway(f, eg)
return common.UpdateEgressGateway(f, eg, 3)
}),
Entry("Failed when delete `IP` that being used", Label("G00010"), false, func() error {
Expect(common.GetEgressGateway(f, name, eg)).NotTo(HaveOccurred())
if enableV4 {
eg.Spec.Ippools.IPv4 = tools.RemoveValueFromSlice(eg.Spec.Ippools.IPv4, v4DefaultEip)
}
if enableV6 {
eg.Spec.Ippools.IPv6 = tools.RemoveValueFromSlice(eg.Spec.Ippools.IPv6, v6DefaultEip)
}
return common.UpdateEgressGateway(f, eg)
return common.UpdateEgressGateway(f, eg, 3)
}),
Entry("Failed when add different number of ip to `Ippools.IPv4` and `Ippools.IPv6`", Label("G00011"), false, func() error {
Expect(common.GetEgressGateway(f, name, eg)).NotTo(HaveOccurred())
if enableV4 && enableV6 {
eg.Spec.Ippools.IPv4 = append(eg.Spec.Ippools.IPv4, singleIpv4Pool...)
return common.UpdateEgressGateway(f, eg)
return common.UpdateEgressGateway(f, eg, 3)
}
return ErrNotNeed
}),
Expand Down

0 comments on commit d2ece79

Please sign in to comment.