From fc95f68247248e4cb029440e2fe4ba0b0df8049c Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 19 Jul 2018 14:29:00 -0400 Subject: 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 --- libpod/runtime_ctr.go | 6 ++++++ libpod/runtime_pod_linux.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 82a2fed19..709775e4a 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -42,6 +42,12 @@ func (r *Runtime) NewContainer(ctx context.Context, rSpec *spec.Spec, options .. } 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 { if err := option(ctr); err != nil { return nil, errors.Wrapf(err, "error running container create option") diff --git a/libpod/runtime_pod_linux.go b/libpod/runtime_pod_linux.go index 25340abdb..3355e4322 100644 --- a/libpod/runtime_pod_linux.go +++ b/libpod/runtime_pod_linux.go @@ -27,6 +27,12 @@ func (r *Runtime) NewPod(options ...PodCreateOption) (*Pod, error) { 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 { if err := option(pod); err != nil { return nil, errors.Wrapf(err, "error running pod create option") -- cgit v1.2.3-54-g00ecf