-
Notifications
You must be signed in to change notification settings - Fork 654
Support --pid=container:xxx for nerdctl run
cmd
#1411
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
Support --pid=container:xxx for nerdctl run
cmd
#1411
Conversation
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.
Thanks, but we need to deal with shared container restarts, it will change pid namesapce.
And please update the doc.
This comment was marked as resolved.
This comment was marked as resolved.
You can test restart the base container and then restart the shared container. |
nerdctl run
cmdnerdctl run
cmd
I fixed it using labels at 7a6d425. Summary of updates:
Can you review it again? @junnplus trivial: I updated the doc of pr. It is marked as updated. |
nerdctl run
cmdnerdctl run
cmd
} | ||
|
||
containerName := parsed[1] | ||
walker := &containerwalker.ContainerWalker{ |
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.
Why do we need to find again?
cOpts = append(cOpts, containerd.WithAdditionalContainerLabels(map[string]string{ | ||
labels.PIDContainer: containerName, | ||
})) |
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 already have withInternalLabels
, should be put together
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.
When a new label is needed, the best way is to add a new parameter of withInternalLabels()
?
And if so, --pid
flags is processed in setPlatformOptions()
. In order to pass into the withInternalLabels()
, the number of setPlatformOptions()
's return value should be increased.
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.
When a new label is needed, the best way is to add a new parameter of withInternalLabels()?
Uniformity is better than fragmentation.
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.
And if so, --pid flags is processed in setPlatformOptions().
I think the --pid
flags should be platform independent, why not consider moving it out of setPlatformOptions
?
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.
Previsouly, --pid
only works on linux.
nerdctl/cmd/nerdctl/run_linux.go
Lines 135 to 144 in c6517c7
pidNs = strings.ToLower(pidNs) | |
if pidNs != "" { | |
if pidNs != "host" { | |
return nil, fmt.Errorf("invalid pid namespace. Set --pid=host to enable host pid namespace") | |
} else { | |
opts = append(opts, oci.WithHostNamespace(specs.PIDNamespace)) | |
if rootlessutil.IsRootless() { | |
opts = append(opts, withBindMountHostProcfs) | |
} | |
} |
The reason, why it only works on the linux, is that it's too sensitive with namespace suppport.
Lines 1184 to 1187 in d15ada7
ns := specs.LinuxNamespace{ | |
Type: specs.PIDNamespace, | |
Path: fmt.Sprintf("/proc/%d/ns/pid", task.Pid()), | |
} |
// WithHostNamespace allows a task to run inside the host's linux namespace
func WithHostNamespace(ns specs.LinuxNamespaceType) SpecOpts {
return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
setLinux(s)
for i, n := range s.Linux.Namespaces {
if n.Type == ns {
s.Linux.Namespaces = append(s.Linux.Namespaces[:i], s.Linux.Namespaces[i+1:]...)
return nil
}
}
return nil
}
}
To avoid a compile error, I placed reconfigPIDContainer()
in cmd/nerdctl/start.go
but I think it caused confusing.
So, I added a condition to check runtime os now.
Line 231 in 8680bdb
if runtime.GOOS != "linux" { |
Anyway, in my opinion, --pid
currently can work on linux only.
Because of it, --pid
should be processed in setPlatformOptions()
. But, I really agree with you. setPlatformContainerOptions()
can make a fragmentation and cause to find a target container twice.
I tried to find a better way to improve it according to your review, but I couldn't. I'm really sorry.
I think the --pid flags should be platform independent, why not consider moving it out of setPlatformOptions?
And I don't understand how to move it out?
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.
The PID namespace (as well as other namespaces) is specific to Linux.
I don't think it will ever be platform-independent in the foreseeable future.
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.
Please squash commits
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.
Thanks
I'm sorry that I didn't apply reviews from jun. I'm looking forward the better way than setplatformcontaineropts(). |
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.
Sorry, no LGTM, I guess the code can be optimized again.
cOpts = append(cOpts, containerd.WithAdditionalContainerLabels(map[string]string{ | ||
labels.PIDContainer: containerName, | ||
})) |
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.
And if so, --pid flags is processed in setPlatformOptions().
I think the --pid
flags should be platform independent, why not consider moving it out of setPlatformOptions
?
- Add context and client to `setPlatformOptions()` - Add branch for platform-specific container opts - Add PIDContainer label into container's labels. It only works on linux platform. - Add reconfigPIDContainer() into container's start process. It recovers the pid namespace from its PIDContainer label. Signed-off-by: Min Uk Lee <[email protected]>
@junnplus LGTY? |
Let me merge this, as I don't think the Thank you @minuk-dev @junnplus 👍 |
#1293
Signed-off-by: Min Uk Lee [email protected]
Changes
--pid=container:xxx
fornerdctl run
commandgeneratePIDOpts()
function for pidsetPlatformOptions()
setPlatformContainerOptions()
- Details 1PIDContainer
label - Details 2Details
1. add
setPlatformContainerOptions()
withInternalLabels()
's parameterssetPlatformOptions()
increase, it would be difficult to maintain the code quality.addPlatformContainerOptions()
.2. add
PIDContainer
label--pid
flag's persistency, save the based container's id into the shared container's label.reconfigPIDContainer()
will recover it instartContainer()
a difference with docker
references