Skip to content

Commit

Permalink
e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Karol Szwaj <[email protected]>
  • Loading branch information
cnvergence committed Dec 6, 2024
1 parent 1c39f16 commit 0d232b9
Showing 1 changed file with 55 additions and 45 deletions.
100 changes: 55 additions & 45 deletions test/e2e/kube-ovn/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,51 +178,6 @@ var _ = framework.Describe("[group:ipam]", func() {
framework.ExpectConsistOf(util.PodIPs(pod), strings.Split(pod.Annotations[util.IPAddressAnnotation], ","))
}
})
framework.ConformanceIt("should allocate IPs from namespace IPPool annotation for deployment without IPPool annotation", func() {
ippoolSep := ","
replicas := 3
ippool := framework.RandomIPs(cidr, ippoolSep, replicas)
newNamespaceName := "test-namespace"
deployName := "test-deployment"
newDc := framework.NewDeploymentClient(cs, newNamespaceName)

ginkgo.By("Creating namespace " + namespaceName)
nsAnnotations := map[string]string{
util.IPPoolAnnotation: ippool,
}
ns := framework.MakeNamespace(newNamespaceName, nil, nsAnnotations)
nsClient.Create(ns)

ginkgo.By("Creating subnet " + subnetName)
cidr = framework.RandomCIDR(f.ClusterIPFamily)
newSubnet := framework.MakeSubnet(subnetName, "", cidr, "", "", "", nil, nil, []string{newNamespaceName})
newSubnet = subnetClient.CreateSync(subnet)

ginkgo.By("Creating deployment " + deployName + " without IPPool")
labels := map[string]string{"app": deployName}
deploy := framework.MakeDeployment(deployName, int32(replicas), labels, nil, "pause", framework.PauseImage, "")
deploy.ObjectMeta.Namespace = newNamespaceName
deploy = newDc.CreateSync(deploy)

ginkgo.By("Getting pods for deployment " + deployName)
pods, err := deployClient.GetPods(deploy)
framework.ExpectNoError(err, "failed to get pods for deployment "+deployName)
framework.ExpectHaveLen(pods.Items, replicas)

ips := strings.Split(ippool, ippoolSep)
for _, pod := range pods.Items {
framework.ExpectHaveKeyWithValue(pod.Annotations, util.AllocatedAnnotation, "true")
framework.ExpectHaveKeyWithValue(pod.Annotations, util.CidrAnnotation, newSubnet.Spec.CIDRBlock)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.GatewayAnnotation, newSubnet.Spec.Gateway)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.IPPoolAnnotation, ippool)
framework.ExpectContainElement(ips, pod.Annotations[util.IPAddressAnnotation])
framework.ExpectHaveKeyWithValue(pod.Annotations, util.LogicalSwitchAnnotation, newSubnet.Name)
framework.ExpectMAC(pod.Annotations[util.MacAddressAnnotation])
framework.ExpectHaveKeyWithValue(pod.Annotations, util.RoutedAnnotation, "true")

framework.ExpectConsistOf(util.PodIPs(pod), strings.Split(pod.Annotations[util.IPAddressAnnotation], ","))
}
})

framework.ConformanceIt("should allocate static ip for statefulset", func() {
replicas := 3
Expand Down Expand Up @@ -554,4 +509,59 @@ var _ = framework.Describe("[group:ipam]", func() {
deploy = deployClient.PatchSync(deploy, patchedDeploy)
checkFn()
})

framework.ConformanceIt("should allocate IPs from namespace IPPool annotation for deployment without IPPool annotation", func() {
replicas := 3
ipsCount := 12
ips1 := framework.RandomIPPool(cidr, ipsCount)
ips2 := framework.RandomIPPool(cidr, ipsCount)
newNamespaceName := "test-namespace"
deployName := "test-deployment"
ipPoolSubnetName := "ip-pool-subnet"
newDc := framework.NewDeploymentClient(cs, newNamespaceName)

ginkgo.By("Creating namespace " + namespaceName)
ns := framework.MakeNamespace(newNamespaceName, nil, nil)
nsClient.Create(ns)

ginkgo.By("Creating subnet " + subnetName)
cidr1 := framework.RandomCIDR(f.ClusterIPFamily)
cidr2 := framework.RandomCIDR(f.ClusterIPFamily)

subnet1 := framework.MakeSubnet(subnetName, "", cidr1, "", "", "", nil, nil, []string{newNamespaceName})
subnet2 := framework.MakeSubnet(subnetName, "", cidr2, "", "", "", nil, nil, []string{newNamespaceName})
subnetClient.CreateSync(subnet1)
subnetClient.CreateSync(subnet2)

ginkgo.By("Creating IPPool resources ")
ippool1 := framework.MakeIPPool("ippool1", ipPoolSubnetName, ips1, []string{newNamespaceName})
ippool2 := framework.MakeIPPool("ippool2", subnetName, ips2, []string{newNamespaceName})
ippoolClient.CreateSync(ippool1)
ippoolClient.CreateSync(ippool2)

ginkgo.By("Creating deployment " + deployName + " without IPPool")
labels := map[string]string{"app": deployName}
deploy := framework.MakeDeployment(deployName, int32(replicas), labels, nil, "pause", framework.PauseImage, "")
deploy.ObjectMeta.Namespace = newNamespaceName
newDc.CreateSync(deploy)

ginkgo.By("Getting pods for deployment " + deployName)
pods, err := deployClient.GetPods(deploy)
framework.ExpectNoError(err, "failed to get pods for deployment "+deployName)
framework.ExpectHaveLen(pods.Items, replicas)

for _, pod := range pods.Items {
framework.ExpectHaveKeyWithValue(pod.Annotations, util.AllocatedAnnotation, "true")
framework.ExpectHaveKeyWithValue(pod.Annotations, util.CidrAnnotation, subnet1.Spec.CIDRBlock)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.GatewayAnnotation, subnet1.Spec.Gateway)
framework.ExpectHaveKeyWithValue(pod.Annotations, util.IPPoolAnnotation, ippool1)
framework.ExpectContainElement(ips1, pod.Annotations[util.IPAddressAnnotation])
framework.ExpectHaveKeyWithValue(pod.Annotations, util.LogicalSwitchAnnotation, subnet1.Name)
framework.ExpectMAC(pod.Annotations[util.MacAddressAnnotation])
framework.ExpectHaveKeyWithValue(pod.Annotations, util.RoutedAnnotation, "true")

framework.ExpectConsistOf(util.PodIPs(pod), strings.Split(pod.Annotations[util.IPAddressAnnotation], ","))
}

})
})

0 comments on commit 0d232b9

Please sign in to comment.