Skip to content

Commit

Permalink
Fix NodeNetworkPolicy e2e test failure
Browse files Browse the repository at this point in the history
In NodeNetworkPolicy e2e tests, we have the following cases:

- Node to Nodes. We deploy two hostNetwork Pods on different Nodes.
- Node to remote Pods. We deploy a hostNetwork Pod on a Node and a
  non-hostNetwork Pod on another Node.

For the case of Node to local Pods, we don't test it since the UDP probing
from a non-hostNetwork Pod to the hostNetwork Pod deployed on the same
Node will get a failure. The reason is that the reply packets use the
local Antrea gateway IP as source IP, instead of the local Node IP, which
is the destination IP of the request packets, resulting in the failure
of test Pods initialization.

This PR fixes the e2e test failure by reverting the test Pods
initialization modified by PR #4537.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
  • Loading branch information
hongliangl committed Apr 2, 2024
1 parent a2b0356 commit e986dd8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
21 changes: 8 additions & 13 deletions pkg/agent/bgp/bgpserver/gobgp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
gobgpapi "github.com/osrg/gobgp/v3/api"
gobgp "github.com/osrg/gobgp/v3/pkg/server"
"google.golang.org/protobuf/types/known/anypb"
"k8s.io/klog/v2"
netutils "k8s.io/utils/net"
"net/netip"
)
Expand Down Expand Up @@ -119,16 +118,13 @@ func (g *GoBGPServer) ResetPeers(ctx context.Context, peerConfigs []*types.BGPPe
// AdvertiseRoutes advertises BGP Paths to all configured peers.
func (g *GoBGPServer) AdvertiseRoutes(ctx context.Context, routes []string, ipFamily netutils.IPFamily) error {
goBGPIPFamily := toGoBGPIPFamily(ipFamily)
klog.Info("ip family ", goBGPIPFamily)

for _, route := range routes {
prefix, _ := netip.ParsePrefix(route)
klog.Info("prefix ", prefix)
nlri, _ := anypb.New(&gobgpapi.IPAddressPrefix{
Prefix: prefix.Addr().String(),
PrefixLen: uint32(prefix.Bits()),
})
klog.Info("prefix ", prefix.Bits(), " ip ", prefix.String())

var attrs []*anypb.Any
a1, _ := anypb.New(&gobgpapi.OriginAttribute{
Expand Down Expand Up @@ -158,11 +154,10 @@ func (g *GoBGPServer) AdvertiseRoutes(ctx context.Context, routes []string, ipFa
},
}

response, err := g.server.AddPath(ctx, path)
_, err := g.server.AddPath(ctx, path)
if err != nil {
return err
}
klog.Info("response ", response)
}
return nil
}
Expand All @@ -174,36 +169,36 @@ func (g *GoBGPServer) WithdrawRoutes(ctx context.Context, routes []string, ipFam
for _, route := range routes {
prefix, _ := netip.ParsePrefix(route)
nlri, _ := anypb.New(&gobgpapi.IPAddressPrefix{
Prefix: prefix.String(),
Prefix: prefix.Addr().String(),
PrefixLen: uint32(prefix.Bits()),
})

var pattrs []*anypb.Any
var attrs []*anypb.Any
a1, _ := anypb.New(&gobgpapi.OriginAttribute{
Origin: 0,
})
pattrs = append(pattrs, a1)
attrs = append(attrs, a1)

if ipFamily == netutils.IPv4 {
a2, _ := anypb.New(&gobgpapi.NextHopAttribute{
NextHop: "0.0.0.0",
})
pattrs = append(pattrs, a2)
attrs = append(attrs, a2)
} else if ipFamily == netutils.IPv6 {
a2, _ := anypb.New(&gobgpapi.MpReachNLRIAttribute{
Family: &gobgpapi.Family{Afi: goBGPIPFamily, Safi: gobgpapi.Family_SAFI_UNICAST},
NextHops: []string{"::"},
Nlris: []*anypb.Any{nlri},
})
pattrs = append(pattrs, a2)
attrs = append(attrs, a2)
}

path := &gobgpapi.DeletePathRequest{
TableType: gobgpapi.TableType_GLOBAL,
//TableType: gobgpapi.TableType_GLOBAL,
Path: &gobgpapi.Path{
Family: &gobgpapi.Family{Afi: goBGPIPFamily, Safi: gobgpapi.Family_SAFI_UNICAST},
Nlri: nlri,
Pattrs: pattrs,
Pattrs: attrs,
},
}

Expand Down
15 changes: 13 additions & 2 deletions pkg/agent/bgp/bgpserver/gobgp/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ func TestGoBGP(t *testing.T) {
"10.20.3.0/26",
}
// time.Sleep(10 * time.Second)

t.Log("AdvertiseRoutes")
err = bgpServer.AdvertiseRoutes(context.Background(), testRoutes, netutils.IPv4)
require.NoError(t, err)

time.Sleep(300 * time.Second)
time.Sleep(30 * time.Second)

t.Log("WithdrawRoutes")
err = bgpServer.WithdrawRoutes(context.Background(), testRoutes, netutils.IPv4)
require.NoError(t, err)

time.Sleep(30 * time.Second)

t.Log("RemovePeer")
err = bgpServer.RemovePeers(context.Background(), []*types.BGPPeerConfig{testPeerConfig}, netutils.IPv4)
require.NoError(t, err)

time.Sleep(3000 * time.Second)
//err = bgpServer.Stop()
}

0 comments on commit e986dd8

Please sign in to comment.