mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
PVC Protection E2E Tests for Failed Scheduling
The PR [2] introduced a change into a scheduler that causes that scheduling of pods that use PVC that is being deleted fail. That's why E2E test for the PR [2] is added. This E2E test also addresses the review comment [1]. [1] https://github.com/kubernetes/kubernetes/pull/56931#pullrequestreview-82564849 [2] https://github.com/kubernetes/kubernetes/pull/55957
This commit is contained in:
parent
d2be1ebb5f
commit
52a43b19d8
@ -926,6 +926,26 @@ func CreateClientPod(c clientset.Interface, ns string, pvc *v1.PersistentVolumeC
|
|||||||
return CreatePod(c, ns, nil, []*v1.PersistentVolumeClaim{pvc}, true, "")
|
return CreatePod(c, ns, nil, []*v1.PersistentVolumeClaim{pvc}, true, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateUnschedulablePod with given claims based on node selector
|
||||||
|
func CreateUnschedulablePod(client clientset.Interface, namespace string, nodeSelector map[string]string, pvclaims []*v1.PersistentVolumeClaim, isPrivileged bool, command string) (*v1.Pod, error) {
|
||||||
|
pod := MakePod(namespace, nodeSelector, pvclaims, isPrivileged, command)
|
||||||
|
pod, err := client.CoreV1().Pods(namespace).Create(pod)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("pod Create API error: %v", err)
|
||||||
|
}
|
||||||
|
// Waiting for pod to become Unschedulable
|
||||||
|
err = WaitForPodNameUnschedulableInNamespace(client, pod.Name, namespace)
|
||||||
|
if err != nil {
|
||||||
|
return pod, fmt.Errorf("pod %q is not Unschedulable: %v", pod.Name, err)
|
||||||
|
}
|
||||||
|
// get fresh pod info
|
||||||
|
pod, err = client.CoreV1().Pods(namespace).Get(pod.Name, metav1.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return pod, fmt.Errorf("pod Get API error: %v", err)
|
||||||
|
}
|
||||||
|
return pod, nil
|
||||||
|
}
|
||||||
|
|
||||||
// wait until all pvcs phase set to bound
|
// wait until all pvcs phase set to bound
|
||||||
func WaitForPVClaimBoundPhase(client clientset.Interface, pvclaims []*v1.PersistentVolumeClaim, timeout time.Duration) ([]*v1.PersistentVolume, error) {
|
func WaitForPVClaimBoundPhase(client clientset.Interface, pvclaims []*v1.PersistentVolumeClaim, timeout time.Duration) ([]*v1.PersistentVolume, error) {
|
||||||
persistentvolumes := make([]*v1.PersistentVolume, len(pvclaims))
|
persistentvolumes := make([]*v1.PersistentVolume, len(pvclaims))
|
||||||
|
@ -1547,6 +1547,28 @@ func WaitForPodToDisappear(c clientset.Interface, ns, podName string, label labe
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WaitForPodNameUnschedulableInNamespace returns an error if it takes too long for the pod to become Pending
|
||||||
|
// and have condition Status equal to Unschedulable,
|
||||||
|
// if the pod Get api returns an error (IsNotFound or other), or if the pod failed with an unexpected reason.
|
||||||
|
// Typically called to test that the passed-in pod is Pending and Unschedulable.
|
||||||
|
func WaitForPodNameUnschedulableInNamespace(c clientset.Interface, podName, namespace string) error {
|
||||||
|
return WaitForPodCondition(c, namespace, podName, "Unschedulable", PodStartTimeout, func(pod *v1.Pod) (bool, error) {
|
||||||
|
// Only consider Failed pods. Successful pods will be deleted and detected in
|
||||||
|
// waitForPodCondition's Get call returning `IsNotFound`
|
||||||
|
if pod.Status.Phase == v1.PodPending {
|
||||||
|
for _, cond := range pod.Status.Conditions {
|
||||||
|
if cond.Type == v1.PodScheduled && cond.Status == v1.ConditionFalse && cond.Reason == "Unschedulable" {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if pod.Status.Phase == v1.PodRunning || pod.Status.Phase == v1.PodSucceeded || pod.Status.Phase == v1.PodFailed {
|
||||||
|
return true, fmt.Errorf("Expected pod %q in namespace %q to be in phase Pending, but got phase: %v", podName, namespace, pod.Status.Phase)
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// WaitForService waits until the service appears (exist == true), or disappears (exist == false)
|
// WaitForService waits until the service appears (exist == true), or disappears (exist == false)
|
||||||
func WaitForService(c clientset.Interface, namespace, name string, exist bool, interval, timeout time.Duration) error {
|
func WaitForService(c clientset.Interface, namespace, name string, exist bool, interval, timeout time.Duration) error {
|
||||||
err := wait.PollImmediate(interval, timeout, func() (bool, error) {
|
err := wait.PollImmediate(interval, timeout, func() (bool, error) {
|
||||||
@ -5119,8 +5141,8 @@ func waitForServerPreferredNamespacedResources(d discovery.DiscoveryInterface, t
|
|||||||
return resources, nil
|
return resources, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitForPersistentVolumeClaimBeRemoved waits for a PersistentVolumeClaim to be removed from the system until timeout occurs, whichever comes first.
|
// WaitForPersistentVolumeClaimDeleted waits for a PersistentVolumeClaim to be removed from the system until timeout occurs, whichever comes first.
|
||||||
func WaitForPersistentVolumeClaimBeRemoved(c clientset.Interface, ns string, pvcName string, Poll, timeout time.Duration) error {
|
func WaitForPersistentVolumeClaimDeleted(c clientset.Interface, ns string, pvcName string, Poll, timeout time.Duration) error {
|
||||||
Logf("Waiting up to %v for PersistentVolumeClaim %s to be removed", timeout, pvcName)
|
Logf("Waiting up to %v for PersistentVolumeClaim %s to be removed", timeout, pvcName)
|
||||||
for start := time.Now(); time.Since(start) < timeout; time.Sleep(Poll) {
|
for start := time.Now(); time.Since(start) < timeout; time.Sleep(Poll) {
|
||||||
_, err := c.CoreV1().PersistentVolumeClaims(ns).Get(pvcName, metav1.GetOptions{})
|
_, err := c.CoreV1().PersistentVolumeClaims(ns).Get(pvcName, metav1.GetOptions{})
|
||||||
|
@ -76,7 +76,7 @@ var _ = utils.SIGDescribe("PVC Protection [Feature:PVCProtection]", func() {
|
|||||||
By("Deleting the PVC")
|
By("Deleting the PVC")
|
||||||
err = client.CoreV1().PersistentVolumeClaims(pvc.Namespace).Delete(pvc.Name, metav1.NewDeleteOptions(0))
|
err = client.CoreV1().PersistentVolumeClaims(pvc.Namespace).Delete(pvc.Name, metav1.NewDeleteOptions(0))
|
||||||
Expect(err).NotTo(HaveOccurred(), "Error deleting PVC")
|
Expect(err).NotTo(HaveOccurred(), "Error deleting PVC")
|
||||||
framework.WaitForPersistentVolumeClaimBeRemoved(client, pvc.Namespace, pvc.Name, framework.Poll, framework.ClaimProvisionTimeout)
|
framework.WaitForPersistentVolumeClaimDeleted(client, pvc.Namespace, pvc.Name, framework.Poll, framework.ClaimProvisionTimeout)
|
||||||
pvcCreatedAndNotDeleted = false
|
pvcCreatedAndNotDeleted = false
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -100,7 +100,44 @@ var _ = utils.SIGDescribe("PVC Protection [Feature:PVCProtection]", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred(), "Error terminating and deleting pod")
|
Expect(err).NotTo(HaveOccurred(), "Error terminating and deleting pod")
|
||||||
|
|
||||||
By("Checking that the PVC is automatically removed from the system because it's no longer in active use by a pod")
|
By("Checking that the PVC is automatically removed from the system because it's no longer in active use by a pod")
|
||||||
framework.WaitForPersistentVolumeClaimBeRemoved(client, pvc.Namespace, pvc.Name, framework.Poll, framework.ClaimProvisionTimeout)
|
framework.WaitForPersistentVolumeClaimDeleted(client, pvc.Namespace, pvc.Name, framework.Poll, framework.ClaimProvisionTimeout)
|
||||||
|
pvcCreatedAndNotDeleted = false
|
||||||
|
})
|
||||||
|
|
||||||
|
It("Verify that scheduling of a pod that uses PVC that is being deleted fails and the pod becomes Unschedulable", func() {
|
||||||
|
By("Creating first Pod that becomes Running and therefore is actively using the PVC")
|
||||||
|
pvcClaims := []*v1.PersistentVolumeClaim{pvc}
|
||||||
|
firstPod, err := framework.CreatePod(client, nameSpace, nil, pvcClaims, false, "")
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "While creating pod that uses the PVC or waiting for the Pod to become Running")
|
||||||
|
|
||||||
|
By("Deleting the PVC, however, the PVC must not be removed from the system as it's in active use by a pod")
|
||||||
|
err = client.CoreV1().PersistentVolumeClaims(pvc.Namespace).Delete(pvc.Name, metav1.NewDeleteOptions(0))
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "Error deleting PVC")
|
||||||
|
|
||||||
|
By("Checking that the PVC status is Terminating")
|
||||||
|
pvc, err = client.CoreV1().PersistentVolumeClaims(pvc.Namespace).Get(pvc.Name, metav1.GetOptions{})
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "While checking PVC status")
|
||||||
|
Expect(pvc.ObjectMeta.DeletionTimestamp).NotTo(Equal(nil))
|
||||||
|
|
||||||
|
By("Creating second Pod whose scheduling fails because it uses a PVC that is being deleted")
|
||||||
|
secondPod, err2 := framework.CreateUnschedulablePod(client, nameSpace, nil, pvcClaims, false, "")
|
||||||
|
Expect(err2).NotTo(HaveOccurred(), "While creating second pod that uses a PVC that is being deleted and that is Unschedulable")
|
||||||
|
|
||||||
|
By("Deleting the second pod that uses the PVC that is being deleted")
|
||||||
|
err = framework.DeletePodWithWait(f, client, secondPod)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "Error terminating and deleting pod")
|
||||||
|
|
||||||
|
By("Checking again that the PVC status is Terminating")
|
||||||
|
pvc, err = client.CoreV1().PersistentVolumeClaims(pvc.Namespace).Get(pvc.Name, metav1.GetOptions{})
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "While checking PVC status")
|
||||||
|
Expect(pvc.ObjectMeta.DeletionTimestamp).NotTo(Equal(nil))
|
||||||
|
|
||||||
|
By("Deleting the first pod that uses the PVC")
|
||||||
|
err = framework.DeletePodWithWait(f, client, firstPod)
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "Error terminating and deleting pod")
|
||||||
|
|
||||||
|
By("Checking that the PVC is automatically removed from the system because it's no longer in active use by a pod")
|
||||||
|
framework.WaitForPersistentVolumeClaimDeleted(client, pvc.Namespace, pvc.Name, framework.Poll, framework.ClaimProvisionTimeout)
|
||||||
pvcCreatedAndNotDeleted = false
|
pvcCreatedAndNotDeleted = false
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user