diff --git a/test/e2e/common/egw.go b/test/e2e/common/egw.go index c0890df2f..e74efc864 100644 --- a/test/e2e/common/egw.go +++ b/test/e2e/common/egw.go @@ -11,6 +11,7 @@ import ( "github.com/google/uuid" "k8s.io/apimachinery/pkg/api/errors" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" @@ -251,3 +252,26 @@ func CheckEgressGatewayStatusSynced(ctx context.Context, cli client.Client, egw } } } + +func DeleteEgressGateway(ctx context.Context, cli client.Client, egw *egressv1.EgressGateway, timeout time.Duration) error { + ctx, cancel := context.WithTimeout(ctx, timeout) + defer cancel() + + err := DeleteObj(ctx, cli, egw) + if err != nil { + return err + } + + for { + select { + case <-ctx.Done(): + return e2eerr.ErrTimeout + default: + err = cli.Get(ctx, types.NamespacedName{Name: egw.Name}, egw) + if apierrors.IsNotFound(err) { + return nil + } + time.Sleep(time.Second / 2) + } + } +} diff --git a/test/e2e/egressgateway/default_egressgateway_test.go b/test/e2e/egressgateway/default_egressgateway_test.go index 8cf6333af..56049147e 100644 --- a/test/e2e/egressgateway/default_egressgateway_test.go +++ b/test/e2e/egressgateway/default_egressgateway_test.go @@ -88,7 +88,7 @@ var _ = Describe("Test default egress gateway", Label("DefaultEgressGateway", "G err = common.DeleteObj(ctx, cli, nsDefaultEgw) Expect(err).NotTo(HaveOccurred()) - err = common.DeleteObj(ctx, cli, clusterDefaultEgw) + err = common.DeleteEgressGateway(ctx, cli, clusterDefaultEgw, time.Second*3) Expect(err).NotTo(HaveOccurred()) ns := &corev1.Namespace{}