Unverified Commit b2d564d4 authored by Oilbeater's avatar Oilbeater Committed by GitHub
Browse files

Merge pull request #294 from alauda/test/node-test

test: add node test
parents 32370082 ae187152
Showing with 54 additions and 22 deletions
+54 -22
......@@ -70,6 +70,18 @@ func CIDRConflict(a, b string) bool {
return aIpNet.Contains(bIp) || bIpNet.Contains(aIp)
}
func CIDRContainIP(cidrStr, ipStr string) bool {
_, cidr, err := net.ParseCIDR(cidrStr)
if err != nil {
return false
}
ip := net.ParseIP(ipStr)
if ip == nil {
return false
}
return cidr.Contains(ip)
}
func CheckProtocol(address string) string {
address = strings.Split(address, "/")[0]
ip := net.ParseIP(address)
......
......@@ -10,30 +10,11 @@ import (
)
func ValidateSubnet(subnet kubeovnv1.Subnet) error {
cidrStr := subnet.Spec.CIDRBlock
if cidrStr == "" {
return fmt.Errorf("cidr is required for logical switch")
}
_, cidr, err := net.ParseCIDR(cidrStr)
if err != nil {
return fmt.Errorf("%s is a invalid cidr %v", cidrStr, err)
}
gatewayStr := subnet.Spec.Gateway
if gatewayStr == "" {
return fmt.Errorf("gateway is required for logical switch")
}
gateway := net.ParseIP(gatewayStr)
if gateway == nil {
return fmt.Errorf("%s is not a valid gateway", gatewayStr)
}
if !cidr.Contains(gateway) {
return fmt.Errorf("gateway address %s not in cidr range", gatewayStr)
if !CIDRContainIP(subnet.Spec.CIDRBlock, subnet.Spec.Gateway){
return fmt.Errorf(" gateway %s is not in cidr %s", subnet.Spec.Gateway, subnet.Spec.CIDRBlock)
}
excludeIps := subnet.Spec.ExcludeIps
for _, ipr := range excludeIps {
ips := strings.Split(ipr, "..")
if len(ips) > 2 {
......@@ -85,7 +66,11 @@ func ValidatePodNetwork(annotations map[string]string) error {
return fmt.Errorf("%s is not a valid %s", ip, IpAddressAnnotation)
}
}
if cidr := annotations[CidrAnnotation]; cidr != "" {
if !CIDRContainIP(cidr, ip) {
return fmt.Errorf("%s not in cidr %s", ip, cidr)
}
}
}
mac := annotations[MacAddressAnnotation]
......
......@@ -14,6 +14,7 @@ import (
// tests to run
_ "github.com/alauda/kube-ovn/test/e2e/ip"
_ "github.com/alauda/kube-ovn/test/e2e/node"
_ "github.com/alauda/kube-ovn/test/e2e/subnet"
)
......
......@@ -53,6 +53,7 @@ var _ = Describe("[IP Allocation]", func() {
pod, err = f.KubeClientSet.CoreV1().Pods(namespace).Get(name, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
Expect(pod.Annotations[util.AllocatedAnnotation]).To(Equal("true"))
Expect(pod.Annotations[util.RoutedAnnotation]).To(Equal("true"))
time.Sleep(1 * time.Second)
ip, err := f.OvnClientSet.KubeovnV1().IPs().Get(fmt.Sprintf("%s.%s", name, namespace), metav1.GetOptions{})
......
package node
import (
"fmt"
"github.com/alauda/kube-ovn/pkg/util"
"github.com/alauda/kube-ovn/test/e2e/framework"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"os"
)
var _ = Describe("[Node Init]", func() {
f := framework.NewFramework("ip allocation", fmt.Sprintf("%s/.kube/config", os.Getenv("HOME")))
It("node annotations", func() {
nodes, err := f.KubeClientSet.CoreV1().Nodes().List(metav1.ListOptions{})
Expect(err).NotTo(HaveOccurred())
subnet, err := f.OvnClientSet.KubeovnV1().Subnets().Get("join", metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
for _, no := range nodes.Items {
annotations := no.Annotations
Expect(annotations[util.AllocatedAnnotation]).To(Equal("true"))
Expect(annotations[util.CidrAnnotation]).To(Equal(subnet.Spec.CIDRBlock))
Expect(annotations[util.GatewayAnnotation]).To(Equal(subnet.Spec.Gateway))
Expect(annotations[util.IpAddressAnnotation]).NotTo(BeEmpty())
Expect(util.CIDRContainIP(annotations[util.CidrAnnotation], annotations[util.IpAddressAnnotation])).To(BeTrue())
Expect(annotations[util.MacAddressAnnotation]).NotTo(BeEmpty())
Expect(annotations[util.PortNameAnnotation]).NotTo(BeEmpty())
Expect(annotations[util.LogicalSwitchAnnotation]).To(Equal(subnet.Name))
}
})
})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment