From 96dd57ca50de54e82cea177c317b92612ed1cf81 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Mon, 4 Jul 2022 07:13:51 -0400 Subject: [PATCH] podman wait can take multiple conditions Podman wait should not be defaulting to just stopped. By default wait API waits for stopped and exited. We should not override this on the client side. Signed-off-by: Daniel J Walsh --- cmd/podman/containers/wait.go | 18 ++++++++++-------- pkg/api/handlers/utils/containers.go | 14 +++----------- pkg/domain/infra/abi/containers.go | 3 +++ test/system/035-logs.bats | 2 +- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/cmd/podman/containers/wait.go b/cmd/podman/containers/wait.go index 5b84807817..be92a3cbeb 100644 --- a/cmd/podman/containers/wait.go +++ b/cmd/podman/containers/wait.go @@ -41,9 +41,9 @@ var ( ) var ( - waitOptions = entities.WaitOptions{} - waitCondition string - waitInterval string + waitOptions = entities.WaitOptions{} + waitConditions []string + waitInterval string ) func waitFlags(cmd *cobra.Command) { @@ -54,7 +54,7 @@ func waitFlags(cmd *cobra.Command) { _ = cmd.RegisterFlagCompletionFunc(intervalFlagName, completion.AutocompleteNone) conditionFlagName := "condition" - flags.StringVar(&waitCondition, conditionFlagName, "stopped", "Condition to wait on") + flags.StringSliceVar(&waitConditions, conditionFlagName, []string{}, "Condition to wait on") _ = cmd.RegisterFlagCompletionFunc(conditionFlagName, common.AutocompleteWaitCondition) } @@ -92,11 +92,13 @@ func wait(cmd *cobra.Command, args []string) error { return errors.New("--latest and containers cannot be used together") } - cond, err := define.StringToContainerStatus(waitCondition) - if err != nil { - return err + for _, condition := range waitConditions { + cond, err := define.StringToContainerStatus(condition) + if err != nil { + return err + } + waitOptions.Condition = append(waitOptions.Condition, cond) } - waitOptions.Condition = []define.ContainerStatus{cond} responses, err := registry.ContainerEngine().ContainerWait(context.Background(), args, waitOptions) if err != nil { diff --git a/pkg/api/handlers/utils/containers.go b/pkg/api/handlers/utils/containers.go index 80f8522fd0..e198bdd6c6 100644 --- a/pkg/api/handlers/utils/containers.go +++ b/pkg/api/handlers/utils/containers.go @@ -99,9 +99,8 @@ func WaitContainerDocker(w http.ResponseWriter, r *http.Request) { func WaitContainerLibpod(w http.ResponseWriter, r *http.Request) { var ( - err error - interval = time.Millisecond * 250 - conditions = []define.ContainerStatus{define.ContainerStateStopped, define.ContainerStateExited} + err error + interval = time.Millisecond * 250 ) decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder) query := waitQueryLibpod{} @@ -118,17 +117,10 @@ func WaitContainerLibpod(w http.ResponseWriter, r *http.Request) { } } - if _, found := r.URL.Query()["condition"]; found { - if len(query.Condition) > 0 { - conditions = query.Condition - } - } - name := GetName(r) waitFn := createContainerWaitFn(r.Context(), name, interval) - - exitCode, err := waitFn(conditions...) + exitCode, err := waitFn(query.Condition...) if err != nil { if errors.Is(err, define.ErrNoSuchCtr) { ContainerNotFound(w, name, err) diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go index 1688be57e1..23a5916042 100644 --- a/pkg/domain/infra/abi/containers.go +++ b/pkg/domain/infra/abi/containers.go @@ -101,6 +101,9 @@ func (ic *ContainerEngine) ContainerWait(ctx context.Context, namesOrIds []strin responses := make([]entities.WaitReport, 0, len(ctrs)) for _, c := range ctrs { response := entities.WaitReport{Id: c.ID()} + if options.Condition == nil { + options.Condition = []define.ContainerStatus{define.ContainerStateStopped, define.ContainerStateExited} + } exitCode, err := c.WaitForConditionWithInterval(ctx, options.Interval, options.Condition...) if err != nil { response.Error = err diff --git a/test/system/035-logs.bats b/test/system/035-logs.bats index 97d984ef19..6b8d5fbc5f 100644 --- a/test/system/035-logs.bats +++ b/test/system/035-logs.bats @@ -124,7 +124,7 @@ function _log_test_restarted() { # FIXME: #9597 # run/start is flaking for remote so let's wait for the container condition # to stop wasting energy until the root cause gets fixed. - run_podman container wait --condition=exited logtest + run_podman container wait --condition=exited --condition=stopped logtest run_podman ${events_backend} start -a logtest logfile=$(mktemp -p ${PODMAN_TMPDIR} logfileXXXXXXXX) $PODMAN $_PODMAN_TEST_OPTS ${events_backend} logs -f logtest > $logfile