Skip to content

Commit

Permalink
e2e: fix retrieving docker network information (#4169)
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian authored Jun 14, 2024
1 parent 6ac97fb commit 49c9ff1
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 54 deletions.
21 changes: 15 additions & 6 deletions test/e2e/iptables-vpc-nat-gw/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,31 @@ func setupNetworkAttachmentDefinition(
ginkgo.By("Got network attachment definition " + nad.Name)

ginkgo.By("Creating underlay macvlan subnet " + externalNetworkName)
cidr := make([]string, 0, 2)
gateway := make([]string, 0, 2)
var cidrV4, cidrV6, gatewayV4, gatewayV6 string
for _, config := range dockerExtNetNetwork.IPAM.Config {
switch util.CheckProtocol(config.Subnet) {
case apiv1.ProtocolIPv4:
if f.HasIPv4() {
cidr = append(cidr, config.Subnet)
gateway = append(gateway, config.Gateway)
cidrV4 = config.Subnet
gatewayV4 = config.Gateway
}
case apiv1.ProtocolIPv6:
if f.HasIPv6() {
cidr = append(cidr, config.Subnet)
gateway = append(gateway, config.Gateway)
cidrV6 = config.Subnet
gatewayV6 = config.Gateway
}
}
}
cidr := make([]string, 0, 2)
gateway := make([]string, 0, 2)
if f.HasIPv4() {
cidr = append(cidr, cidrV4)
gateway = append(gateway, gatewayV4)
}
if f.HasIPv6() {
cidr = append(cidr, cidrV6)
gateway = append(gateway, gatewayV6)
}
excludeIPs := make([]string, 0, len(network.Containers)*2)
for _, container := range network.Containers {
if container.IPv4Address != "" && f.HasIPv4() {
Expand Down
36 changes: 23 additions & 13 deletions test/e2e/kube-ovn/subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,25 +505,30 @@ var _ = framework.Describe("[group:subnet]", func() {
framework.ExpectNoError(err)

ginkgo.By("Determine external egress gateway addresses")
gateways := make([]string, 0, 2)
var gatewayV4, gatewayV6 string
for _, config := range network.IPAM.Config {
if config.Subnet != "" {
switch util.CheckProtocol(config.Subnet) {
case apiv1.ProtocolIPv4:
if cidrV4 != "" {
gateway, err := util.LastIP(config.Subnet)
gatewayV4, err = util.LastIP(config.Subnet)
framework.ExpectNoError(err)
gateways = append(gateways, gateway)
}
case apiv1.ProtocolIPv6:
if cidrV6 != "" {
gateway, err := util.LastIP(config.Subnet)
gatewayV6, err = util.LastIP(config.Subnet)
framework.ExpectNoError(err)
gateways = append(gateways, gateway)
}
}
}
}
gateways := make([]string, 0, 2)
if gatewayV4 != "" {
gateways = append(gateways, gatewayV4)
}
if gatewayV6 != "" {
gateways = append(gateways, gatewayV6)
}

ginkgo.By("Creating subnet " + subnetName)
prPriority := 1000 + rand.IntN(1000)
Expand Down Expand Up @@ -597,28 +602,33 @@ var _ = framework.Describe("[group:subnet]", func() {
framework.ExpectNoError(err)

ginkgo.By("Determine external egress gateway addresses")
cidrs := make([]string, 0, 2)
gateways := make([]string, 0, 2)
var gatewayV4, gatewayV6 string
for _, config := range network.IPAM.Config {
if config.Subnet != "" {
switch util.CheckProtocol(config.Subnet) {
case apiv1.ProtocolIPv4:
if cidrV4 != "" {
gateway, err := util.LastIP(config.Subnet)
gatewayV4, err = util.LastIP(config.Subnet)
framework.ExpectNoError(err)
cidrs = append(cidrs, cidrV4)
gateways = append(gateways, gateway)
}
case apiv1.ProtocolIPv6:
if cidrV6 != "" {
gateway, err := util.LastIP(config.Subnet)
gatewayV6, err = util.LastIP(config.Subnet)
framework.ExpectNoError(err)
cidrs = append(cidrs, cidrV6)
gateways = append(gateways, gateway)
}
}
}
}
cidrs := make([]string, 0, 2)
gateways := make([]string, 0, 2)
if gatewayV4 != "" {
cidrs = append(cidrs, cidrV4)
gateways = append(gateways, gatewayV4)
}
if gatewayV6 != "" {
cidrs = append(cidrs, cidrV6)
gateways = append(gateways, gatewayV6)
}

ginkgo.By("Creating subnet " + subnetName)
gatewayNodes := make([]string, 0, len(nodes.Items))
Expand Down
63 changes: 45 additions & 18 deletions test/e2e/kube-ovn/underlay/underlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,22 +393,31 @@ var _ = framework.SerialDescribe("[group:underlay]", func() {
_ = vlanClient.Create(vlan)

ginkgo.By("Creating subnet " + subnetName)
cidr := make([]string, 0, 2)
gateway := make([]string, 0, 2)
var cidrV4, cidrV6, gatewayV4, gatewayV6 string
for _, config := range dockerNetwork.IPAM.Config {
switch util.CheckProtocol(config.Subnet) {
case apiv1.ProtocolIPv4:
if f.HasIPv4() {
cidr = append(cidr, config.Subnet)
gateway = append(gateway, config.Gateway)
cidrV4 = config.Subnet
gatewayV4 = config.Gateway
}
case apiv1.ProtocolIPv6:
if f.HasIPv6() {
cidr = append(cidr, config.Subnet)
gateway = append(gateway, config.Gateway)
cidrV6 = config.Subnet
gatewayV6 = config.Gateway
}
}
}
cidr := make([]string, 0, 2)
gateway := make([]string, 0, 2)
if f.HasIPv4() {
cidr = append(cidr, cidrV4)
gateway = append(gateway, gatewayV4)
}
if f.HasIPv6() {
cidr = append(cidr, cidrV6)
gateway = append(gateway, gatewayV6)
}
excludeIPs := make([]string, 0, len(network.Containers)*2)
for _, container := range network.Containers {
if container.IPv4Address != "" && f.HasIPv4() {
Expand Down Expand Up @@ -517,22 +526,31 @@ var _ = framework.SerialDescribe("[group:underlay]", func() {
_ = vlanClient.Create(vlan)

ginkgo.By("Creating underlay subnet " + subnetName)
underlayCidr := make([]string, 0, 2)
gateway := make([]string, 0, 2)
var cidrV4, cidrV6, gatewayV4, gatewayV6 string
for _, config := range dockerNetwork.IPAM.Config {
switch util.CheckProtocol(config.Subnet) {
case apiv1.ProtocolIPv4:
if f.HasIPv4() {
underlayCidr = append(underlayCidr, config.Subnet)
gateway = append(gateway, config.Gateway)
cidrV4 = config.Subnet
gatewayV4 = config.Gateway
}
case apiv1.ProtocolIPv6:
if f.HasIPv6() {
underlayCidr = append(underlayCidr, config.Subnet)
gateway = append(gateway, config.Gateway)
cidrV6 = config.Subnet
gatewayV6 = config.Gateway
}
}
}
underlayCidr := make([]string, 0, 2)
gateway := make([]string, 0, 2)
if f.HasIPv4() {
underlayCidr = append(underlayCidr, cidrV4)
gateway = append(gateway, gatewayV4)
}
if f.HasIPv6() {
underlayCidr = append(underlayCidr, cidrV6)
gateway = append(gateway, gatewayV6)
}

excludeIPs := make([]string, 0, len(network.Containers)*2)
for _, container := range network.Containers {
Expand Down Expand Up @@ -814,22 +832,31 @@ var _ = framework.SerialDescribe("[group:underlay]", func() {
_ = vlanClient.Create(vlan)

ginkgo.By("Creating underlay subnet " + subnetName)
underlayCidr := make([]string, 0, 2)
gateway := make([]string, 0, 2)
var cidrV4, cidrV6, gatewayV4, gatewayV6 string
for _, config := range dockerNetwork.IPAM.Config {
switch util.CheckProtocol(config.Subnet) {
case apiv1.ProtocolIPv4:
if f.HasIPv4() {
underlayCidr = append(underlayCidr, config.Subnet)
gateway = append(gateway, config.Gateway)
cidrV4 = config.Subnet
gatewayV4 = config.Gateway
}
case apiv1.ProtocolIPv6:
if f.HasIPv6() {
underlayCidr = append(underlayCidr, config.Subnet)
gateway = append(gateway, config.Gateway)
cidrV6 = config.Subnet
gatewayV6 = config.Gateway
}
}
}
underlayCidr := make([]string, 0, 2)
gateway := make([]string, 0, 2)
if f.HasIPv4() {
underlayCidr = append(underlayCidr, cidrV4)
gateway = append(gateway, gatewayV4)
}
if f.HasIPv6() {
underlayCidr = append(underlayCidr, cidrV6)
gateway = append(gateway, gatewayV6)
}

excludeIPs := make([]string, 0, len(network.Containers)*2)
for _, container := range network.Containers {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/lb-svc/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"math/big"
"math/rand/v2"
"net"
"strings"
"testing"
"time"

Expand All @@ -25,6 +24,7 @@ import (

"github.com/onsi/ginkgo/v2"

apiv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
"github.com/kubeovn/kube-ovn/pkg/util"
"github.com/kubeovn/kube-ovn/test/e2e/framework"
"github.com/kubeovn/kube-ovn/test/e2e/framework/docker"
Expand Down Expand Up @@ -98,7 +98,7 @@ var _ = framework.SerialDescribe("[group:lb-svc]", func() {

ginkgo.By("Creating subnet " + subnetName)
for _, config := range dockerNetwork.IPAM.Config {
if !strings.ContainsRune(config.Subnet, ':') {
if util.CheckProtocol(config.Subnet) == apiv1.ProtocolIPv4 {
cidr = config.Subnet
gateway = config.Gateway
break
Expand Down
47 changes: 32 additions & 15 deletions test/e2e/ovn-vpc-nat-gw/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,22 +474,31 @@ var _ = framework.Describe("[group:ovn-vpc-nat-gw]", func() {
_ = vlanClient.Create(vlan)

ginkgo.By("Creating underlay subnet " + underlaySubnetName)
cidr := make([]string, 0, 2)
gateway := make([]string, 0, 2)
var cidrV4, cidrV6, gatewayV4, gatewayV6 string
for _, config := range dockerNetwork.IPAM.Config {
switch util.CheckProtocol(config.Subnet) {
case kubeovnv1.ProtocolIPv4:
if f.HasIPv4() {
cidr = append(cidr, config.Subnet)
gateway = append(gateway, config.Gateway)
cidrV4 = config.Subnet
gatewayV4 = config.Gateway
}
case kubeovnv1.ProtocolIPv6:
if f.HasIPv6() {
cidr = append(cidr, config.Subnet)
gateway = append(gateway, config.Gateway)
cidrV6 = config.Subnet
gatewayV6 = config.Gateway
}
}
}
cidr := make([]string, 0, 2)
gateway := make([]string, 0, 2)
if f.HasIPv4() {
cidr = append(cidr, cidrV4)
gateway = append(gateway, gatewayV4)
}
if f.HasIPv6() {
cidr = append(cidr, cidrV6)
gateway = append(gateway, gatewayV6)
}
excludeIPs := make([]string, 0, len(network.Containers)*2)
for _, container := range network.Containers {
if container.IPv4Address != "" && f.HasIPv4() {
Expand Down Expand Up @@ -689,24 +698,32 @@ var _ = framework.Describe("[group:ovn-vpc-nat-gw]", func() {
_ = vlanClient.Create(vlan)

ginkgo.By("Creating extra underlay subnet " + underlayExtraSubnetName)
extracidr := make([]string, 0, 2)
extragateway := make([]string, 0, 2)
gatewayV4 := ""
cidrV4, cidrV6, gatewayV4, gatewayV6 = "", "", "", ""
for _, config := range dockerExtraNetwork.IPAM.Config {
switch util.CheckProtocol(config.Subnet) {
case kubeovnv1.ProtocolIPv4:
if f.HasIPv4() {
cidrV4 = config.Subnet
gatewayV4 = config.Gateway
extracidr = append(extracidr, config.Subnet)
extragateway = append(extragateway, config.Gateway)
}
case kubeovnv1.ProtocolIPv6:
if f.HasIPv6() {
extracidr = append(extracidr, config.Subnet)
extragateway = append(extragateway, config.Gateway)
cidrV6 = config.Subnet
gatewayV6 = config.Gateway
}
}
}
cidr = make([]string, 0, 2)
gateway = make([]string, 0, 2)
if f.HasIPv4() {
cidr = append(cidr, cidrV4)
gateway = append(gateway, gatewayV4)
}
if f.HasIPv6() {
cidr = append(cidr, cidrV6)
gateway = append(gateway, gatewayV6)
}

extraExcludeIPs := make([]string, 0, len(extraNetwork.Containers)*2)
for _, container := range extraNetwork.Containers {
if container.IPv4Address != "" && f.HasIPv4() {
Expand All @@ -716,8 +733,8 @@ var _ = framework.Describe("[group:ovn-vpc-nat-gw]", func() {
extraExcludeIPs = append(extraExcludeIPs, strings.Split(container.IPv6Address, "/")[0])
}
}
extraVlanSubnetCidr := strings.Join(extracidr, ",")
extraVlanSubnetGw := strings.Join(extragateway, ",")
extraVlanSubnetCidr := strings.Join(cidr, ",")
extraVlanSubnetGw := strings.Join(gateway, ",")
underlayExtraSubnet := framework.MakeSubnet(underlayExtraSubnetName, vlanExtraName, extraVlanSubnetCidr, extraVlanSubnetGw, "", "", extraExcludeIPs, nil, nil)
_ = subnetClient.CreateSync(underlayExtraSubnet)
vlanExtraSubnet := subnetClient.Get(underlayExtraSubnetName)
Expand Down

0 comments on commit 49c9ff1

Please sign in to comment.