-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix(executor): Handle sidecar killing in a process-namespace-shared pod #4575
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2ac86c3
fix(executor): Handle sidecar killing in a process-namespace-shared pod
dtaniwaki 471ff8c
Merge branch 'master' into handle-sigterm-failure
dtaniwaki 7ef21b1
Add executor commont test
dtaniwaki 14fe1e5
Merge branch 'master' into handle-sigterm-failure
dtaniwaki 3b82e03
Merge branch 'master' into handle-sigterm-failure
alexec a5165af
Merge branch 'master' into handle-sigterm-failure
alexec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package common | ||
|
||
import ( | ||
"bytes" | ||
"syscall" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/utils/pointer" | ||
) | ||
|
||
type MockKC struct { | ||
getContainerStatusPod *v1.Pod | ||
getContainerStatusContainerStatus *v1.ContainerStatus | ||
getContainerStatusErr error | ||
killContainerError error | ||
} | ||
|
||
func (m *MockKC) GetContainerStatus(containerID string) (*v1.Pod, *v1.ContainerStatus, error) { | ||
return m.getContainerStatusPod, m.getContainerStatusContainerStatus, m.getContainerStatusErr | ||
} | ||
|
||
func (m *MockKC) KillContainer(pod *v1.Pod, container *v1.ContainerStatus, sig syscall.Signal) error { | ||
return m.killContainerError | ||
} | ||
|
||
func (*MockKC) CreateArchive(containerID, sourcePath string) (*bytes.Buffer, error) { | ||
return nil, nil | ||
} | ||
|
||
// TestScriptTemplateWithVolume ensure we can a script pod with input artifacts | ||
func TestTerminatePodWithContainerID(t *testing.T) { | ||
// Already terminated. | ||
mock := &MockKC{ | ||
getContainerStatusContainerStatus: &v1.ContainerStatus{ | ||
State: v1.ContainerState{ | ||
Terminated: &v1.ContainerStateTerminated{}, | ||
}, | ||
}, | ||
} | ||
err := TerminatePodWithContainerID(mock, "container-id", syscall.SIGTERM) | ||
assert.NoError(t, err) | ||
|
||
// w/ ShareProcessNamespace. | ||
mock = &MockKC{ | ||
getContainerStatusPod: &v1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "foo", | ||
}, | ||
Spec: v1.PodSpec{ | ||
ShareProcessNamespace: pointer.BoolPtr(true), | ||
}, | ||
}, | ||
getContainerStatusContainerStatus: &v1.ContainerStatus{ | ||
State: v1.ContainerState{ | ||
Terminated: nil, | ||
}, | ||
}, | ||
} | ||
err = TerminatePodWithContainerID(mock, "container-id", syscall.SIGTERM) | ||
assert.EqualError(t, err, "cannot terminate a process-namespace-shared Pod foo") | ||
|
||
// w/ HostPID. | ||
mock = &MockKC{ | ||
getContainerStatusPod: &v1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "foo", | ||
}, | ||
Spec: v1.PodSpec{ | ||
HostPID: true, | ||
}, | ||
}, | ||
getContainerStatusContainerStatus: &v1.ContainerStatus{ | ||
State: v1.ContainerState{ | ||
Terminated: nil, | ||
}, | ||
}, | ||
} | ||
err = TerminatePodWithContainerID(mock, "container-id", syscall.SIGTERM) | ||
assert.EqualError(t, err, "cannot terminate a hostPID Pod foo") | ||
|
||
// w/ RestartPolicy. | ||
mock = &MockKC{ | ||
getContainerStatusPod: &v1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "foo", | ||
}, | ||
Spec: v1.PodSpec{ | ||
RestartPolicy: "Always", | ||
}, | ||
}, | ||
getContainerStatusContainerStatus: &v1.ContainerStatus{ | ||
State: v1.ContainerState{ | ||
Terminated: nil, | ||
}, | ||
}, | ||
} | ||
err = TerminatePodWithContainerID(mock, "container-id", syscall.SIGTERM) | ||
assert.EqualError(t, err, "cannot terminate pod with a \"Always\" restart policy") | ||
|
||
// Successfully call KillContainer of the client interface. | ||
mock = &MockKC{ | ||
getContainerStatusPod: &v1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "foo", | ||
}, | ||
Spec: v1.PodSpec{ | ||
RestartPolicy: "Never", | ||
}, | ||
}, | ||
getContainerStatusContainerStatus: &v1.ContainerStatus{ | ||
State: v1.ContainerState{ | ||
Terminated: nil, | ||
}, | ||
}, | ||
} | ||
err = TerminatePodWithContainerID(mock, "container-id", syscall.SIGTERM) | ||
assert.NoError(t, err) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it immediately returns an error here, the wait container exit with
0
and the pod succeeds. It's also the same in other error returns in this method too. Was it expected behavior?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a unit test of this method. I think we should have e2e tests for all the executors. If we had, this functional test had found the problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have e2e smoke test for 3 of the executors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you're right. The problem occurs on the combination of k8sapi and
shareProcessNamespace
.