summaryrefslogtreecommitdiff
path: root/libpod/options.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-03-31 19:58:31 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-04-03 14:57:16 +0000
commita1c0f18bcac9e0b21b4abbb4e49bea4336842e4e (patch)
treec54147b99c04f02b528857840310f43213c7608b /libpod/options.go
parent838df4eec4496868e772d5708e00f38bad478718 (diff)
downloadpodman-a1c0f18bcac9e0b21b4abbb4e49bea4336842e4e.tar.gz
podman-a1c0f18bcac9e0b21b4abbb4e49bea4336842e4e.tar.bz2
podman-a1c0f18bcac9e0b21b4abbb4e49bea4336842e4e.zip
Add backend code for generic dependencies
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #577 Approved by: rhatdan
Diffstat (limited to 'libpod/options.go')
-rw-r--r--libpod/options.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/libpod/options.go b/libpod/options.go
index 987a37429..739d53a8b 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -625,6 +625,38 @@ func WithCgroupNSFrom(nsCtr *Container) CtrCreateOption {
}
}
+// WithDependencies sets dependency containers of the given container
+// Dependency containers must be running before this container is started
+func WithDependencyCtrs(ctrs []*Container) CtrCreateOption {
+ return func(ctr *Container) error {
+ if ctr.valid {
+ return ErrCtrFinalized
+ }
+
+ deps := make([]string, 0, len(ctrs))
+
+ for _, dep := range ctrs {
+ if !dep.valid {
+ return errors.Wrapf(ErrCtrRemoved, "container %s is not valid", dep.ID())
+ }
+
+ if dep.ID() == ctr.ID() {
+ return errors.Wrapf(ErrInvalidArg, "must specify another container")
+ }
+
+ if ctr.config.Pod != "" && dep.config.Pod != ctr.config.Pod {
+ return errors.Wrapf(ErrInvalidArg, "container has joined pod %s and dependency container %s is not a member of the pod", ctr.config.Pod, dep.ID())
+ }
+
+ deps = append(deps, dep.ID())
+ }
+
+ ctr.config.Dependencies = deps
+
+ return nil
+ }
+}
+
// WithNetNS indicates that the container should be given a new network
// namespace with a minimal configuration
// An optional array of port mappings can be provided