From 0d232b95b60ce49de3e5221081bdef7b3cd871b5 Mon Sep 17 00:00:00 2001 From: Karol Szwaj Date: Fri, 6 Dec 2024 16:47:01 +0100 Subject: [PATCH] e2e test Signed-off-by: Karol Szwaj --- test/e2e/kube-ovn/ipam/ipam.go | 100 ++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 45 deletions(-) diff --git a/test/e2e/kube-ovn/ipam/ipam.go b/test/e2e/kube-ovn/ipam/ipam.go index 8cec8f996fa..556483ebb6d 100644 --- a/test/e2e/kube-ovn/ipam/ipam.go +++ b/test/e2e/kube-ovn/ipam/ipam.go @@ -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 @@ -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], ",")) + } + + }) })