Skip to content

Support PID NamespaceMode_TARGET#5203

Merged
mikebrow merged 2 commits intocontainerd:masterfrom
tghartland:5008-target-namespace
Apr 22, 2021
Merged

Support PID NamespaceMode_TARGET#5203
mikebrow merged 2 commits intocontainerd:masterfrom
tghartland:5008-target-namespace

Conversation

@tghartland
Copy link
Copy Markdown
Contributor

@tghartland tghartland commented Mar 15, 2021

Fixes #5008

As mentioned in the issue, support for the namespace mode TARGET is needed for debugging with kubernetes ephemeral containers. Kubernetes is already passing a TargetID, so containerd just needs to set up the new container with the existing PID namespace of the target container.

I'll need some guidance on these things:

  • Add unit tests.
  • Enforce that the new and target containers exist in the same pod?
  • Confirm the behaviour when the target container is not running (error?).
  • Anything else I might have missed.

And @verb I'd like you to take a look to ensure that this implementation matches what is expected by kubernetes.

@k8s-ci-robot
Copy link
Copy Markdown

Hi @tghartland. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Mar 15, 2021

Build succeeded.

@tghartland tghartland force-pushed the 5008-target-namespace branch from ea9a6b8 to 95beac7 Compare March 16, 2021 13:41
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Mar 16, 2021

Build succeeded.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Mar 16, 2021

Build succeeded.

@tghartland tghartland changed the title WIP: Support PID NamespaceMode_TARGET Support PID NamespaceMode_TARGET Mar 25, 2021
@tghartland
Copy link
Copy Markdown
Contributor Author

@AkihiroSuda or @estesp, can either of you review this when you have time?

@verb
Copy link
Copy Markdown

verb commented Apr 13, 2021

@tghartland This looks to me like the behavior Kubernetes expects. Thanks for implementing this!

@dims
Copy link
Copy Markdown
Member

dims commented Apr 18, 2021

cc @mikebrow

