diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-12-02 16:31:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-02 16:31:11 +0100 |
commit | e4275b3453598c3cdcf1ee00ff73c55780aef444 (patch) | |
tree | 15915f36125dfd9db9d56440f2a89f0610aa52fc /libpod/util.go | |
parent | 39c705e9405faa4d02b71165d05eec1e7bb44d93 (diff) | |
parent | 6c405b5fbcc83ba49c187087eb4e1ccc1a7ff147 (diff) | |
download | podman-e4275b3453598c3cdcf1ee00ff73c55780aef444.tar.gz podman-e4275b3453598c3cdcf1ee00ff73c55780aef444.tar.bz2 podman-e4275b3453598c3cdcf1ee00ff73c55780aef444.zip |
Merge pull request #4493 from mheon/add_removing_state
Add ContainerStateRemoving
Diffstat (limited to 'libpod/util.go')
-rw-r--r-- | libpod/util.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libpod/util.go b/libpod/util.go index bae2f4eb8..30e5cd4c3 100644 --- a/libpod/util.go +++ b/libpod/util.go @@ -206,3 +206,28 @@ func DefaultSeccompPath() (string, error) { } return config.SeccompDefaultPath, nil } + +// CheckDependencyContainer verifies the given container can be used as a +// dependency of another container. +// Both the dependency to check and the container that will be using the +// dependency must be passed in. +// It is assumed that ctr is locked, and depCtr is unlocked. +func checkDependencyContainer(depCtr, ctr *Container) error { + state, err := depCtr.State() + if err != nil { + return errors.Wrapf(err, "error accessing dependency container %s state", depCtr.ID()) + } + if state == define.ContainerStateRemoving { + return errors.Wrapf(define.ErrCtrStateInvalid, "cannot use container %s as a dependency as it is being removed", depCtr.ID()) + } + + if depCtr.ID() == ctr.ID() { + return errors.Wrapf(define.ErrInvalidArg, "must specify another container") + } + + if ctr.config.Pod != "" && depCtr.PodID() != ctr.config.Pod { + return errors.Wrapf(define.ErrInvalidArg, "container has joined pod %s and dependency container %s is not a member of the pod", ctr.config.Pod, depCtr.ID()) + } + + return nil +} |