Merge pull request #71429 from gnufied/fix-detach-while-mount-flake

Fix flake with e2e test that checks detach while mount in progress
pull/58/head
k8s-ci-robot 2018-11-26 16:57:21 -08:00 committed by GitHub
commit fad23990ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 0 deletions

View File

@ -84,10 +84,17 @@ var _ = utils.SIGDescribe("Detaching volumes", func() {
uniqueVolumeName := getUniqueVolumeName(pod, driverInstallAs)
By("waiting for volumes to be attached to node")
err = waitForVolumesAttached(cs, node.Name, uniqueVolumeName)
Expect(err).NotTo(HaveOccurred(), "while waiting for volume to attach to %s node", node.Name)
By("waiting for volume-in-use on the node after pod creation")
err = waitForVolumesInUse(cs, node.Name, uniqueVolumeName)
Expect(err).NotTo(HaveOccurred(), "while waiting for volume in use")
By("waiting for kubelet to start mounting the volume")
time.Sleep(20 * time.Second)
By("Deleting the flexvolume pod")
err = framework.DeletePodWithWait(f, cs, pod)
Expect(err).NotTo(HaveOccurred(), "in deleting the pod")
@ -134,6 +141,22 @@ func waitForVolumesNotInUse(client clientset.Interface, nodeName, volumeName str
})
}
func waitForVolumesAttached(client clientset.Interface, nodeName, volumeName string) error {
return wait.PollImmediate(2*time.Second, 2*time.Minute, func() (bool, error) {
node, err := client.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{})
if err != nil {
return false, fmt.Errorf("error fetching node %s with %v", nodeName, err)
}
volumeAttached := node.Status.VolumesAttached
for _, volume := range volumeAttached {
if string(volume.Name) == volumeName {
return true, nil
}
}
return false, nil
})
}
func waitForVolumesInUse(client clientset.Interface, nodeName, volumeName string) error {
return wait.PollImmediate(10*time.Second, 60*time.Second, func() (bool, error) {
node, err := client.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{})