mirror of
https://github.com/containers/podman.git
synced 2025-06-25 20:26:51 +08:00
Merge pull request #14818 from rhatdan/wait
podman wait can take multiple conditions
This commit is contained in:
@ -41,9 +41,9 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
waitOptions = entities.WaitOptions{}
|
waitOptions = entities.WaitOptions{}
|
||||||
waitCondition string
|
waitConditions []string
|
||||||
waitInterval string
|
waitInterval string
|
||||||
)
|
)
|
||||||
|
|
||||||
func waitFlags(cmd *cobra.Command) {
|
func waitFlags(cmd *cobra.Command) {
|
||||||
@ -54,7 +54,7 @@ func waitFlags(cmd *cobra.Command) {
|
|||||||
_ = cmd.RegisterFlagCompletionFunc(intervalFlagName, completion.AutocompleteNone)
|
_ = cmd.RegisterFlagCompletionFunc(intervalFlagName, completion.AutocompleteNone)
|
||||||
|
|
||||||
conditionFlagName := "condition"
|
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)
|
_ = 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")
|
return errors.New("--latest and containers cannot be used together")
|
||||||
}
|
}
|
||||||
|
|
||||||
cond, err := define.StringToContainerStatus(waitCondition)
|
for _, condition := range waitConditions {
|
||||||
if err != nil {
|
cond, err := define.StringToContainerStatus(condition)
|
||||||
return err
|
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)
|
responses, err := registry.ContainerEngine().ContainerWait(context.Background(), args, waitOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -99,9 +99,8 @@ func WaitContainerDocker(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func WaitContainerLibpod(w http.ResponseWriter, r *http.Request) {
|
func WaitContainerLibpod(w http.ResponseWriter, r *http.Request) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
interval = time.Millisecond * 250
|
interval = time.Millisecond * 250
|
||||||
conditions = []define.ContainerStatus{define.ContainerStateStopped, define.ContainerStateExited}
|
|
||||||
)
|
)
|
||||||
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
|
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
|
||||||
query := waitQueryLibpod{}
|
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)
|
name := GetName(r)
|
||||||
|
|
||||||
waitFn := createContainerWaitFn(r.Context(), name, interval)
|
waitFn := createContainerWaitFn(r.Context(), name, interval)
|
||||||
|
exitCode, err := waitFn(query.Condition...)
|
||||||
exitCode, err := waitFn(conditions...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, define.ErrNoSuchCtr) {
|
if errors.Is(err, define.ErrNoSuchCtr) {
|
||||||
ContainerNotFound(w, name, err)
|
ContainerNotFound(w, name, err)
|
||||||
|
@ -101,6 +101,9 @@ func (ic *ContainerEngine) ContainerWait(ctx context.Context, namesOrIds []strin
|
|||||||
responses := make([]entities.WaitReport, 0, len(ctrs))
|
responses := make([]entities.WaitReport, 0, len(ctrs))
|
||||||
for _, c := range ctrs {
|
for _, c := range ctrs {
|
||||||
response := entities.WaitReport{Id: c.ID()}
|
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...)
|
exitCode, err := c.WaitForConditionWithInterval(ctx, options.Interval, options.Condition...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error = err
|
response.Error = err
|
||||||
|
@ -124,7 +124,7 @@ function _log_test_restarted() {
|
|||||||
# FIXME: #9597
|
# FIXME: #9597
|
||||||
# run/start is flaking for remote so let's wait for the container condition
|
# run/start is flaking for remote so let's wait for the container condition
|
||||||
# to stop wasting energy until the root cause gets fixed.
|
# 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
|
run_podman ${events_backend} start -a logtest
|
||||||
logfile=$(mktemp -p ${PODMAN_TMPDIR} logfileXXXXXXXX)
|
logfile=$(mktemp -p ${PODMAN_TMPDIR} logfileXXXXXXXX)
|
||||||
$PODMAN $_PODMAN_TEST_OPTS ${events_backend} logs -f logtest > $logfile
|
$PODMAN $_PODMAN_TEST_OPTS ${events_backend} logs -f logtest > $logfile
|
||||||
|
Reference in New Issue
Block a user