Commit 7707aac2 authored by Jeff Vance's avatar Jeff Vance

refactor pv code for readability

parent 1bbd9dfa
...@@ -74,6 +74,7 @@ go_library( ...@@ -74,6 +74,7 @@ go_library(
"portforward.go", "portforward.go",
"pre_stop.go", "pre_stop.go",
"proxy.go", "proxy.go",
"pvutil.go",
"rc.go", "rc.go",
"reboot.go", "reboot.go",
"replica_set.go", "replica_set.go",
......
...@@ -22,7 +22,6 @@ import ( ...@@ -22,7 +22,6 @@ import (
"strings" "strings"
"time" "time"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/uuid" "k8s.io/apimachinery/pkg/util/uuid"
...@@ -209,32 +208,6 @@ func createPodUsingNfs(f *framework.Framework, c clientset.Interface, ns, nfsIP, ...@@ -209,32 +208,6 @@ func createPodUsingNfs(f *framework.Framework, c clientset.Interface, ns, nfsIP,
return rtnPod return rtnPod
} }
// Deletes the passed-in pod and waits for the pod to be terminated. Resilient to the pod
// not existing.
func deletePodwithWait(f *framework.Framework, c clientset.Interface, pod *v1.Pod) {
if pod == nil {
return
}
framework.Logf("Deleting pod %v", pod.Name)
err := c.Core().Pods(pod.Namespace).Delete(pod.Name, nil)
if err != nil {
if apierrs.IsNotFound(err) {
return // assume pod was deleted already
}
Expect(err).NotTo(HaveOccurred())
}
// wait for pod to terminate. Expect apierr NotFound
err = f.WaitForPodTerminated(pod.Name, "")
Expect(err).To(HaveOccurred())
if !apierrs.IsNotFound(err) {
framework.Logf("Error! Expected IsNotFound error deleting pod %q, instead got: %v", pod.Name, err)
Expect(apierrs.IsNotFound(err)).To(BeTrue())
}
framework.Logf("Pod %v successfully deleted", pod.Name)
}
// Checks for a lingering nfs mount and/or uid directory on the pod's host. The host IP is used // Checks for a lingering nfs mount and/or uid directory on the pod's host. The host IP is used
// so that this test runs in GCE, where it appears that SSH cannot resolve the hostname. // so that this test runs in GCE, where it appears that SSH cannot resolve the hostname.
// If expectClean is true then we expect the node to be cleaned up and thus commands like // If expectClean is true then we expect the node to be cleaned up and thus commands like
...@@ -442,8 +415,8 @@ var _ = framework.KubeDescribe("kubelet", func() { ...@@ -442,8 +415,8 @@ var _ = framework.KubeDescribe("kubelet", func() {
}) })
AfterEach(func() { AfterEach(func() {
deletePodwithWait(f, c, pod) deletePodWithWait(f, c, pod)
deletePodwithWait(f, c, nfsServerPod) deletePodWithWait(f, c, nfsServerPod)
}) })
// execute It blocks from above table of tests // execute It blocks from above table of tests
...@@ -454,11 +427,11 @@ var _ = framework.KubeDescribe("kubelet", func() { ...@@ -454,11 +427,11 @@ var _ = framework.KubeDescribe("kubelet", func() {
pod = createPodUsingNfs(f, c, ns, nfsIP, t.podCmd) pod = createPodUsingNfs(f, c, ns, nfsIP, t.podCmd)
By("Delete the NFS server pod") By("Delete the NFS server pod")
deletePodwithWait(f, c, nfsServerPod) deletePodWithWait(f, c, nfsServerPod)
nfsServerPod = nil nfsServerPod = nil
By("Delete the pod mounted to the NFS volume") By("Delete the pod mounted to the NFS volume")
deletePodwithWait(f, c, pod) deletePodWithWait(f, c, pod)
// pod object is now stale, but is intentionally not nil // pod object is now stale, but is intentionally not nil
By("Check if host running deleted pod has been cleaned up -- expect not") By("Check if host running deleted pod has been cleaned up -- expect not")
......
...@@ -189,7 +189,7 @@ func testVolumeUnmountsFromDeletedPod(c clientset.Interface, f *framework.Framew ...@@ -189,7 +189,7 @@ func testVolumeUnmountsFromDeletedPod(c clientset.Interface, f *framework.Framew
By("Restarting the kubelet.") By("Restarting the kubelet.")
kubeletCommand(kStop, c, clientPod) kubeletCommand(kStop, c, clientPod)
deletePod(f, c, clientPod.Namespace, clientPod) deletePodWithWait(f, c, clientPod)
kubeletCommand(kStart, c, clientPod) kubeletCommand(kStart, c, clientPod)
By("Expecting the volume mount not to be found.") By("Expecting the volume mount not to be found.")
...@@ -222,7 +222,7 @@ func initTestCase(f *framework.Framework, c clientset.Interface, pvConfig persis ...@@ -222,7 +222,7 @@ func initTestCase(f *framework.Framework, c clientset.Interface, pvConfig persis
// tearDownTestCase destroy resources created by initTestCase. // tearDownTestCase destroy resources created by initTestCase.
func tearDownTestCase(c clientset.Interface, f *framework.Framework, ns string, pod *v1.Pod, pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume) { func tearDownTestCase(c clientset.Interface, f *framework.Framework, ns string, pod *v1.Pod, pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume) {
deletePod(f, c, ns, pod) deletePodWithWait(f, c, pod)
deletePersistentVolumeClaim(c, pvc.Name, ns) deletePersistentVolumeClaim(c, pvc.Name, ns)
deletePersistentVolume(c, pv.Name) deletePersistentVolume(c, pv.Name)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment