Skip to content

Commit

Permalink
Update egress agent test
Browse files Browse the repository at this point in the history
  • Loading branch information
lou-lan committed Jul 31, 2023
1 parent 75589ad commit 4b16ba5
Show file tree
Hide file tree
Showing 23 changed files with 1,104 additions and 297 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ unitest_tests:
-@rm -rf $(UNITEST_OUTPUT)
-@mkdir -p $(UNITEST_OUTPUT)
@echo "run unitest tests"
$(ROOT_DIR)/tools/golang/ginkgo.sh \
sudo $(ROOT_DIR)/tools/golang/ginkgo.sh \
--cover --coverprofile=./coverage.out --covermode set \
--json-report unitestreport.json \
-randomize-suites -randomize-all --keep-going --timeout=1h -p --slow-spec-threshold=120s \
Expand Down
2 changes: 1 addition & 1 deletion charts/crds/egressgateway.spidernet.io_egresstunnels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
group: egressgateway.spidernet.io
names:
categories:
- egressnode
- egresstunnel
kind: EgressTunnel
listKind: EgressTunnelList
plural: egresstunnels
Expand Down
10 changes: 0 additions & 10 deletions pkg/agent/police.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,16 +487,6 @@ func parseMark(mark string) (uint32, error) {
return i32, nil
}

func parseMarkToInt(mark string) (int, error) {
tmp := strings.ReplaceAll(mark, "0x", "")
i64, err := strconv.ParseInt(tmp, 16, 32)
if err != nil {
return 0, err
}
i32 := int(i64)
return i32, nil
}

func (r *policeReconciler) buildPolicyRule(policyName string, mark uint32, version uint8, isIgnoreInternalCIDR bool) *iptables.Rule {
tmp := "v4-"
ignoreInternalCIDRName := EgressClusterCIDRIPv4
Expand Down
4 changes: 0 additions & 4 deletions pkg/agent/police_test.go

This file was deleted.

19 changes: 13 additions & 6 deletions pkg/agent/vxlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package agent
import (
"context"
"fmt"
"strconv"

"net"
"strings"
Expand Down Expand Up @@ -185,7 +186,7 @@ func (r *vxlanReconciler) updateEgressNodeStatus(node *egressv1.EgressTunnel, ve
ctx := context.Background()
err = r.client.Get(ctx, types.NamespacedName{Name: r.cfg.NodeName}, node)
if err != nil {
if !errors.IsNotFound(err) {
if errors.IsNotFound(err) {
return nil
}
return err
Expand Down Expand Up @@ -283,11 +284,7 @@ func (r *vxlanReconciler) parseVTEP(status egressv1.EgressNodeStatus) *vxlan.Pee
if !ready {
return nil
}
return &vxlan.Peer{
IPv4: ipv4,
IPv6: ipv6,
MAC: mac,
}
return &vxlan.Peer{IPv4: ipv4, IPv6: ipv6, MAC: mac}
}

func (r *vxlanReconciler) version() int {
Expand Down Expand Up @@ -423,6 +420,16 @@ func (r *vxlanReconciler) ensureRoute() error {
return nil
}

func parseMarkToInt(mark string) (int, error) {
tmp := strings.ReplaceAll(mark, "0x", "")
i64, err := strconv.ParseInt(tmp, 16, 32)
if err != nil {
return 0, err
}
i32 := int(i64)
return i32, nil
}

func newEgressNodeController(mgr manager.Manager, cfg *config.Config, log logr.Logger) error {
ruleRoute := route.NewRuleRoute(log)

Expand Down
30 changes: 30 additions & 0 deletions pkg/agent/vxlan/vxlan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,33 @@ func TestDiffLink(t *testing.T) {
})
}
}

func TestVxlan(t *testing.T) {
device := New()
mac, err := net.ParseMAC("66:bf:c7:47:5c:14")
if err != nil {
t.Fatal(err)
}

ipv6, ipv6Net, err := net.ParseCIDR("fd01::1/120")
if err != nil {
t.Fatal(err)
}

ipv4Net := &net.IPNet{
IP: []byte{10, 6, 1, 21},
Mask: []byte{255, 255, 255, 0},
}

ipv6Net = &net.IPNet{
IP: ipv6,
Mask: ipv6Net.Mask,
}

err = device.EnsureLink("egress",
101, 3456, mac, 0,
ipv4Net, nil, true)
if err != nil {
t.Fatal(err)
}
}
121 changes: 0 additions & 121 deletions pkg/agent/vxlan_test.go

This file was deleted.

9 changes: 5 additions & 4 deletions pkg/controller/egress_cluster_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package controller
import (
"context"
"fmt"
"github.com/spidernet-io/egressgateway/pkg/utils/ip"
"strings"
"sync"

Expand Down Expand Up @@ -144,11 +145,11 @@ func (r *eciReconciler) reconcileCalicoIPPool(ctx context.Context, req reconcile
log.Info("update event")

// check if cidr about ippools changed
isv4Cidr, err := utils.IsIPv4Cidr(ippool.Spec.CIDR)
isv4Cidr, err := ip.IsIPv4Cidr(ippool.Spec.CIDR)
if err != nil {
return reconcile.Result{Requeue: true}, err
}
isv6Cidr, err := utils.IsIPv6Cidr(ippool.Spec.CIDR)
isv6Cidr, err := ip.IsIPv6Cidr(ippool.Spec.CIDR)
if err != nil {
return reconcile.Result{Requeue: true}, err
}
Expand Down Expand Up @@ -547,11 +548,11 @@ func getCidr(pod *corev1.Pod, param string) (ipv4Range, ipv6Range []string, err
// get cidr
ipRanges := strings.Split(ipRange, ",")
if len(ipRanges) == 1 {
if isV4, _ := utils.IsIPv4Cidr(ipRanges[0]); isV4 {
if isV4, _ := ip.IsIPv4Cidr(ipRanges[0]); isV4 {
ipv4Range = ipRanges
ipv6Range = []string{}
}
if isV6, _ := utils.IsIPv6Cidr(ipRanges[0]); isV6 {
if isV6, _ := ip.IsIPv6Cidr(ipRanges[0]); isV6 {
ipv6Range = ipRanges
ipv4Range = []string{}

Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/webhook/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func ValidateHook(client client.Client, cfg *config.Config) *webhook.Admission {
}

if req.Operation == v1.Create {
if cfg.FileConfig.EnableIPv4 && cfg.FileConfig.EnableIPv6 {
if cfg.FileConfig.EnableIPv4 || cfg.FileConfig.EnableIPv6 {
if ok, err := checkEIP(client, ctx, *egp); !ok {
return webhook.Denied(err.Error())
}
Expand Down Expand Up @@ -161,7 +161,7 @@ func checkEIP(client client.Client, ctx context.Context, egp egressv1.EgressPoli
return true, nil
}

// ValidateHook ValidateHook
// MutateHook MutateHook
func MutateHook(client client.Client, cfg *config.Config) *webhook.Admission {
return &webhook.Admission{
Handler: admission.HandlerFunc(func(ctx context.Context, req webhook.AdmissionRequest) webhook.AdmissionResponse {
Expand Down
Loading

0 comments on commit 4b16ba5

Please sign in to comment.