mirror of
https://github.com/containers/podman.git
synced 2025-12-01 02:27:13 +08:00
Improve ContainerEngine.ContainerWait()
Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
@@ -95,10 +95,11 @@ func wait(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("--latest and containers cannot be used together")
|
||||
}
|
||||
|
||||
waitOptions.Condition, err = define.StringToContainerStatus(waitCondition)
|
||||
cond, err := define.StringToContainerStatus(waitCondition)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
waitOptions.Condition = []define.ContainerStatus{cond}
|
||||
|
||||
responses, err := registry.ContainerEngine().ContainerWait(context.Background(), args, waitOptions)
|
||||
if err != nil {
|
||||
|
||||
@@ -24,7 +24,7 @@ func WaitContainer(w http.ResponseWriter, r *http.Request) (int32, error) {
|
||||
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||
query := struct {
|
||||
Interval string `schema:"interval"`
|
||||
Condition define.ContainerStatus `schema:"condition"`
|
||||
Condition []define.ContainerStatus `schema:"condition"`
|
||||
}{
|
||||
// Override golang default values for types
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func WaitContainer(w http.ResponseWriter, r *http.Request) (int32, error) {
|
||||
return 0, err
|
||||
}
|
||||
options := entities.WaitOptions{
|
||||
Condition: define.ContainerStateStopped,
|
||||
Condition: []define.ContainerStatus{define.ContainerStateStopped},
|
||||
}
|
||||
name := GetName(r)
|
||||
if _, found := r.URL.Query()["interval"]; found {
|
||||
|
||||
@@ -176,7 +176,7 @@ type UnpauseOptions struct{}
|
||||
//go:generate go run ../generator/generator.go WaitOptions
|
||||
// WaitOptions are optional options for waiting on containers
|
||||
type WaitOptions struct {
|
||||
Condition *define.ContainerStatus
|
||||
Condition []define.ContainerStatus
|
||||
Interval *string
|
||||
}
|
||||
|
||||
|
||||
@@ -76,19 +76,19 @@ func (o *WaitOptions) ToParams() (url.Values, error) {
|
||||
}
|
||||
|
||||
// WithCondition
|
||||
func (o *WaitOptions) WithCondition(value define.ContainerStatus) *WaitOptions {
|
||||
v := &value
|
||||
func (o *WaitOptions) WithCondition(value []define.ContainerStatus) *WaitOptions {
|
||||
v := value
|
||||
o.Condition = v
|
||||
return o
|
||||
}
|
||||
|
||||
// GetCondition
|
||||
func (o *WaitOptions) GetCondition() define.ContainerStatus {
|
||||
var condition define.ContainerStatus
|
||||
func (o *WaitOptions) GetCondition() []define.ContainerStatus {
|
||||
var condition []define.ContainerStatus
|
||||
if o.Condition == nil {
|
||||
return condition
|
||||
}
|
||||
return *o.Condition
|
||||
return o.Condition
|
||||
}
|
||||
|
||||
// WithInterval
|
||||
|
||||
@@ -75,7 +75,7 @@ var _ = Describe("Podman containers attach", func() {
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
wait := define.ContainerStateRunning
|
||||
_, err = containers.Wait(bt.conn, ctnr.ID, new(containers.WaitOptions).WithCondition(wait))
|
||||
_, err = containers.Wait(bt.conn, ctnr.ID, new(containers.WaitOptions).WithCondition([]define.ContainerStatus{wait}))
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
tickTock := time.NewTimer(2 * time.Second)
|
||||
|
||||
@@ -207,7 +207,7 @@ func (b *bindingTest) RunTopContainer(containerName *string, insidePod *bool, po
|
||||
return "", err
|
||||
}
|
||||
wait := define.ContainerStateRunning
|
||||
_, err = containers.Wait(b.conn, ctr.ID, new(containers.WaitOptions).WithCondition(wait))
|
||||
_, err = containers.Wait(b.conn, ctr.ID, new(containers.WaitOptions).WithCondition([]define.ContainerStatus{wait}))
|
||||
return ctr.ID, err
|
||||
}
|
||||
|
||||
|
||||
@@ -281,7 +281,7 @@ var _ = Describe("Podman containers ", func() {
|
||||
_, err := bt.RunTopContainer(&name, nil, nil)
|
||||
Expect(err).To(BeNil())
|
||||
go func() {
|
||||
exitCode, err = containers.Wait(bt.conn, name, new(containers.WaitOptions).WithCondition(pause))
|
||||
exitCode, err = containers.Wait(bt.conn, name, new(containers.WaitOptions).WithCondition([]define.ContainerStatus{pause}))
|
||||
errChan <- err
|
||||
close(errChan)
|
||||
}()
|
||||
@@ -295,7 +295,7 @@ var _ = Describe("Podman containers ", func() {
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
|
||||
_, waitErr := containers.Wait(bt.conn, name, new(containers.WaitOptions).WithCondition(running))
|
||||
_, waitErr := containers.Wait(bt.conn, name, new(containers.WaitOptions).WithCondition([]define.ContainerStatus{running}))
|
||||
unpauseErrChan <- waitErr
|
||||
close(unpauseErrChan)
|
||||
}()
|
||||
|
||||
@@ -51,7 +51,7 @@ type ContainerRunlabelReport struct {
|
||||
}
|
||||
|
||||
type WaitOptions struct {
|
||||
Condition define.ContainerStatus
|
||||
Condition []define.ContainerStatus
|
||||
Interval time.Duration
|
||||
Latest bool
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ 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()}
|
||||
exitCode, err := c.WaitForConditionWithInterval(ctx, options.Interval, options.Condition)
|
||||
exitCode, err := c.WaitForConditionWithInterval(ctx, options.Interval, options.Condition...)
|
||||
if err != nil {
|
||||
response.Error = err
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user