From 9de354034b9ea3a7921da3cac3eafb03b8872ab4 Mon Sep 17 00:00:00 2001 From: Jing Xu Date: Wed, 17 Oct 2018 14:19:04 -0700 Subject: [PATCH] Make sure kubelet is restarted in the storage test In some storage tests, kubelet is stopped first and the test check node NotReady state. However, if it fails to have this state, kubelet could not be restarted because the defer function is placed after the stop kubelet command. This PR fixes this issue. --- test/e2e/storage/utils/utils.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/e2e/storage/utils/utils.go b/test/e2e/storage/utils/utils.go index fac42ba9159..c6cd4e8a3b0 100644 --- a/test/e2e/storage/utils/utils.go +++ b/test/e2e/storage/utils/utils.go @@ -220,13 +220,13 @@ func TestVolumeUnmountsFromDeletedPodWithForceOption(c clientset.Interface, f *f Expect(result.Code).To(BeZero(), fmt.Sprintf("Expected grep exit code of 0, got %d", result.Code)) } + // This command is to make sure kubelet is started after test finishes no matter it fails or not. + defer func() { + KubeletCommand(KStart, c, clientPod) + }() By("Stopping the kubelet.") KubeletCommand(KStop, c, clientPod) - defer func() { - if err != nil { - KubeletCommand(KStart, c, clientPod) - } - }() + By(fmt.Sprintf("Deleting Pod %q", clientPod.Name)) if forceDelete { err = c.CoreV1().Pods(clientPod.Namespace).Delete(clientPod.Name, metav1.NewDeleteOptions(0))