Improve ContainerEngine.ContainerWait()

Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
Matej Vasek
2021-02-01 21:23:44 +01:00
parent 570e1587dd
commit fc385806df
9 changed files with 17 additions and 16 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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)
}()

View File

@@ -51,7 +51,7 @@ type ContainerRunlabelReport struct {
}
type WaitOptions struct {
Condition define.ContainerStatus
Condition []define.ContainerStatus
Interval time.Duration
Latest bool
}

View File

@@ -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 {