-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
podman pod create --pid flag #10894
podman pod create --pid flag #10894
Conversation
bcc4d84
to
9474e69
Compare
What does "pod" mean? Are you allowing pod's to join other pods pid namespace? |
libpod/options.go
Outdated
if pod.valid { | ||
return define.ErrPodFinalized | ||
} | ||
pod.config.Pid = inp |
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 need to require that UsePodPID
is set in the pod configuration - we have to be sharing the pod PID namespace for this to be set.
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 need to require that
UsePodPID
is set in the pod configuration - we have to be sharing the pod PID namespace for this to be set.
Should I require it by checking and erroring out if not set, or warn the user and set it for them?
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.
Good question. I was leaning towards just erroring out unless the user passes --share
as well to specify that the PID namespace is shared, but that seems like a bad user experience. @rhatdan Should setting --pid
automatically cause the pod to share the PID namespace?
libpod/pod.go
Outdated
@@ -170,6 +174,16 @@ func (p *Pod) CPUQuota() int64 { | |||
return 0 | |||
} | |||
|
|||
// Pid returns the pod process id namespace value |
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.
This isn't getting the PID, but rather the path of the infra container's PID file?
It's also not really related to the PID namespace
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.
Yeah I was unsure here of what would be helpful here @mheon, because the namespace just contains pod
or host
or whatever the user passed or a ns file if specified. What would this be expected to return?
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.
Returning the mode of the namespace is what I would expect - we want to tell the user how the pod was configured. The PID of the pod's init container isn't that valuable.
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.
Similar comment here for me, I'd change the variable to indicate it's pidmode and not the pid to help make the support of this more clear months down the line.
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.
good idea @TomSweeneyRedHat. I will change to make it more explicit that it returns the mode passed by the user.
libpod/runtime_pod_infra_linux.go
Outdated
ns := spec.LinuxNamespace{} | ||
pidVal := p.config.Pid.NSMode | ||
if pidVal != "" { | ||
if pidVal == "container" { |
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.
This validation should be done in the option (WithPid()
so we only have to do it once and we can reject invalid configurations at creation time, not runtime.
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.
Okay @mheon , to streamline this and preserve the originally passed values I might make another InfraContainerConfig value that is an actual specs.LinuxNameSpace{}
. This will allow me to be able to print the proper mode in podInspect but also not have to parse anything again in runtime_pod_infra_linux.go
pkg/domain/entities/pods.go
Outdated
@@ -146,6 +147,17 @@ func (p *PodCreateOptions) CPULimits() *specs.LinuxCPU { | |||
return cpu | |||
} | |||
|
|||
func setNamespaces(p *PodCreateOptions) (specgen.Namespace, error) { |
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.
Suggest renaming to "getPIDNamespace" or, alternatively, making this return a struct which identifies which namespace is which - right now this is only useful for setting the PID namespace, but eventually we'll end up with four-ish settable namespaces.
pkg/specgen/generate/pod_create.go
Outdated
@@ -102,6 +102,13 @@ func createPodOptions(p *specgen.PodSpecGenerator, rt *libpod.Runtime) ([]libpod | |||
options = append(options, libpod.WithInfraCommand(p.InfraCommand)) | |||
} | |||
|
|||
if !p.Pid.IsDefault() { | |||
options = append(options, libpod.WithPid(p.Pid)) | |||
if p.Pid.NSMode == "pod" { |
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.
This bit doesn't seem necessary?
libpod/options.go
Outdated
} | ||
if p.config.UsePodPID { | ||
ns := specs.LinuxNamespace{} | ||
ns.Type = "pid" |
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.
Is there a reason we need to recreate the namespace?
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.
I think specs.LinuxNameSpace{}
is the type that the infra generator takes versus specgen.NameSpace
, we need to switch over at some point and this is behind the scenes enough.
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.
Ahhh, I missed the type change. Hm. My concern would be forwards-compat - we need to make sure that pods from before this change, without a valid namespace in the DB, continue to work.
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.
well, the specgen.ParseNamespace()
function I use in pkg/domain/entities/pods.go takes the type specgen.NameSpace so the actual validation and parsing relies more on the specgen version this is just a conversion. This switch will only execute when someone explicitly says --pid=...
so would forwards-compat be a problem?
6740c45
to
66359de
Compare
pod means that the containers will default to using the pod's pid ns which is similar to private (the default). I added this because the |
libpod/pod.go
Outdated
@@ -97,6 +98,8 @@ type InfraContainerConfig struct { | |||
HasInfraContainer bool `json:"makeInfraContainer"` | |||
NoNetwork bool `json:"noNetwork,omitempty"` | |||
HostNetwork bool `json:"infraHostNetwork,omitempty"` | |||
Pid specgen.Namespace `json:"infraPid,omitempty"` | |||
LinuxPidNS specs.LinuxNamespace `json:"LinuxPIDNS,omitempty"` |
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.
Do we need both of these? I would imagine we can get the mode just by looking at the specs.LinuxNamespace
- or, alternatively, generate the specs.LinuxNamespace
from the specgen.Namespace
when creating the infra container?
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.
@mheon I kept both of them in order to parse the Pid NS before runtime. The types are different as specgen.Namespace
contains info like host
or pod
which I do use again at runtime but specs.LinuxNamespace
is the actual NS struct containing pid
and the proper path. Not sure if I can parse before runtime and not have both of these but I will look.
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.
fixed
7d32fe8
to
d044791
Compare
@@ -120,6 +120,14 @@ Add a DNS alias for the container. When the container is joined to a CNI network | |||
|
|||
Disable creation of /etc/hosts for the pod. | |||
|
|||
#### **--pid**=*pid* | |||
|
|||
Set the PID mode for the pod Default is to create a private PID namespace for the pod. Requires PID NS to be shared. |
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.
I'm having a hard time parsing this. Maybe?
Set the PID mode for the pod Default is to create a private PID namespace for the pod. Requires PID NS to be shared. | |
Set the PID mode for the pod. The default is to create a private PID namespace for the pod. Requires the PID namespace to be shared. |
@@ -120,6 +120,14 @@ Add a DNS alias for the container. When the container is joined to a CNI network | |||
|
|||
Disable creation of /etc/hosts for the pod. | |||
|
|||
#### **--pid**=*pid* |
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.
I was thinking "process ID (pid) when reading this. I'll let others over-rule me, but I'd rather the option be named something else, in case we ever manipulate the pid later down the road. Perhaps --pid-mode
, regardless, at least change the variable:
#### **--pid**=*pid* | |
#### **--pid**=*pid-mode* |
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.
I feel like --pid-ns
might be more accurate if anything @TomSweeneyRedHat. Only thing is, container create calls it --pid
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.
Ugh. They should be the same in both places, and it looks like Docker has gone with --pid
too, so we probably ought to stay with --pid
. Rather than *pid-mode*
at line 123, I'd be fine with *pid-ns*
if you prefer for the variable
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.
okay @TomSweeneyRedHat I am good with keeping it as --pid
, probably best so people don't get confused as to what this flag is compared to container create and docker
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.
LGTM in general. Just two comments.
libpod/pod.go
Outdated
@@ -97,6 +98,7 @@ type InfraContainerConfig struct { | |||
HasInfraContainer bool `json:"makeInfraContainer"` | |||
NoNetwork bool `json:"noNetwork,omitempty"` | |||
HostNetwork bool `json:"infraHostNetwork,omitempty"` | |||
Pid specgen.Namespace `json:"infraPid,omitempty"` |
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.
I think this should be called PidNS
to prevent mistaking it for a process ID. Same at other places in the code.
But I do agree that --pid
makes sense on the CLI to remain consistent with container create
.
podCreate = podmanTest.Podman([]string{"pod", "create", "--pid", ns, "--share", "pid"}) | ||
podCreate.WaitWithDefaultTimeout() | ||
Expect(podCreate).Should(ExitWithError()) | ||
|
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.
Will the pid ns now be displayed in podman inspect
? If so, it would be nice to exercise that here in the 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.
@vrothberg we decided to output the NSMode
the user gave us as it is more helpful, aka: path
, pod
, private
... I will check for that here, thanks for calling that out!
/hold |
/lgtm |
added support for --pid flag. User can specify ns:file, pod, private, or host. container returns an error since you cannot point the ns of the pods infra container to a container outside of the pod. Signed-off-by: cdoern <[email protected]>
sorry had to re-push to fix a test, ran locally and all green. should be good now @baude |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cdoern, rhatdan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold cancel |
added support for --pid flag. User can specify ns:file, pod, private, or host pid namespace values. container returns an error since you cannot point the ns of the pods infra container
to a container outside of the pod.
Signed-off-by: cdoern [email protected]