diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-03-02 23:52:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-02 23:52:21 +0100 |
commit | 873d64fd6b543eabfa600e28184e5ca7a32beac1 (patch) | |
tree | ecbd30846cd966258ef14a045fb23df9065c39f4 /libpod/runtime_ctr.go | |
parent | c5dfd83cf4528e58f5928ac1ef1f2b00fd5ca559 (diff) | |
parent | e45456223c4caa762be1a9b1f6b94006d5053c1a (diff) | |
download | podman-873d64fd6b543eabfa600e28184e5ca7a32beac1.tar.gz podman-873d64fd6b543eabfa600e28184e5ca7a32beac1.tar.bz2 podman-873d64fd6b543eabfa600e28184e5ca7a32beac1.zip |
Merge pull request #5363 from mheon/add_ctr_validate
Add validate() for containers
Diffstat (limited to 'libpod/runtime_ctr.go')
-rw-r--r-- | libpod/runtime_ctr.go | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 39284026c..de93fdce7 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -133,7 +133,12 @@ func (r *Runtime) newContainer(ctx context.Context, rSpec *spec.Spec, options .. return r.setupContainer(ctx, ctr) } -func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (c *Container, err error) { +func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Container, err error) { + // Validate the container + if err := ctr.validate(); err != nil { + return nil, err + } + // Allocate a lock for the container lock, err := r.lockManager.AllocateLock() if err != nil { @@ -190,27 +195,6 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (c *Contai ctr.config.Name = name } - // If CGroups are disabled, we MUST create a PID namespace. - // Otherwise, the OCI runtime won't be able to stop our container. - if ctr.config.NoCgroups { - if ctr.config.Spec.Linux == nil { - return nil, errors.Wrapf(define.ErrInvalidArg, "must provide Linux namespace configuration in OCI spec when using NoCgroups") - } - foundPid := false - for _, ns := range ctr.config.Spec.Linux.Namespaces { - if ns.Type == spec.PIDNamespace { - foundPid = true - if ns.Path != "" { - return nil, errors.Wrapf(define.ErrInvalidArg, "containers not creating CGroups must create a private PID namespace - cannot use another") - } - break - } - } - if !foundPid { - return nil, errors.Wrapf(define.ErrInvalidArg, "containers not creating CGroups must create a private PID namespace") - } - } - // Check CGroup parent sanity, and set it if it was not set. // Only if we're actually configuring CGroups. if !ctr.config.NoCgroups { |