mirror of
https://github.com/containers/podman.git
synced 2025-05-22 01:27:07 +08:00
Set namespace for new pods/containers based on runtime
New containers and pods will default to the namespace of the runtime, but this can be overridden by With... options if desired. Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
This commit is contained in:
@ -42,6 +42,12 @@ func (r *Runtime) NewContainer(ctx context.Context, rSpec *spec.Spec, options ..
|
|||||||
}
|
}
|
||||||
ctr.config.StopTimeout = CtrRemoveTimeout
|
ctr.config.StopTimeout = CtrRemoveTimeout
|
||||||
|
|
||||||
|
// Set namespace based on current runtime namespace
|
||||||
|
// Do so before options run so they can override it
|
||||||
|
if r.config.Namespace != "" {
|
||||||
|
ctr.config.Namespace = r.config.Namespace
|
||||||
|
}
|
||||||
|
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
if err := option(ctr); err != nil {
|
if err := option(ctr); err != nil {
|
||||||
return nil, errors.Wrapf(err, "error running container create option")
|
return nil, errors.Wrapf(err, "error running container create option")
|
||||||
|
@ -27,6 +27,12 @@ func (r *Runtime) NewPod(options ...PodCreateOption) (*Pod, error) {
|
|||||||
return nil, errors.Wrapf(err, "error creating pod")
|
return nil, errors.Wrapf(err, "error creating pod")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set default namespace to runtime's namespace
|
||||||
|
// Do so before options run so they can override it
|
||||||
|
if r.config.Namespace != "" {
|
||||||
|
pod.config.Namespace = r.config.Namespace
|
||||||
|
}
|
||||||
|
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
if err := option(pod); err != nil {
|
if err := option(pod); err != nil {
|
||||||
return nil, errors.Wrapf(err, "error running pod create option")
|
return nil, errors.Wrapf(err, "error running pod create option")
|
||||||
|
Reference in New Issue
Block a user