Skip to content

Commit

Permalink
Fix the default egress gateway problem
Browse files Browse the repository at this point in the history
Signed-off-by: bzsuni <[email protected]>
  • Loading branch information
bzsuni committed Dec 12, 2023
1 parent ee2aa76 commit 99c2a07
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/auto-pr-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ jobs:
echo "RUN_UNITEST_ENABLED=false" >> $GITHUB_ENV
else
# call by auto-nightly-ci, the event is schedule or its workflow_dispatch
if ${{ github.event_name != 'workflow_dispatch' }}; then
echo "RUN_TAG=main" >> $GITHUB_ENV
fi
# use main sha for ci image tag
echo "trigger by workflow_call"
echo "RUN_TAG=main" >> $GITHUB_ENV
echo "RUN_E2E_LABEL=" >> $GITHUB_ENV
echo "RUN_E2E_ENABLED=true" >> $GITHUB_ENV
echo "RUN_UNITEST_ENABLED=true" >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ E2E_KIND_IPV6_POD_CIDR = fd40::/48

#====== calico
CALICO_VERSION ?=
MAMUAL_CALICO_VERSION ?= v3.26.4
MANUAL_CALICO_VERSION ?= v3.26.4
INSTALL_TIME_OUT = 300s
ifeq ($(E2E_CHINA_IMAGE_REGISTRY),true)
CALICO_REGISTRY ?= docker.m.daocloud.io
Expand Down
1 change: 1 addition & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ install_calico: KIND_CLUSTER_NAME ?= $(E2E_KIND_CLUSTER_NAME)
install_calico:
echo "install calico"
export CALICO_VERSION=$(CALICO_VERSION); \
export MANUAL_CALICO_VERSION=$(MANUAL_CALICO_VERSION); \
export HTTP_PROXY=$(HTTP_PROXY); \
export CALICO_REGISTRY=$(CALICO_REGISTRY); \
export INSTALL_TIME_OUT=$(INSTALL_TIME_OUT); \
Expand Down
38 changes: 38 additions & 0 deletions test/e2e/common/egw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -251,3 +252,40 @@ 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)
}
}
}

func GetClusterDefualtEgressGateway(ctx context.Context, cli client.Client) (*egressv1.EgressGateway, error) {
egwList := new(egressv1.EgressGatewayList)
err := cli.List(ctx, egwList)
if err != nil {
return nil, err
}
for _, v := range egwList.Items {
if v.Spec.ClusterDefault {
return &v, nil
}
}
return nil, nil
}
2 changes: 1 addition & 1 deletion test/e2e/egressgateway/default_egressgateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/egresspolicy/egresspolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package egresspolicy_test
import (
"context"
"fmt"
"strings"
"time"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -828,6 +829,10 @@ var _ = Describe("EgressPolicy", Serial, func() {
egw.Spec.ClusterDefault = true
})

if err != nil && strings.Contains(err.Error(), "A cluster can only have one default gateway") {
Skip("The default egressgateway already exists, skip this test case")
}

Expect(err).NotTo(HaveOccurred())

DeferCleanup(func() {
Expand Down

0 comments on commit 99c2a07

Please sign in to comment.