// Clean both server and client pods. func volumeTestCleanup(f *framework.Framework, config VolumeTestConfig) { By(fmt.Sprint("cleaning the environment after ", config.prefix)) defer GinkgoRecover() client := f.Client podClient := client.Pods(config.namespace) err := podClient.Delete(config.prefix+"-client", nil) if err != nil { // Log the error before failing test: if the test has already failed, // framework.ExpectNoError() won't print anything to logs! glog.Warningf("Failed to delete client pod: %v", err) framework.ExpectNoError(err, "Failed to delete client pod: %v", err) } if config.serverImage != "" { if err := f.WaitForPodTerminated(config.prefix+"-client", ""); !apierrs.IsNotFound(err) { framework.ExpectNoError(err, "Failed to wait client pod terminated: %v", err) } // See issue #24100. // Prevent umount errors by making sure making sure the client pod exits cleanly *before* the volume server pod exits. By("sleeping a bit so client can stop and unmount") time.Sleep(20 * time.Second) err = podClient.Delete(config.prefix+"-server", nil) if err != nil { glog.Warningf("Failed to delete server pod: %v", err) framework.ExpectNoError(err, "Failed to delete server pod: %v", err) } } }
// Delete the passed in pod. func deletePod(f *framework.Framework, c *client.Client, ns string, pod *api.Pod) error { framework.Logf("Deleting pod %v", pod.Name) err := c.Pods(ns).Delete(pod.Name, nil) if err != nil { return fmt.Errorf("Pod %v encountered a delete error: %v", pod.Name, err) } // Wait for pod to terminate err = f.WaitForPodTerminated(pod.Name, "") if err != nil && !apierrs.IsNotFound(err) { return fmt.Errorf("Pod %v will not teminate: %v", pod.Name, err) } // Re-get the pod to double check that it has been deleted; expect err // Note: Get() writes a log error if the pod is not found _, err = c.Pods(ns).Get(pod.Name) if err == nil { return fmt.Errorf("Pod %v has been deleted but able to re-Get the deleted pod", pod.Name) } if !apierrs.IsNotFound(err) { return fmt.Errorf("Pod %v has been deleted but still exists: %v", pod.Name, err) } framework.Logf("Ignore \"not found\" error above. Pod %v successfully deleted", pod.Name) return nil }
// Delete the passed in pod. func deletePod(f *framework.Framework, c clientset.Interface, ns string, pod *v1.Pod) { framework.Logf("Deleting pod %v", pod.Name) err := c.Core().Pods(ns).Delete(pod.Name, nil) Expect(err).NotTo(HaveOccurred()) // Wait for pod to terminate. Expect apierr NotFound err = f.WaitForPodTerminated(pod.Name, "") Expect(err).To(HaveOccurred()) Expect(apierrs.IsNotFound(err)).To(BeTrue()) framework.Logf("Ignore \"not found\" error above. Pod %v successfully deleted", pod.Name) }
// Delete the passed in pod. func deletePod(f *framework.Framework, c clientset.Interface, ns string, pod *v1.Pod) { if c != nil { if pod != nil && len(pod.Name) > 0 { framework.Logf("Deleting pod %v", pod.Name) err := c.Core().Pods(ns).Delete(pod.Name, nil) if err != nil && !apierrs.IsNotFound(err) { Expect(err).NotTo(HaveOccurred()) } // Wait for pod to terminate. Expect apierr NotFound err = f.WaitForPodTerminated(pod.Name, "") if err != nil && !apierrs.IsNotFound(err) { Expect(err).NotTo(HaveOccurred()) } framework.Logf("Ignore \"not found\" error above. Pod %v successfully deleted", pod.Name) } } }