Skip to content

Commit

Permalink
Fix the default egress gateway problem (#1045)
Browse files Browse the repository at this point in the history
Signed-off-by: bzsuni <[email protected]>
  • Loading branch information
bzsuni authored Dec 12, 2023
1 parent ee2aa76 commit 591462a
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 4 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
DEFAULT_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 DEFAULT_CALICO_VERSION=$(DEFAULT_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
}
6 changes: 6 additions & 0 deletions test/e2e/constant/constant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2022 Authors of spidernet-io
// SPDX-License-Identifier: Apache-2.0

package constant

var WebhookMsgClusterDefaultGateway = "A cluster can only have one default gateway"
7 changes: 6 additions & 1 deletion test/e2e/egressgateway/default_egressgateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package egressgateway_test

import (
"context"
"strings"
"time"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -16,6 +17,7 @@ import (

egressv1 "github.com/spidernet-io/egressgateway/pkg/k8s/apis/v1beta1"
"github.com/spidernet-io/egressgateway/test/e2e/common"
e2econstant "github.com/spidernet-io/egressgateway/test/e2e/constant"
)

var _ = Describe("Test default egress gateway", Label("DefaultEgressGateway", "G00017"), Ordered, func() {
Expand Down Expand Up @@ -88,7 +90,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 All @@ -108,6 +110,9 @@ var _ = Describe("Test default egress gateway", Label("DefaultEgressGateway", "G
// create global egress gateway
ctx := context.Background()
err := cli.Create(ctx, clusterDefaultEgw)
if err != nil && strings.Contains(err.Error(), e2econstant.WebhookMsgClusterDefaultGateway) {
Skip("The default egressgateway already exists, skip this test case")
}
Expect(err).NotTo(HaveOccurred())

// create egress policy1
Expand Down
6 changes: 6 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 All @@ -22,6 +23,7 @@ import (

egressv1 "github.com/spidernet-io/egressgateway/pkg/k8s/apis/v1beta1"
"github.com/spidernet-io/egressgateway/test/e2e/common"
e2econstant "github.com/spidernet-io/egressgateway/test/e2e/constant"
)

var _ = Describe("EgressPolicy", Serial, func() {
Expand Down Expand Up @@ -828,6 +830,10 @@ var _ = Describe("EgressPolicy", Serial, func() {
egw.Spec.ClusterDefault = true
})

if err != nil && strings.Contains(err.Error(), e2econstant.WebhookMsgClusterDefaultGateway) {
Skip("The default egressgateway already exists, skip this test case")
}

Expect(err).NotTo(HaveOccurred())

DeferCleanup(func() {
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/installCalico.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CALICO_NODE=${DEST_CALICO_YAML_DIR}/calico_node.yaml
if [ -z "${CALICO_VERSION}" ]; then
[ -n "${HTTP_PROXY}" ] && { calico_info_json=$(curl --retry 3 --retry-delay 5 -x "${HTTP_PROXY}" -s https://api.github.com/repos/projectcalico/calico/releases/latest); echo ${calico_info_json}; calico_tag=$(echo ${calico_info_json} | jq -r '.tag_name'); }
[ -z "${HTTP_PROXY}" ] && { calico_info_json=$(curl --retry 3 --retry-delay 5 -s https://api.github.com/repos/projectcalico/calico/releases/latest); echo ${calico_info_json}; calico_tag=$(echo ${calico_info_json} | jq -r '.tag_name'); }
[ "${calico_tag}" == "null" ] && { echo "failed to get the calico version, specify the version manually"; calico_tag=${MANUAL_CALICO_VERSION}; }
[ "${calico_tag}" == "null" ] && { echo "failed to get the calico version, specify the version manually"; calico_tag=${DEFAULT_CALICO_VERSION}; }
else
calico_tag=${CALICO_VERSION}
fi
Expand Down

0 comments on commit 591462a

Please sign in to comment.