mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 18:02:01 +00:00
Cleanup statefulset after e2e test
This commit is contained in:
parent
392cd5ce8c
commit
8924b58e2c
@ -1349,35 +1349,48 @@ var _ = SIGDescribe("StatefulSet", func() {
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.It("PVC should be recreated when pod is pending due to missing PVC [Disruptive][Serial]", func() {
|
||||
ssName := "test-ss"
|
||||
headlessSvcName := "test"
|
||||
// Define StatefulSet Labels
|
||||
ssPodLabels := map[string]string{
|
||||
"name": "sample-pod",
|
||||
"pod": WebserverImageName,
|
||||
ginkgo.Describe("Automatically recreate PVC for pending pod when PVC is missing", func() {
|
||||
ssName := "ss"
|
||||
labels := map[string]string{
|
||||
"foo": "bar",
|
||||
"baz": "blah",
|
||||
}
|
||||
headlessSvcName := "test"
|
||||
var statefulPodMounts []v1.VolumeMount
|
||||
var ss *appsv1.StatefulSet
|
||||
|
||||
readyNode, err := e2enode.GetReadySchedulableWorkerNode(c)
|
||||
ginkgo.BeforeEach(func(ctx context.Context) {
|
||||
statefulPodMounts = []v1.VolumeMount{{Name: "datadir", MountPath: "/data/"}}
|
||||
ss = e2estatefulset.NewStatefulSet(ssName, ns, headlessSvcName, 1, statefulPodMounts, nil, labels)
|
||||
})
|
||||
|
||||
ginkgo.AfterEach(func(ctx context.Context) {
|
||||
if ginkgo.CurrentSpecReport().Failed() {
|
||||
e2eoutput.DumpDebugInfo(ctx, c, ns)
|
||||
}
|
||||
framework.Logf("Deleting all statefulset in ns %v", ns)
|
||||
e2estatefulset.DeleteAllStatefulSets(ctx, c, ns)
|
||||
})
|
||||
|
||||
ginkgo.It("PVC should be recreated when pod is pending due to missing PVC [Disruptive][Serial]", func(ctx context.Context) {
|
||||
e2epv.SkipIfNoDefaultStorageClass(ctx, c)
|
||||
|
||||
readyNode, err := e2enode.GetRandomReadySchedulableNode(ctx, c)
|
||||
framework.ExpectNoError(err)
|
||||
hostLabel := "kubernetes.io/hostname"
|
||||
hostLabelVal := readyNode.Labels[hostLabel]
|
||||
|
||||
statefulPodMounts := []v1.VolumeMount{{Name: "datadir", MountPath: "/data/"}}
|
||||
ss := e2estatefulset.NewStatefulSet(ssName, ns, headlessSvcName, 1, statefulPodMounts, nil, ssPodLabels)
|
||||
ss.Spec.Template.Spec.NodeSelector = map[string]string{hostLabel: hostLabelVal} // force the pod on a specific node
|
||||
|
||||
e2epv.SkipIfNoDefaultStorageClass(c)
|
||||
ginkgo.By("Creating statefulset " + ssName + " in namespace " + ns)
|
||||
_, err = c.AppsV1().StatefulSets(ns).Create(context.TODO(), ss, metav1.CreateOptions{})
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
ginkgo.By("Confirming PVC exists")
|
||||
err = verifyStatefulSetPVCsExist(c, ss, []int{0})
|
||||
err = verifyStatefulSetPVCsExist(ctx, c, ss, []int{0})
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
ginkgo.By("Confirming Pod is ready")
|
||||
e2estatefulset.WaitForStatusReadyReplicas(c, ss, 1)
|
||||
e2estatefulset.WaitForStatusReadyReplicas(ctx, c, ss, 1)
|
||||
podName := getStatefulSetPodNameAtIndex(0, ss)
|
||||
pod, err := c.CoreV1().Pods(ns).Get(context.TODO(), podName, metav1.GetOptions{})
|
||||
framework.ExpectNoError(err)
|
||||
@ -1434,16 +1447,17 @@ var _ = SIGDescribe("StatefulSet", func() {
|
||||
cordoned = false
|
||||
|
||||
ginkgo.By("Confirming PVC recreated")
|
||||
err = verifyStatefulSetPVCsExist(c, ss, []int{0})
|
||||
err = verifyStatefulSetPVCsExist(ctx, c, ss, []int{0})
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
ginkgo.By("Confirming Pod is ready after being recreated")
|
||||
e2estatefulset.WaitForStatusReadyReplicas(c, ss, 1)
|
||||
e2estatefulset.WaitForStatusReadyReplicas(ctx, c, ss, 1)
|
||||
pod, err = c.CoreV1().Pods(ns).Get(context.TODO(), podName, metav1.GetOptions{})
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqual(pod.Spec.NodeName, readyNode.Name) // confirm the pod was scheduled back to the original node
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
func uncordonNode(c clientset.Interface, oldData, newData []byte, nodeName string) {
|
||||
ginkgo.By("Uncordoning Node")
|
||||
|
Loading…
Reference in New Issue
Block a user