Skip to content

Commit

Permalink
Merge pull request spidernet-io#1872 from ty-dc/pr/case-c00007
Browse files Browse the repository at this point in the history
e2e: add case about coordinator
  • Loading branch information
weizhoublue authored Jul 21, 2023
2 parents b95dad8 + 1be5940 commit dc84177
Show file tree
Hide file tree
Showing 15 changed files with 656 additions and 190 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ require (
github.com/openkruise/kruise-api v1.3.0
github.com/prometheus-community/pro-bing v0.2.0
github.com/prometheus/client_golang v1.14.0
github.com/spidernet-io/e2eframework v0.0.0-20230403061847-445757b963b3
github.com/spidernet-io/e2eframework v0.0.0-20230721034001-0ebb34260e8f
github.com/spidernet-io/spiderdoctor v0.3.0
github.com/tigera/operator v1.30.4
github.com/vishvananda/netlink v1.2.1-beta.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.14.0 h1:Rg7d3Lo706X9tHsJMUjdiwMpHB7W8WnSVOssIY+JElU=
github.com/spf13/viper v1.14.0/go.mod h1:WT//axPky3FdvXHzGw33dNdXXXfFQqmEalje+egj8As=
github.com/spidernet-io/e2eframework v0.0.0-20230403061847-445757b963b3 h1:DwiGehYumYZUF3wUVQqSaY/WvpZ71zLeIJ1WaSNQn20=
github.com/spidernet-io/e2eframework v0.0.0-20230403061847-445757b963b3/go.mod h1:fCnYp0IxYHYmGMMm7WDy8pTb3BICSMV2Z7sro9vJhrs=
github.com/spidernet-io/e2eframework v0.0.0-20230721034001-0ebb34260e8f h1:0FhUUHUUBAUrrjOsr1K3VP3RXcjTqBjq8GgB02rWYoQ=
github.com/spidernet-io/e2eframework v0.0.0-20230721034001-0ebb34260e8f/go.mod h1:RdWxk8i4tb80fYXBOEb8lm4Giusp6DFAGxgmt7OIGOo=
github.com/spidernet-io/spiderdoctor v0.3.0 h1:Nq8xf8f1GkT3dRmeM2gt38ivkS5Fjpnz7LzueWGL6cA=
github.com/spidernet-io/spiderdoctor v0.3.0/go.mod h1:4TcvXLBhlgqTYFO+LnagEKsEF2UKTukLhodPrsuqYnA=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
Expand Down
4 changes: 3 additions & 1 deletion pkg/networking/gwconnection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ package gwconnection

import (
"fmt"
"go.uber.org/zap"
"time"

"go.uber.org/zap"

ping "github.com/prometheus-community/pro-bing"
)

Expand All @@ -31,6 +32,7 @@ func NewPinger(count int, interval, timeout, gw string, logger *zap.Logger) (*Pi
return nil, err
}
pinger.Timeout = timeoutDuration
pinger.SetPrivileged(true)

return &Pinger{logger, pinger}, nil
}
Expand Down
8 changes: 4 additions & 4 deletions test/doc/coordinator.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| C00002 | coordinator in tuneMode: overlay works well | p1 | smoke | done | |
| C00003 | coordinator in tuneMode: underlay with two NIC | p1 | smoke | | |
| C00004 | coordinator in tuneMode: overlay with two NIC | p1 | smoke | | |
| C00005 | specify the NIC where the default route is located | p2 | | | |
| C00006 | ip conflict detection (ipv4, ipv6) | p2 | | | |
| C00007 | override pod mac prefix | p2 | | | |
| C00008 | gateway connection detection | p2 | | | |
| C00005 | specify the NIC where the default route is located | p2 | done | | |
| C00006 | ip conflict detection (ipv4, ipv6) | p2 | done | | |
| C00007 | override pod mac prefix | p2 | | done | |
| C00008 | gateway connection detection | p2 | done | | |
51 changes: 32 additions & 19 deletions test/e2e/annotation/annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,12 +549,10 @@ var _ = Describe("test annotation", Label("annotation"), func() {
})
})
It("succeeded to running pod after added valid route field", Label("A00002"), func() {
var v4PoolName, v6PoolName, ipv4Gw, ipv6Gw string
var v4PoolName, v6PoolName, ipv4Dst, ipv6Dst, ipv4Gw, ipv6Gw string
var v4Pool, v6Pool *spiderpool.SpiderIPPool
var err error

v4Dst := "0.0.0.0/0"
v6Dst := "::/0"
annoPodRouteValue := new(types.AnnoPodRoutesValue)
annoPodIPPoolValue := types.AnnoPodIPPoolValue{}

Expand All @@ -573,10 +571,10 @@ var _ = Describe("test annotation", Label("annotation"), func() {
}
Expect(err).To(Succeed(), "failed to create v4 ippool %v ,err is %v\n", v4PoolName, err)

subnet := v4Pool.Spec.Subnet
ipv4Gw = strings.Split(subnet, "0/")[0] + "1"
ipv4Dst = v4Pool.Spec.Subnet
ipv4Gw = strings.Split(v4Pool.Spec.Subnet, "0/")[0] + "1"
*annoPodRouteValue = append(*annoPodRouteValue, types.AnnoRouteItem{
Dst: v4Dst,
Dst: ipv4Dst,
Gw: ipv4Gw,
})
annoPodIPPoolValue.IPv4Pools = []string{v4PoolName}
Expand All @@ -595,10 +593,10 @@ var _ = Describe("test annotation", Label("annotation"), func() {
}
Expect(err).To(Succeed(), "failed to create v6 ippool %v ,err is %v\n", v6PoolName, err)

subnet := v6Pool.Spec.Subnet
ipv6Gw = strings.Split(subnet, "/")[0] + "1"
ipv6Dst = v6Pool.Spec.Subnet
ipv6Gw = strings.Split(v6Pool.Spec.Subnet, "/")[0] + "1"
*annoPodRouteValue = append(*annoPodRouteValue, types.AnnoRouteItem{
Dst: v6Dst,
Dst: ipv6Dst,
Gw: ipv6Gw,
})
annoPodIPPoolValue.IPv6Pools = []string{v6PoolName}
Expand Down Expand Up @@ -634,20 +632,22 @@ var _ = Describe("test annotation", Label("annotation"), func() {
// check whether the route is effective
GinkgoWriter.Println("check whether the route is effective")
if frame.Info.IpV4Enabled {
command := fmt.Sprintf("ip r | grep 'default via %s'", ipv4Gw)
command := fmt.Sprintf("ip r | grep '%s via %s'", ipv4Dst, ipv4Gw)
ctx, cancel := context.WithTimeout(context.Background(), common.ExecCommandTimeout)
defer cancel()
_, err := frame.ExecCommandInPod(podName, nsName, command, ctx)
Expect(err).NotTo(HaveOccurred(), "failed to exec command %v\n", command)
out, err := frame.ExecCommandInPod(podName, nsName, command, ctx)
Expect(err).NotTo(HaveOccurred(), "failed to exec command %v , error is %v, %v \n", command, err, string(out))
}
if frame.Info.IpV6Enabled {
command := "ip -6 r | grep 'default via'| awk '{print $3}' "
// The ipv6 address on the network interface will be abbreviated. For example fd00:0c3d::2 becomes fd00:c3d::2.
// Abbreviate the expected ipv6 address and use it in subsequent assertions.
ipv6Dst = strings.Replace(ipv6Dst, ":0", ":", -1)
ipv6Gw = strings.Replace(ipv6Gw, ":0", ":", -1)
command := fmt.Sprintf("ip -6 r | grep '%s via %s'", ipv6Dst, ipv6Gw)
ctx, cancel := context.WithTimeout(context.Background(), common.ExecCommandTimeout)
defer cancel()
out, err := frame.ExecCommandInPod(podName, nsName, command, ctx)
Expect(err).NotTo(HaveOccurred(), "failed to exec command %v\n", command)
effectiveIpv6GwStr := strings.TrimSpace(string(out))
Expect(common.ContrastIpv6ToIntValues(effectiveIpv6GwStr, ipv6Gw)).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "failed to exec command %v , error is %v, %v \n", command, err, string(out))
}

// delete pod
Expand All @@ -666,8 +666,9 @@ var _ = Describe("test annotation", Label("annotation"), func() {
})

It("Successfully run pods with multi-NIC ippools annotations", Label("A00010"), func() {
var v4PoolName, v6PoolName string
var v4PoolName, v6PoolName, newv4SubnetName, newv6SubnetName string
var v4Pool, v6Pool *spiderpool.SpiderIPPool
var newv4SubnetObject, newv6SubnetObject *spiderpool.SpiderSubnet
var err error

ctx, cancel := context.WithTimeout(context.Background(), common.PodStartTimeout)
Expand All @@ -677,7 +678,10 @@ var _ = Describe("test annotation", Label("annotation"), func() {
v4PoolName, v4Pool = common.GenerateExampleIpv4poolObject(1)
Expect(v4Pool).NotTo(BeNil())
if frame.Info.SpiderSubnetEnabled {
err = common.CreateIppoolInSpiderSubnet(ctx, frame, v4SubnetName, v4Pool, 1)
newv4SubnetName, newv4SubnetObject = common.GenerateExampleV4SubnetObject(100)
Expect(newv4SubnetObject).NotTo(BeNil())
Expect(common.CreateSubnet(frame, newv4SubnetObject)).NotTo(HaveOccurred())
err = common.CreateIppoolInSpiderSubnet(ctx, frame, newv4SubnetName, v4Pool, 1)
} else {
err = common.CreateIppool(frame, v4Pool)
}
Expand All @@ -688,7 +692,10 @@ var _ = Describe("test annotation", Label("annotation"), func() {
v6PoolName, v6Pool = common.GenerateExampleIpv6poolObject(1)
Expect(v6Pool).NotTo(BeNil())
if frame.Info.SpiderSubnetEnabled {
err = common.CreateIppoolInSpiderSubnet(ctx, frame, v6SubnetName, v6Pool, 1)
newv6SubnetName, newv6SubnetObject = common.GenerateExampleV6SubnetObject(100)
Expect(newv6SubnetObject).NotTo(BeNil())
Expect(common.CreateSubnet(frame, newv6SubnetObject)).NotTo(HaveOccurred())
err = common.CreateIppoolInSpiderSubnet(ctx, frame, newv6SubnetName, v6Pool, 1)
} else {
err = common.CreateIppool(frame, v6Pool)
}
Expand Down Expand Up @@ -761,10 +768,16 @@ var _ = Describe("test annotation", Label("annotation"), func() {
if frame.Info.IpV4Enabled {
GinkgoWriter.Printf("delete v4 ippool %v. \n", v4PoolName)
Expect(common.DeleteIPPoolByName(frame, v4PoolName)).To(Succeed())
if frame.Info.SpiderSubnetEnabled {
Expect(common.DeleteSubnetByName(frame, v4SubnetName)).NotTo(HaveOccurred())
}
}
if frame.Info.IpV6Enabled {
GinkgoWriter.Printf("delete v6 ippool %v. \n", v6PoolName)
Expect(common.DeleteIPPoolByName(frame, v6PoolName)).To(Succeed())
if frame.Info.SpiderSubnetEnabled {
Expect(common.DeleteSubnetByName(frame, v6SubnetName)).NotTo(HaveOccurred())
}
}
})
})
Expand Down
13 changes: 5 additions & 8 deletions test/e2e/common/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
NodeReadyTimeout = time.Minute
ResourceDeleteTimeout = time.Minute * 5
BatchCreateTimeout = time.Minute * 5
KdoctorCheckTime = time.Minute * 10
)

var ForcedWaitingTime = time.Second
Expand Down Expand Up @@ -59,22 +60,18 @@ var (
SpiderPoolIPv4SubnetVlan200 string = "vlan200-v4"
SpiderPoolIPv6SubnetVlan200 string = "vlan200-v6"

SpiderPoolIPPoolAnnotationKey = "ipam.spidernet.io/ippool"
SpiderPoolIPPoolsAnnotationKey = "ipam.spidernet.io/ippools"
SpiderPoolSubnetAnnotationKey = "ipam.spidernet.io/subnet"
SpiderPoolSubnetsAnnotationKey = "ipam.spidernet.io/subnets"

MultusNs = "kube-system"
SpiderDoctorAgentNs = "kube-system"
SpiderDoctorAgentDSName = "spiderdoctor-agent"

// Route
V4Dst string = "0.0.0.0/0"
V6Dst string = "::/0"
// gateway and check for ip conflicting machines
VlanGatewayContainer = "vlan-gateway"

// Network Name
NIC1 string = "eth0"
NIC2 string = "net1"
NIC3 string = "eth0.100"
NIC4 string = "eth0.200"
)

// Error
Expand Down
39 changes: 8 additions & 31 deletions test/e2e/common/spiderpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,39 +551,15 @@ func BatchDeletePoolUntilFinish(f *frame.Framework, iPPoolNameList []string, ctx
return nil
}

func GenerateExampleIpv4Gateway() (v4Gateway string) {
num1 := GenerateRandomNumber(255)
num2 := GenerateRandomNumber(255)
num3 := GenerateRandomNumber(255)
num4 := GenerateRandomNumber(255)
v4Gateway = fmt.Sprintf("%s.%s.%s.%s", num1, num2, num3, num4)
return v4Gateway
func GenerateRandomIPV4() string {
a, b, c, d := r.Intn(255), r.Intn(255), r.Intn(255), r.Intn(255)
return fmt.Sprintf("%d:%d:%d:%d", a, b, c, d)
}

func GenerateExampleIpv6Gateway() (v6Gateway string) {
num1 := GenerateRandomNumber(9999)
num2 := GenerateRandomNumber(9999)
num3 := GenerateRandomNumber(9999)
num4 := GenerateRandomNumber(9999)
v6Gateway = fmt.Sprintf("%s:%s:%s::%s", num1, num2, num3, num4)
return v6Gateway
}

func GenerateExampleIpv4Address() (ipv4Address string) {
randomNum1 := GenerateRandomNumber(255)
randomNum2 := GenerateRandomNumber(255)
randomNum3 := GenerateRandomNumber(255)
randomNum4 := GenerateRandomNumber(255)
ipv4Address = fmt.Sprintf("%s.%s.%s.%s", randomNum1, randomNum2, randomNum3, randomNum4)
return ipv4Address
}

func GenerateExampleIpv6Address() (ipv6Address string) {
randomNum1 := GenerateRandomNumber(9999)
randomNum2 := GenerateRandomNumber(9999)
randomNum3 := GenerateRandomNumber(9999)
ipv6Address = fmt.Sprintf("%s:%s::%s", randomNum1, randomNum2, randomNum3)
return ipv6Address
func GenerateRandomIPV6() string {
n := make([]byte, 3)
r.Read(n)
return fmt.Sprintf("%x:%x::%x", n[0], n[1], n[2])
}

// Waiting for Ippool Status Condition By Allocated IPs meets expectations
Expand Down Expand Up @@ -733,6 +709,7 @@ func CreateIppoolInSpiderSubnet(ctx context.Context, f *frame.Framework, subnetN

pool.Spec.Subnet = subnetObj.Spec.Subnet
pool.Spec.IPs = selectIpRanges
pool.Spec.Gateway = subnetObj.Spec.Gateway
err = CreateIppool(f, pool)
if err != nil {
// The informer of SpiderSubnet will delay synchronizing its own state information,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var frame *e2e.Framework

// var name string
var spiderDoctorAgent *appsv1.DaemonSet
var annotations = make(map[string]string)

var successRate = float64(1)
var name string
Expand Down
Loading

0 comments on commit dc84177

Please sign in to comment.