@dmcgowan could we get this into 1.5.0 please? will help with kubectl debug with --target scenario ( see kubernetes/kubernetes#101074 )

@dims
Copy link
Copy Markdown
Member

dims commented Apr 18, 2021

/ok-to-test

@dims dims requested review from Random-Liu and mxpv and removed request for Random-Liu April 18, 2021 20:28
@dims dims added this to the 1.5 milestone Apr 18, 2021
@dims
Copy link
Copy Markdown
Member

dims commented Apr 18, 2021

@mikebrow @dmcgowan please feel free to move the milestone if 1.5.0 is not appropriate.

@AkihiroSuda AkihiroSuda requested a review from mikebrow April 20, 2021 16:03
@AkihiroSuda AkihiroSuda requested a review from dmcgowan April 20, 2021 16:04
Copy link
Copy Markdown
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments.. Cheers!

Comment thread pkg/cri/server/container_create_linux.go Outdated
@mikebrow
Copy link
Copy Markdown
Member

Oh hey, I see this is your first contribution. Welcome aboard!

@fuweid
Copy link
Copy Markdown
Member

fuweid commented Apr 21, 2021

Confirm the behaviour when the target container is not running (error?)

Would you mind to add the checker before start like what normal container does? I am worry about pid resue here :p

The checker doesn't prevent anything but it can lower the possibility.

REF: https://github.com/containerd/containerd/blob/master/pkg/cri/server/container_start.go#L83

@tghartland tghartland force-pushed the 5008-target-namespace branch from f4668bd to 6880528 Compare April 21, 2021 08:22
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Apr 21, 2021

Build succeeded.

@tghartland tghartland force-pushed the 5008-target-namespace branch from 6880528 to 101d1bf Compare April 21, 2021 15:02
@mikebrow
Copy link
Copy Markdown
Member

Confirm the behaviour when the target container is not running (error?)

Would you mind to add the checker before start like what normal container does? I am worry about pid resue here :p
The checker doesn't prevent anything but it can lower the possibility.
REF: https://github.com/containerd/containerd/blob/master/pkg/cri/server/container_start.go#L83

And keep the same check where it is now?
Or should it be valid to create a container, then create a container targeting that container, and finally start both containers? (As long as the target container is started first).

After a quick check of the code for the feature... I see that it needs to be checked/verified at least on create. And I agree with @fuweid that it should also be checked/verified before doing the start for the created debug container.

@tghartland
Copy link
Copy Markdown
Contributor Author

tghartland commented Apr 21, 2021

Pushed changes:

  • Moved the validation checks for the target container into a function in pkg/cri/server/helpers.go
    • Check that the target container exists, that it is in the same sandbox as the new container, and that it is running.
  • Check the target validity when creating the container, and recheck when starting the container.
  • Moved the unit test to helpers_test.go and adapted it slightly to test the validation function.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Apr 21, 2021

Build succeeded.

Comment thread pkg/cri/server/helpers.go Outdated
Comment thread pkg/cri/server/helpers.go Outdated
Comment thread pkg/cri/server/helpers.go Outdated
@tghartland tghartland force-pushed the 5008-target-namespace branch from 101d1bf to 2fc5a50 Compare April 21, 2021 15:19
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Apr 21, 2021

Build succeeded.

@tghartland tghartland force-pushed the 5008-target-namespace branch from 2fc5a50 to f5d43ad Compare April 21, 2021 15:36
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Apr 21, 2021

Build succeeded.

This commit adds support for the PID namespace mode TARGET
when generating a container spec.

The container that is created will be sharing its PID namespace
with the target container that was specified by ID in the namespace
options.

Signed-off-by: Thomas Hartland <[email protected]>
@tghartland tghartland force-pushed the 5008-target-namespace branch from f5d43ad to 7f3f632 Compare April 21, 2021 15:55
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Apr 21, 2021

Build succeeded.

Copy link
Copy Markdown
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mikebrow
Copy link
Copy Markdown
Member

mikebrow commented Apr 21, 2021

I didn't see any label or annotation marking ephemeral container in a pod. Maybe I miss something. If the caller (kubelet) can add label on container, it will be helpful.

+1 for the caller identifying the container.. can just see some admin opening an issue about a random container left running in their pod :-)

@verb
Copy link
Copy Markdown

verb commented Apr 21, 2021

I didn't see any label or annotation marking ephemeral container in a pod. Maybe I miss something. If the caller (kubelet) can add label on container, it will be helpful.

+1 for the caller identifying the container.. can just see some admin opening an issue about a random container left running in their pod :-)

I set a label in an earlier implementation, but it wasn't necessary for the kubelet so I dropped it. Happy to add it back if it would be helpful.

Not sure if someone here intends to implement the change in the kubelet, but if not it would make a good new contributor issue. If you open an enhancements tracking issue and tag me I'll guide it.

@tghartland tghartland force-pushed the 5008-target-namespace branch from 7f3f632 to d63e9c6 Compare April 21, 2021 17:44
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Apr 21, 2021

Build succeeded.

@tghartland tghartland force-pushed the 5008-target-namespace branch from d63e9c6 to efcb187 Compare April 21, 2021 17:59
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Apr 21, 2021

Build succeeded.

@mikebrow
Copy link
Copy Markdown
Member

@dims good to merge?

Copy link
Copy Markdown
Member

@dims dims left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mikebrow mikebrow merged commit 3dad67e into containerd:master Apr 22, 2021
@tghartland
Copy link
Copy Markdown
Contributor Author

Great, thanks for the reviews.

Is it still possible for this to be in 1.5.0 or does it need to wait for a later release now?

@fuweid
Copy link
Copy Markdown
Member

fuweid commented Apr 22, 2021

@tghartland this patch is already in the release 1.5 and just wait for release. Thanks for contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for TARGET NamespaceMode in CRI implementation

9 participants