-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Check pod status before hook #5211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| fix run preHook and postHook on completed pods |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the late response, but after going through the code again, I think we may need to change the condition check from current status into something like this: if pod.Status.Phase != corev1api.PodRunning {
...
} |
||
| hookLog.Infof("Pod entered phase %s before some post-backup exec hooks ran", pod.Status.Phase) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code path also applies to pre-hooks as far as I can tell. |
||
| return nil | ||
| } | ||
|
|
||
| hookLog.Info("running exec hook") | ||
|
|
||
| req := e.restClient.Post(). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -262,6 +262,37 @@ func TestEnsureContainerExists(t *testing.T) { | |
| assert.NoError(t, err) | ||
| } | ||
|
|
||
| func TestPodCompeted(t *testing.T) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo |
||
| 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 | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.