Skip to content

Commit

Permalink
add assign IP e2e
Browse files Browse the repository at this point in the history
Signed-off-by: Icarus9913 <icaruswu66@qq.com>
  • Loading branch information
Icarus9913 committed Dec 20, 2023
1 parent 60895d9 commit 9d01b9a
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 15 deletions.
24 changes: 12 additions & 12 deletions test/doc/assignip.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# E2E Cases for IP Assignment

| Case ID | Title | Priority | Smoke | Status | Other |
|---------|---------------------------------------------------------------------------------------------------------|----------|-------|--------|-------------|
| E00001 | Assign IP to a pod for ipv4, ipv6 and dual-stack case | p1 | true | done | |
| E00002 | Assign IP to deployment/pod for ipv4, ipv6 and dual-stack case | p1 | true | done | |
| E00003 | Assign IP to statefulSet/pod for ipv4, ipv6 and dual-stack case | p1 | true | done | |
| E00004 | Assign IP to daemonSet/pod for ipv4, ipv6 and dual-stack case | p1 | true | done | |
| E00005 | Assign IP to job/pod for ipv4, ipv6 and dual-stack case | p1 | true | done | |
| E00006 | Assign IP to replicaset/pod for ipv4, ipv6 and dual-stack case | p1 | true | done | |
| E00007 | Successfully run a pod with long yaml for ipv4, ipv6 and dual-stack case | p2 | | done | |
| E00008 | Failed to run a pod when IP resource of an IPPool is exhausted | p3 | | done | |
| E00009 | The cluster is dual stack, but the spiderpool only allocates ipv4 or ipv6, the pod should run correctly | p3 | | | |
| E00010 | The cluster is single stack, but the spiderpool allocates ipv4 and ipv6, the pod should run correctly | p3 | | | |
| Case ID | Title | Priority | Smoke | Status | Other |
|---------|-------------------------------------------------------------------------------------------------------|----------|-------|--------|-------------|
| E00001 | Assign IP to a pod for ipv4, ipv6 and dual-stack case | p1 | true | done | |
| E00002 | Assign IP to deployment/pod for ipv4, ipv6 and dual-stack case | p1 | true | done | |
| E00003 | Assign IP to statefulSet/pod for ipv4, ipv6 and dual-stack case | p1 | true | done | |
| E00004 | Assign IP to daemonSet/pod for ipv4, ipv6 and dual-stack case | p1 | true | done | |
| E00005 | Assign IP to job/pod for ipv4, ipv6 and dual-stack case | p1 | true | done | |
| E00006 | Assign IP to replicaset/pod for ipv4, ipv6 and dual-stack case | p1 | true | done | |
| E00007 | Successfully run a pod with long yaml for ipv4, ipv6 and dual-stack case | p2 | | done | |
| E00008 | Failed to run a pod when IP resource of an IPPool is exhausted | p3 | | done | |
| E00009 | The cluster is dual stack, but the spiderpool can allocates ipv4 or ipv6 only with IPPools annotation | p2 | | done | |
| E00010 | The cluster is dual stack, but the spiderpool can allocates ipv4 or ipv6 only with Subnet annotation | p2 | | done | |
81 changes: 78 additions & 3 deletions test/e2e/assignip/assignip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ package assignip_test

import (
"context"
"encoding/json"
"strings"

spiderpoolv2beta1 "github.com/spidernet-io/spiderpool/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/spidernet-io/e2eframework/tools"

"github.com/spidernet-io/spiderpool/pkg/constant"
spiderpoolv2beta1 "github.com/spidernet-io/spiderpool/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1"
"github.com/spidernet-io/spiderpool/pkg/types"
"github.com/spidernet-io/spiderpool/test/e2e/common"
corev1 "k8s.io/api/core/v1"
)

var _ = Describe("test pod", Label("assignip"), func() {

Context("fail to run a pod when IP resource of an ippool is exhausted or its IP been set excludeIPs", func() {
var deployName, v4PoolName, v6PoolName, namespace string
var v4PoolNameList, v6PoolNameList []string
Expand Down Expand Up @@ -157,5 +160,77 @@ var _ = Describe("test pod", Label("assignip"), func() {
Expect(frame.DeleteDeployment(deployName, namespace)).To(Succeed())
GinkgoWriter.Printf("Succeeded to delete deployment %v/%v \n", namespace, deployName)
})

It("The cluster is dual stack, but the spiderpool can allocates ipv4 or ipv6 only with IPPools annotation", Label("E00009"), func() {
if !(frame.Info.IpV4Enabled && frame.Info.IpV6Enabled) {
Skip("Single stack just skip this e2e case")
}

deployment := common.GenerateExampleDeploymentYaml(deployName, namespace, 1)
annotations := map[string]string{
constant.AnnoPodIPPool: common.GeneratePodIPPoolAnnotations(frame, "", []string{v4PoolObj.Name}, nil),
}
deployment.Spec.Template.Annotations = annotations
Expect(deployment).NotTo(BeNil(), "failed to generate Deployment yaml")

GinkgoWriter.Printf("Try to create deploy %v/%v \n", namespace, deployName)
Expect(frame.CreateDeployment(deployment)).To(Succeed())

// Checking the pod run status should all be running.
var podList *corev1.PodList
var err error
Eventually(func() bool {
podList, err = frame.GetPodListByLabel(deployment.Spec.Template.Labels)
if nil != err || len(podList.Items) == 0 {
return false
}
return frame.CheckPodListRunning(podList)
}, 2*common.PodStartTimeout, common.ForcedWaitingTime).Should(BeTrue())

Expect(podList.Items).To(HaveLen(1))
Expect(podList.Items[0].Status.PodIPs).To(HaveLen(1))
})

It("The cluster is dual stack, but the spiderpool can allocates ipv4 or ipv6 only with Subnet annotation", Label("E00010"), func() {
if !frame.Info.SpiderSubnetEnabled {
Skip("The SpiderSubnet feature is disabled, skip this e2e case")
}
if !(frame.Info.IpV4Enabled && frame.Info.IpV6Enabled) {
Skip("Single stack just skip this e2e case")
}

deployment := common.GenerateExampleDeploymentYaml(deployName, namespace, 1)

// Create deployments in bulk in a subnet
subnetAnno := types.AnnoSubnetItem{
IPv4: []string{v4SubnetName},
IPv6: nil,
}
subnetAnnoMarshal, err := json.Marshal(subnetAnno)
Expect(err).NotTo(HaveOccurred())

annotations := map[string]string{
constant.AnnoSpiderSubnet: string(subnetAnnoMarshal),
constant.AnnoSpiderSubnetPoolIPNumber: "1",
}
deployment.Spec.Template.Annotations = annotations
Expect(deployment).NotTo(BeNil(), "failed to generate Deployment yaml")

GinkgoWriter.Printf("Try to create deploy %v/%v \n", namespace, deployName)
Expect(frame.CreateDeployment(deployment)).To(Succeed())

// Checking the pod run status should all be running.
var podList *corev1.PodList
Eventually(func() bool {
podList, err = frame.GetPodListByLabel(deployment.Spec.Template.Labels)
if nil != err || len(podList.Items) == 0 {
return false
}
return frame.CheckPodListRunning(podList)
}, 2*common.PodStartTimeout, common.ForcedWaitingTime).Should(BeTrue())

Expect(podList.Items).To(HaveLen(1))
Expect(podList.Items[0].Status.PodIPs).To(HaveLen(1))
})
})
})

0 comments on commit 9d01b9a

Please sign in to comment.