summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatej Vasek <mvasek@redhat.com>2021-02-01 21:23:44 +0100
committerMatej Vasek <mvasek@redhat.com>2021-02-03 21:49:09 +0100
commitfc385806dfe1d13a7d4e4bdaeea93a22a55bd3d4 (patch)
tree1551262302d3cf31740cfd3474d150e1c2b21422
parent570e1587dde267adea7fe460086dffee6aec83a4 (diff)
downloadpodman-fc385806dfe1d13a7d4e4bdaeea93a22a55bd3d4.tar.gz
podman-fc385806dfe1d13a7d4e4bdaeea93a22a55bd3d4.tar.bz2
podman-fc385806dfe1d13a7d4e4bdaeea93a22a55bd3d4.zip
Improve ContainerEngine.ContainerWait()
Signed-off-by: Matej Vasek <mvasek@redhat.com>
-rw-r--r--cmd/podman/containers/wait.go3
-rw-r--r--pkg/api/handlers/utils/containers.go6
-rw-r--r--pkg/bindings/containers/types.go2
-rw-r--r--pkg/bindings/containers/types_wait_options.go10
-rw-r--r--pkg/bindings/test/attach_test.go2
-rw-r--r--pkg/bindings/test/common_test.go2
-rw-r--r--pkg/bindings/test/containers_test.go4
-rw-r--r--pkg/domain/entities/containers.go2
-rw-r--r--pkg/domain/infra/abi/containers.go2
9 files changed, 17 insertions, 16 deletions
diff --git a/cmd/podman/containers/wait.go b/cmd/podman/containers/wait.go
index 14d660678..7a531b98a 100644
--- a/cmd/podman/containers/wait.go
+++ b/cmd/podman/containers/wait.go
@@ -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 {
diff --git a/pkg/api/handlers/utils/containers.go b/pkg/api/handlers/utils/containers.go
index fac237f87..7443f9b46 100644
--- a/pkg/api/handlers/utils/containers.go
+++ b/pkg/api/handlers/utils/containers.go
@@ -23,8 +23,8 @@ func WaitContainer(w http.ResponseWriter, r *http.Request) (int32, error) {
containerEngine := abi.ContainerEngine{Libpod: runtime}
decoder := r.Context().Value("decoder").(*schema.Decoder)
query := struct {
- Interval string `schema:"interval"`
- Condition define.ContainerStatus `schema:"condition"`
+ Interval string `schema:"interval"`
+ 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 {
diff --git a/pkg/bindings/containers/types.go b/pkg/bindings/containers/types.go
index 771cde72c..4889b444a 100644
--- a/pkg/bindings/containers/types.go
+++ b/pkg/bindings/containers/types.go
@@ -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
}
diff --git a/pkg/bindings/containers/types_wait_options.go b/pkg/bindings/containers/types_wait_options.go
index 005cc38cb..a3f1e3b8c 100644
--- a/pkg/bindings/containers/types_wait_options.go
+++ b/pkg/bindings/containers/types_wait_options.go
@@ -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
diff --git a/pkg/bindings/test/attach_test.go b/pkg/bindings/test/attach_test.go
index 9a46f6309..771b2d528 100644
--- a/pkg/bindings/test/attach_test.go
+++ b/pkg/bindings/test/attach_test.go
@@ -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)
diff --git a/pkg/bindings/test/common_test.go b/pkg/bindings/test/common_test.go
index c2b1347d2..8fbc631d8 100644
--- a/pkg/bindings/test/common_test.go
+++ b/pkg/bindings/test/common_test.go
@@ -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
}
diff --git a/pkg/bindings/test/containers_test.go b/pkg/bindings/test/containers_test.go
index 9b9f98047..14eb1ffc6 100644
--- a/pkg/bindings/test/containers_test.go
+++ b/pkg/bindings/test/containers_test.go
@@ -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)
}()
diff --git a/pkg/domain/entities/containers.go b/pkg/domain/entities/containers.go
index 63be5578f..2d50d6826 100644
--- a/pkg/domain/entities/containers.go
+++ b/pkg/domain/entities/containers.go
@@ -51,7 +51,7 @@ type ContainerRunlabelReport struct {
}
type WaitOptions struct {
- Condition define.ContainerStatus
+ Condition []define.ContainerStatus
Interval time.Duration
Latest bool
}
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index cfd3d7272..7a672d863 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -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 {