Skip to content

Commit

Permalink
update e2e testing
Browse files Browse the repository at this point in the history
1. add e2e testing for 3-master cluster;
2. add e2e testing for StatefulSet Pod force deletion.
  • Loading branch information
zhangzujian committed Mar 31, 2022
1 parent 60bf81a commit e369343
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 5 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/build-x86-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,24 @@ jobs:
command: |
sudo make kind-install
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.17
id: go

- name: Run E2E
run: |
go install github.com/onsi/ginkgo/ginkgo@latest
sudo kubectl cluster-info
sudo chmod 666 /home/runner/.kube/config
make e2e
- name: Cleanup
run: |
sh -c 'while :; do if [ $(kubectl get --no-headers subnet | wc -l) -eq 2 ]; then break; fi; sleep 5; done'
sh dist/images/cleanup.sh
ipv6-e2e:
needs: build
name: ipv6-e2e
Expand Down
6 changes: 3 additions & 3 deletions dist/images/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ done

for subnet in $(kubectl get subnet -o name); do
kubectl patch "$subnet" --type='json' -p '[{"op": "replace", "path": "/metadata/finalizers", "value": []}]'
kubectl delete "$subnet"
kubectl delete --ignore-not-found "$subnet"
done

for vlan in $(kubectl get vlan -o name); do
kubectl delete $vlan
kubectl delete --ignore-not-found $vlan
done

for pn in $(kubectl get provider-network -o name); do
kubectl delete $pn
kubectl delete --ignore-not-found $pn
done

sleep 5
Expand Down
69 changes: 69 additions & 0 deletions test/e2e/ip/static_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,74 @@ var _ = Describe("[IP Allocation]", func() {
err = f.KubeClientSet.AppsV1().StatefulSets(namespace).Delete(context.Background(), sts.Name, metav1.DeleteOptions{})
Expect(err).NotTo(HaveOccurred())
})

It("force delete statefulset pod", func() {
name := f.GetName()
var replicas int32 = 3
autoMount := false
sts := appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: map[string]string{"e2e": "true"},
},
Spec: appsv1.StatefulSetSpec{
Replicas: &replicas,
Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"apps": name}},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"apps": name,
"e2e": "true",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: name,
Image: testImage,
ImagePullPolicy: corev1.PullIfNotPresent,
},
},
AutomountServiceAccountToken: &autoMount,
},
},
},
}

By("Create statefulset")
_, err := f.KubeClientSet.AppsV1().StatefulSets(namespace).Create(context.Background(), &sts, metav1.CreateOptions{})
Expect(err).NotTo(HaveOccurred())

err = f.WaitStatefulsetReady(name, namespace)
Expect(err).NotTo(HaveOccurred())

ips := make([]string, replicas)
for i := range ips {
pod, err := f.KubeClientSet.CoreV1().Pods(namespace).Get(context.Background(), fmt.Sprintf("%s-%d", name, i), metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
ips[i] = pod.Status.PodIP
}

err = f.KubeClientSet.CoreV1().Pods(namespace).DeleteCollection(context.Background(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: labels.SelectorFromSet(sts.Spec.Template.Labels).String()})
Expect(err).NotTo(HaveOccurred())

err = f.WaitStatefulsetReady(name, namespace)
Expect(err).NotTo(HaveOccurred())
for i := range ips {
pod, err := f.KubeClientSet.CoreV1().Pods(namespace).Get(context.Background(), fmt.Sprintf("%s-%d", name, i), metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
Expect(pod.Status.PodIP).To(Equal(ips[i]))
}

By("Force delete statefulset Pod")
var gracePeriodSeconds int64
for i := 0; i < int(replicas); i++ {
err = f.KubeClientSet.CoreV1().Pods(namespace).Delete(context.Background(), fmt.Sprintf("%s-%d", name, i), metav1.DeleteOptions{GracePeriodSeconds: &gracePeriodSeconds})
Expect(err).NotTo(HaveOccurred())
}
err = f.WaitStatefulsetReady(name, namespace)
Expect(err).NotTo(HaveOccurred())
})
})
})
5 changes: 3 additions & 2 deletions test/e2e/underlay/underlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,10 @@ var _ = Describe("[Underlay]", func() {
Expect(err).NotTo(HaveOccurred())

By("validate OVN logical router port")
ovnPods, err := f.KubeClientSet.CoreV1().Pods("kube-system").List(context.Background(), metav1.ListOptions{LabelSelector: "app=ovn-central"})
ovnPods, err := f.KubeClientSet.CoreV1().Pods("kube-system").List(context.Background(), metav1.ListOptions{LabelSelector: "app=ovn-central,ovn-nb-leader=true"})
Expect(err).NotTo(HaveOccurred())
Expect(ovnPods).NotTo(BeNil())
Expect(ovnPods.Items).To(HaveLen(1))

ovnPod := ovnPods.Items[0]
lsp := fmt.Sprintf("%s-%s", name, util.DefaultVpc)
Expand Down Expand Up @@ -616,7 +617,7 @@ var _ = Describe("[Underlay]", func() {

By("create pods")
name := f.GetName()
pods := make([]*corev1.Pod, 2)
pods := make([]*corev1.Pod, len(nodes))
var autoMount bool
for i := range nodes {
pods[i] = &corev1.Pod{
Expand Down

0 comments on commit e369343

Please sign in to comment.