summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-02-17 21:04:33 +0100
committerGitHub <noreply@github.com>2019-02-17 21:04:33 +0100
commit6aaf8d39a9a26510e40fd54399e97fe177afadde (patch)
tree3754ecbf29b1d8e63675894f25abde206b8308c3 /cmd
parenta99f4924d9d76f59e85bde09944d7c5e687ea8aa (diff)
parent81804fc4641d279fec8f9bf48b21b22fc90cb891 (diff)
downloadpodman-6aaf8d39a9a26510e40fd54399e97fe177afadde.tar.gz
podman-6aaf8d39a9a26510e40fd54399e97fe177afadde.tar.bz2
podman-6aaf8d39a9a26510e40fd54399e97fe177afadde.zip
Merge pull request #2295 from haircommander/recursive-start
Recursively start a pod if a container is run in it
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/attach.go3
-rw-r--r--cmd/podman/play_kube.go2
-rw-r--r--cmd/podman/run.go7
-rw-r--r--cmd/podman/start.go6
-rw-r--r--cmd/podman/utils.go4
5 files changed, 13 insertions, 9 deletions
diff --git a/cmd/podman/attach.go b/cmd/podman/attach.go
index 7480bd6a2..b70ff649c 100644
--- a/cmd/podman/attach.go
+++ b/cmd/podman/attach.go
@@ -76,7 +76,8 @@ func attachCmd(c *cliconfig.AttachValues) error {
inputStream = nil
}
- if err := startAttachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.DetachKeys, c.SigProxy, false); err != nil && errors.Cause(err) != libpod.ErrDetach {
+ // If the container is in a pod, also set to recursively start dependencies
+ if err := startAttachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.DetachKeys, c.SigProxy, false, ctr.PodID() != ""); err != nil && errors.Cause(err) != libpod.ErrDetach {
return errors.Wrapf(err, "error attaching to container %s", ctr.ID())
}
diff --git a/cmd/podman/play_kube.go b/cmd/podman/play_kube.go
index 4ecd30cd4..97ab7afd4 100644
--- a/cmd/podman/play_kube.go
+++ b/cmd/podman/play_kube.go
@@ -154,7 +154,7 @@ func playKubeYAMLCmd(c *cliconfig.KubePlayValues) error {
// start the containers
for _, ctr := range containers {
- if err := ctr.Start(ctx); err != nil {
+ if err := ctr.Start(ctx, false); err != nil {
// Making this a hard failure here to avoid a mess
// the other containers are in created status
return err
diff --git a/cmd/podman/run.go b/cmd/podman/run.go
index 64f8b6856..45fc8df76 100644
--- a/cmd/podman/run.go
+++ b/cmd/podman/run.go
@@ -72,7 +72,8 @@ func runCmd(c *cliconfig.RunValues) error {
ctx := getContext()
// Handle detached start
if createConfig.Detach {
- if err := ctr.Start(ctx); err != nil {
+ // if the container was created as part of a pod, also start its dependencies, if any.
+ if err := ctr.Start(ctx, c.IsSet("pod")); err != nil {
// This means the command did not exist
exitCode = 127
if strings.Index(err.Error(), "permission denied") > -1 {
@@ -117,7 +118,8 @@ func runCmd(c *cliconfig.RunValues) error {
}
}
}
- if err := startAttachCtr(ctr, outputStream, errorStream, inputStream, c.String("detach-keys"), c.Bool("sig-proxy"), true); err != nil {
+ // if the container was created as part of a pod, also start its dependencies, if any.
+ if err := startAttachCtr(ctr, outputStream, errorStream, inputStream, c.String("detach-keys"), c.Bool("sig-proxy"), true, c.IsSet("pod")); err != nil {
// We've manually detached from the container
// Do not perform cleanup, or wait for container exit code
// Just exit immediately
@@ -125,7 +127,6 @@ func runCmd(c *cliconfig.RunValues) error {
exitCode = 0
return nil
}
-
// This means the command did not exist
exitCode = 127
if strings.Index(err.Error(), "permission denied") > -1 {
diff --git a/cmd/podman/start.go b/cmd/podman/start.go
index 1f671aefd..bbb4e87d2 100644
--- a/cmd/podman/start.go
+++ b/cmd/podman/start.go
@@ -105,7 +105,8 @@ func startCmd(c *cliconfig.StartValues) error {
}
// attach to the container and also start it not already running
- err = startAttachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.DetachKeys, sigProxy, !ctrRunning)
+ // If the container is in a pod, also set to recursively start dependencies
+ err = startAttachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.DetachKeys, sigProxy, !ctrRunning, ctr.PodID() != "")
if errors.Cause(err) == libpod.ErrDetach {
// User manually detached
// Exit cleanly immediately
@@ -144,7 +145,8 @@ func startCmd(c *cliconfig.StartValues) error {
continue
}
// Handle non-attach start
- if err := ctr.Start(ctx); err != nil {
+ // If the container is in a pod, also set to recursively start dependencies
+ if err := ctr.Start(ctx, ctr.PodID() != ""); err != nil {
if lastError != nil {
fmt.Fprintln(os.Stderr, lastError)
}
diff --git a/cmd/podman/utils.go b/cmd/podman/utils.go
index 744d010d5..c76e7f2a4 100644
--- a/cmd/podman/utils.go
+++ b/cmd/podman/utils.go
@@ -20,7 +20,7 @@ type RawTtyFormatter struct {
}
// Start (if required) and attach to a container
-func startAttachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys string, sigProxy bool, startContainer bool) error {
+func startAttachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys string, sigProxy bool, startContainer bool, recursive bool) error {
ctx := context.Background()
resize := make(chan remotecommand.TerminalSize)
@@ -76,7 +76,7 @@ func startAttachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detac
return ctr.Attach(streams, detachKeys, resize)
}
- attachChan, err := ctr.StartAndAttach(getContext(), streams, detachKeys, resize)
+ attachChan, err := ctr.StartAndAttach(getContext(), streams, detachKeys, resize, recursive)
if err != nil {
return err
}