mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-05 04:55:22 +00:00
check pod status before hook (#5211)
Signed-off-by: cleverhu <shouping.hu@daocloud.io> Co-authored-by: cleverhu <shouping.hu@daocloud.io>
This commit is contained in:
1
changelogs/unreleased/5211-cleverhu
Normal file
1
changelogs/unreleased/5211-cleverhu
Normal file
@@ -0,0 +1 @@
|
||||
fix run preHook and postHook on completed pods
|
||||
@@ -123,6 +123,12 @@ func (e *defaultPodCommandExecutor) ExecutePodCommand(log logrus.FieldLogger, it
|
||||
"hookTimeout": localHook.Timeout,
|
||||
},
|
||||
)
|
||||
|
||||
if pod.Status.Phase == corev1api.PodSucceeded || pod.Status.Phase == corev1api.PodFailed {
|
||||
hookLog.Infof("Pod entered phase %s before some post-backup exec hooks ran", pod.Status.Phase)
|
||||
return nil
|
||||
}
|
||||
|
||||
hookLog.Info("running exec hook")
|
||||
|
||||
req := e.restClient.Post().
|
||||
|
||||
@@ -262,6 +262,37 @@ func TestEnsureContainerExists(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestPodCompeted(t *testing.T) {
|
||||
pod := &corev1api.Pod{
|
||||
Spec: corev1api.PodSpec{
|
||||
Containers: []corev1api.Container{
|
||||
{
|
||||
Name: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
Status: corev1api.PodStatus{
|
||||
Phase: corev1api.PodSucceeded,
|
||||
},
|
||||
}
|
||||
|
||||
obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(pod)
|
||||
require.NoError(t, err)
|
||||
|
||||
clientConfig := &rest.Config{}
|
||||
poster := &mockPoster{}
|
||||
defer poster.AssertExpectations(t)
|
||||
podCommandExecutor := NewPodCommandExecutor(clientConfig, poster).(*defaultPodCommandExecutor)
|
||||
|
||||
hook := v1.ExecHook{
|
||||
Container: "foo",
|
||||
Command: []string{"some", "command"},
|
||||
}
|
||||
|
||||
err = podCommandExecutor.ExecutePodCommand(velerotest.NewLogger(), obj, "namespace", "name", "hookName", &hook)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
type mockStreamExecutorFactory struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user