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 3277188
Show file tree
Hide file tree
Showing 21 changed files with 384 additions and 254 deletions.
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
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)

Check warning on line 148 in pkg/controller/egress_cluster_info.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/egress_cluster_info.go#L148

Added line #L148 was not covered by tests
if err != nil {
return reconcile.Result{Requeue: true}, err
}
isv6Cidr, err := utils.IsIPv6Cidr(ippool.Spec.CIDR)
isv6Cidr, err := ip.IsIPv6Cidr(ippool.Spec.CIDR)

Check warning on line 152 in pkg/controller/egress_cluster_info.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/egress_cluster_info.go#L152

Added line #L152 was not covered by tests
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 {

Check warning on line 551 in pkg/controller/egress_cluster_info.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/egress_cluster_info.go#L551

Added line #L551 was not covered by tests
ipv4Range = ipRanges
ipv6Range = []string{}
}
if isV6, _ := utils.IsIPv6Cidr(ipRanges[0]); isV6 {
if isV6, _ := ip.IsIPv6Cidr(ipRanges[0]); isV6 {

Check warning on line 555 in pkg/controller/egress_cluster_info.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/egress_cluster_info.go#L555

Added line #L555 was not covered by tests
ipv6Range = ipRanges
ipv4Range = []string{}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/webhook/validate.go
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion pkg/controller/webhook/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestValidateEgressGateway(t *testing.T) {
}
}

func TestValidateEgressGatewayPolicy(t *testing.T) {
func TestValidateEgressPolicy(t *testing.T) {
ctx := context.Background()

cases := map[string]struct {
Expand Down
17 changes: 9 additions & 8 deletions pkg/egressgateway/egress_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package egressgateway
import (
"context"
"fmt"
"github.com/spidernet-io/egressgateway/pkg/utils/ip"
"math/rand"
"net"
"time"
Expand Down Expand Up @@ -657,10 +658,10 @@ func (r egnReconciler) allocatorEIP(selEipLolicy string, nodeName string, pi pol
var useIpv4s []net.IP
var useIpv4sByNode []net.IP

ipv4Ranges, _ := utils.MergeIPRanges(constant.IPv4, eg.Spec.Ippools.IPv4)
ipv4Ranges, _ := ip.MergeIPRanges(constant.IPv4, eg.Spec.Ippools.IPv4)
perIpv4 = pi.ipv4
if len(perIpv4) != 0 {
result, err := utils.IsIPIncludedRange(constant.IPv4, perIpv4, ipv4Ranges)
result, err := ip.IsIPIncludedRange(constant.IPv4, perIpv4, ipv4Ranges)
if err != nil {
return "", "", err
}
Expand All @@ -676,8 +677,8 @@ func (r egnReconciler) allocatorEIP(selEipLolicy string, nodeName string, pi pol
}
}

ipv4s, _ := utils.ParseIPRanges(constant.IPv4, ipv4Ranges)
freeIpv4s := utils.IPsDiffSet(ipv4s, useIpv4s, false)
ipv4s, _ := ip.ParseIPRanges(constant.IPv4, ipv4Ranges)
freeIpv4s := ip.IPsDiffSet(ipv4s, useIpv4s, false)

if len(freeIpv4s) == 0 {
for _, node := range eg.Status.NodeList {
Expand Down Expand Up @@ -709,11 +710,11 @@ func (r egnReconciler) allocatorEIP(selEipLolicy string, nodeName string, pi pol
var useIpv6s []net.IP
var useIpv6sByNode []net.IP

ipv6Ranges, _ := utils.MergeIPRanges(constant.IPv6, eg.Spec.Ippools.IPv6)
ipv6Ranges, _ := ip.MergeIPRanges(constant.IPv6, eg.Spec.Ippools.IPv6)

perIpv6 = pi.ipv6
if len(perIpv6) != 0 {
result, err := utils.IsIPIncludedRange(constant.IPv6, perIpv6, ipv6Ranges)
result, err := ip.IsIPIncludedRange(constant.IPv6, perIpv6, ipv6Ranges)
if err != nil {
return "", "", err
}
Expand All @@ -729,8 +730,8 @@ func (r egnReconciler) allocatorEIP(selEipLolicy string, nodeName string, pi pol
}
}

ipv6s, _ := utils.ParseIPRanges(constant.IPv6, ipv6Ranges)
freeIpv6s := utils.IPsDiffSet(ipv6s, useIpv6s, false)
ipv6s, _ := ip.ParseIPRanges(constant.IPv6, ipv6Ranges)
freeIpv6s := ip.IPsDiffSet(ipv6s, useIpv6s, false)

if len(freeIpv6s) == 0 {
for _, node := range eg.Status.NodeList {
Expand Down
Loading

0 comments on commit 3277188

Please sign in to comment.