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:
Matthew Heon
2018-07-19 14:29:00 -04:00
parent 3ae0c80806
commit fc95f68247
2 changed files with 12 additions and 0 deletions

View File

@ -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")