aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2021-09-30 14:43:39 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2021-10-04 07:07:56 -0400
commit21c9dc3c406bb486c44c4a27e5b0497bab1cd40d (patch)
tree56793ffd885f835fa54013e9914844ff9ba20d92 /pkg
parent36821d302e3787a42d6eefdbd0bdbb6d9da261fb (diff)
downloadpodman-21c9dc3c406bb486c44c4a27e5b0497bab1cd40d.tar.gz
podman-21c9dc3c406bb486c44c4a27e5b0497bab1cd40d.tar.bz2
podman-21c9dc3c406bb486c44c4a27e5b0497bab1cd40d.zip
Add --time out for podman * rm -f commands
Add --time flag to podman container rm Add --time flag to podman pod rm Add --time flag to podman volume rm Add --time flag to podman network rm Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/api/handlers/compat/containers.go12
-rw-r--r--pkg/api/handlers/compat/networks.go6
-rw-r--r--pkg/api/handlers/compat/volumes.go5
-rw-r--r--pkg/api/handlers/libpod/pods.go5
-rw-r--r--pkg/api/handlers/libpod/volumes.go5
-rw-r--r--pkg/bindings/containers/types.go1
-rw-r--r--pkg/bindings/containers/types_remove_options.go15
-rw-r--r--pkg/bindings/network/types.go3
-rw-r--r--pkg/bindings/network/types_remove_options.go15
-rw-r--r--pkg/bindings/pods/types.go3
-rw-r--r--pkg/bindings/pods/types_remove_options.go15
-rw-r--r--pkg/bindings/volumes/types.go3
-rw-r--r--pkg/bindings/volumes/types_remove_options.go15
-rw-r--r--pkg/domain/entities/containers.go1
-rw-r--r--pkg/domain/entities/network.go3
-rw-r--r--pkg/domain/entities/pods.go9
-rw-r--r--pkg/domain/entities/volumes.go5
-rw-r--r--pkg/domain/infra/abi/containers.go11
-rw-r--r--pkg/domain/infra/abi/containers_runlabel.go3
-rw-r--r--pkg/domain/infra/abi/network.go4
-rw-r--r--pkg/domain/infra/abi/pods.go2
-rw-r--r--pkg/domain/infra/abi/volumes.go2
-rw-r--r--pkg/domain/infra/tunnel/containers.go4
-rw-r--r--pkg/domain/infra/tunnel/network.go3
-rw-r--r--pkg/domain/infra/tunnel/pods.go3
-rw-r--r--pkg/domain/infra/tunnel/volumes.go3
26 files changed, 123 insertions, 33 deletions
diff --git a/pkg/api/handlers/compat/containers.go b/pkg/api/handlers/compat/containers.go
index 18005e24a..4f101ce84 100644
--- a/pkg/api/handlers/compat/containers.go
+++ b/pkg/api/handlers/compat/containers.go
@@ -34,11 +34,12 @@ import (
func RemoveContainer(w http.ResponseWriter, r *http.Request) {
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
query := struct {
- Force bool `schema:"force"`
- Ignore bool `schema:"ignore"`
- Link bool `schema:"link"`
- DockerVolumes bool `schema:"v"`
- LibpodVolumes bool `schema:"volumes"`
+ Force bool `schema:"force"`
+ Ignore bool `schema:"ignore"`
+ Link bool `schema:"link"`
+ Timeout *uint `schema:"timeout"`
+ DockerVolumes bool `schema:"v"`
+ LibpodVolumes bool `schema:"volumes"`
}{
// override any golang type defaults
}
@@ -55,6 +56,7 @@ func RemoveContainer(w http.ResponseWriter, r *http.Request) {
}
if utils.IsLibpodRequest(r) {
options.Volumes = query.LibpodVolumes
+ options.Timeout = query.Timeout
} else {
if query.Link {
utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
diff --git a/pkg/api/handlers/compat/networks.go b/pkg/api/handlers/compat/networks.go
index b1456ed9e..dd28f6deb 100644
--- a/pkg/api/handlers/compat/networks.go
+++ b/pkg/api/handlers/compat/networks.go
@@ -245,7 +245,8 @@ func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
ic := abi.ContainerEngine{Libpod: runtime}
query := struct {
- Force bool `schema:"force"`
+ Force bool `schema:"force"`
+ Timeout *uint `schema:"timeout"`
}{
// This is where you can override the golang default value for one of fields
}
@@ -257,7 +258,8 @@ func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
}
options := entities.NetworkRmOptions{
- Force: query.Force,
+ Force: query.Force,
+ Timeout: query.Timeout,
}
name := utils.GetName(r)
diff --git a/pkg/api/handlers/compat/volumes.go b/pkg/api/handlers/compat/volumes.go
index 0f9b66888..e779aa185 100644
--- a/pkg/api/handlers/compat/volumes.go
+++ b/pkg/api/handlers/compat/volumes.go
@@ -213,7 +213,8 @@ func RemoveVolume(w http.ResponseWriter, r *http.Request) {
decoder = r.Context().Value(api.DecoderKey).(*schema.Decoder)
)
query := struct {
- Force bool `schema:"force"`
+ Force bool `schema:"force"`
+ Timeout *uint `schema:"timeout"`
}{
// override any golang type defaults
}
@@ -239,7 +240,7 @@ func RemoveVolume(w http.ResponseWriter, r *http.Request) {
vol, err := runtime.LookupVolume(name)
if err == nil {
// As above, we do not pass `force` from the query parameters here
- if err := runtime.RemoveVolume(r.Context(), vol, false); err != nil {
+ if err := runtime.RemoveVolume(r.Context(), vol, false, query.Timeout); err != nil {
if errors.Cause(err) == define.ErrVolumeBeingUsed {
utils.Error(w, "volumes being used", http.StatusConflict, err)
} else {
diff --git a/pkg/api/handlers/libpod/pods.go b/pkg/api/handlers/libpod/pods.go
index 7bd6d3dbf..77d026550 100644
--- a/pkg/api/handlers/libpod/pods.go
+++ b/pkg/api/handlers/libpod/pods.go
@@ -246,7 +246,8 @@ func PodDelete(w http.ResponseWriter, r *http.Request) {
decoder = r.Context().Value(api.DecoderKey).(*schema.Decoder)
)
query := struct {
- Force bool `schema:"force"`
+ Force bool `schema:"force"`
+ Timeout *uint `schema:"timeout"`
}{
// override any golang type defaults
}
@@ -262,7 +263,7 @@ func PodDelete(w http.ResponseWriter, r *http.Request) {
utils.PodNotFound(w, name, err)
return
}
- if err := runtime.RemovePod(r.Context(), pod, true, query.Force); err != nil {
+ if err := runtime.RemovePod(r.Context(), pod, true, query.Force, query.Timeout); err != nil {
utils.Error(w, "Something went wrong", http.StatusInternalServerError, err)
return
}
diff --git a/pkg/api/handlers/libpod/volumes.go b/pkg/api/handlers/libpod/volumes.go
index 318758868..3ba39b860 100644
--- a/pkg/api/handlers/libpod/volumes.go
+++ b/pkg/api/handlers/libpod/volumes.go
@@ -169,7 +169,8 @@ func RemoveVolume(w http.ResponseWriter, r *http.Request) {
decoder = r.Context().Value(api.DecoderKey).(*schema.Decoder)
)
query := struct {
- Force bool `schema:"force"`
+ Force bool `schema:"force"`
+ Timeout *uint `schema:"timeout"`
}{
// override any golang type defaults
}
@@ -185,7 +186,7 @@ func RemoveVolume(w http.ResponseWriter, r *http.Request) {
utils.VolumeNotFound(w, name, err)
return
}
- if err := runtime.RemoveVolume(r.Context(), vol, query.Force); err != nil {
+ if err := runtime.RemoveVolume(r.Context(), vol, query.Force, query.Timeout); err != nil {
if errors.Cause(err) == define.ErrVolumeBeingUsed {
utils.Error(w, "volumes being used", http.StatusConflict, err)
return
diff --git a/pkg/bindings/containers/types.go b/pkg/bindings/containers/types.go
index 3fe3442bb..3a7d5a4c7 100644
--- a/pkg/bindings/containers/types.go
+++ b/pkg/bindings/containers/types.go
@@ -132,6 +132,7 @@ type RemoveOptions struct {
Ignore *bool
Force *bool
Volumes *bool
+ Timeout *uint
}
//go:generate go run ../generator/generator.go InspectOptions
diff --git a/pkg/bindings/containers/types_remove_options.go b/pkg/bindings/containers/types_remove_options.go
index 8eaa13c2a..1e52e819d 100644
--- a/pkg/bindings/containers/types_remove_options.go
+++ b/pkg/bindings/containers/types_remove_options.go
@@ -61,3 +61,18 @@ func (o *RemoveOptions) GetVolumes() bool {
}
return *o.Volumes
}
+
+// WithTimeout set field Timeout to given value
+func (o *RemoveOptions) WithTimeout(value uint) *RemoveOptions {
+ o.Timeout = &value
+ return o
+}
+
+// GetTimeout returns value of field Timeout
+func (o *RemoveOptions) GetTimeout() uint {
+ if o.Timeout == nil {
+ var z uint
+ return z
+ }
+ return *o.Timeout
+}
diff --git a/pkg/bindings/network/types.go b/pkg/bindings/network/types.go
index e62ae8f52..8088de061 100644
--- a/pkg/bindings/network/types.go
+++ b/pkg/bindings/network/types.go
@@ -40,7 +40,8 @@ type InspectOptions struct {
// RemoveOptions are optional options for inspecting networks
type RemoveOptions struct {
// Force removes the network even if it is being used
- Force *bool
+ Force *bool
+ Timeout *uint
}
//go:generate go run ../generator/generator.go ListOptions
diff --git a/pkg/bindings/network/types_remove_options.go b/pkg/bindings/network/types_remove_options.go
index 57fc4fa3a..2f7fea77e 100644
--- a/pkg/bindings/network/types_remove_options.go
+++ b/pkg/bindings/network/types_remove_options.go
@@ -31,3 +31,18 @@ func (o *RemoveOptions) GetForce() bool {
}
return *o.Force
}
+
+// WithTimeout set field Timeout to given value
+func (o *RemoveOptions) WithTimeout(value uint) *RemoveOptions {
+ o.Timeout = &value
+ return o
+}
+
+// GetTimeout returns value of field Timeout
+func (o *RemoveOptions) GetTimeout() uint {
+ if o.Timeout == nil {
+ var z uint
+ return z
+ }
+ return *o.Timeout
+}
diff --git a/pkg/bindings/pods/types.go b/pkg/bindings/pods/types.go
index cb41cf623..71fada4eb 100644
--- a/pkg/bindings/pods/types.go
+++ b/pkg/bindings/pods/types.go
@@ -68,7 +68,8 @@ type StatsOptions struct {
//go:generate go run ../generator/generator.go RemoveOptions
// RemoveOptions are optional options for removing pods
type RemoveOptions struct {
- Force *bool
+ Force *bool
+ Timeout *uint
}
//go:generate go run ../generator/generator.go ExistsOptions
diff --git a/pkg/bindings/pods/types_remove_options.go b/pkg/bindings/pods/types_remove_options.go
index ce142ee74..bbcc4d769 100644
--- a/pkg/bindings/pods/types_remove_options.go
+++ b/pkg/bindings/pods/types_remove_options.go
@@ -31,3 +31,18 @@ func (o *RemoveOptions) GetForce() bool {
}
return *o.Force
}
+
+// WithTimeout set field Timeout to given value
+func (o *RemoveOptions) WithTimeout(value uint) *RemoveOptions {
+ o.Timeout = &value
+ return o
+}
+
+// GetTimeout returns value of field Timeout
+func (o *RemoveOptions) GetTimeout() uint {
+ if o.Timeout == nil {
+ var z uint
+ return z
+ }
+ return *o.Timeout
+}
diff --git a/pkg/bindings/volumes/types.go b/pkg/bindings/volumes/types.go
index 3fda77ddd..d2f19c0c8 100644
--- a/pkg/bindings/volumes/types.go
+++ b/pkg/bindings/volumes/types.go
@@ -28,7 +28,8 @@ type PruneOptions struct {
// RemoveOptions are optional options for removing volumes
type RemoveOptions struct {
// Force removes the volume even if it is being used
- Force *bool
+ Force *bool
+ Timeout *uint
}
//go:generate go run ../generator/generator.go ExistsOptions
diff --git a/pkg/bindings/volumes/types_remove_options.go b/pkg/bindings/volumes/types_remove_options.go
index 0e0a3c804..fe079cddf 100644
--- a/pkg/bindings/volumes/types_remove_options.go
+++ b/pkg/bindings/volumes/types_remove_options.go
@@ -31,3 +31,18 @@ func (o *RemoveOptions) GetForce() bool {
}
return *o.Force
}
+
+// WithTimeout set field Timeout to given value
+func (o *RemoveOptions) WithTimeout(value uint) *RemoveOptions {
+ o.Timeout = &value
+ return o
+}
+
+// GetTimeout returns value of field Timeout
+func (o *RemoveOptions) GetTimeout() uint {
+ if o.Timeout == nil {
+ var z uint
+ return z
+ }
+ return *o.Timeout
+}
diff --git a/pkg/domain/entities/containers.go b/pkg/domain/entities/containers.go
index a302cdb7d..deae85fe1 100644
--- a/pkg/domain/entities/containers.go
+++ b/pkg/domain/entities/containers.go
@@ -132,6 +132,7 @@ type RmOptions struct {
Force bool
Ignore bool
Latest bool
+ Timeout *uint
Volumes bool
}
diff --git a/pkg/domain/entities/network.go b/pkg/domain/entities/network.go
index b61297d41..d7389a699 100644
--- a/pkg/domain/entities/network.go
+++ b/pkg/domain/entities/network.go
@@ -27,7 +27,8 @@ type NetworkReloadReport struct {
// NetworkRmOptions describes options for removing networks
type NetworkRmOptions struct {
- Force bool
+ Force bool
+ Timeout *uint
}
//NetworkRmReport describes the results of network removal
diff --git a/pkg/domain/entities/pods.go b/pkg/domain/entities/pods.go
index 653f64b42..309677396 100644
--- a/pkg/domain/entities/pods.go
+++ b/pkg/domain/entities/pods.go
@@ -95,10 +95,11 @@ type PodStartReport struct {
}
type PodRmOptions struct {
- All bool
- Force bool
- Ignore bool
- Latest bool
+ All bool
+ Force bool
+ Ignore bool
+ Latest bool
+ Timeout *uint
}
type PodRmReport struct {
diff --git a/pkg/domain/entities/volumes.go b/pkg/domain/entities/volumes.go
index 62f5401cc..2ecfb4446 100644
--- a/pkg/domain/entities/volumes.go
+++ b/pkg/domain/entities/volumes.go
@@ -94,8 +94,9 @@ type VolumeConfigResponse struct {
}
type VolumeRmOptions struct {
- All bool
- Force bool
+ All bool
+ Force bool
+ Timeout *uint
}
type VolumeRmReport struct {
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index 8e7e2d411..6ca142618 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -283,7 +283,7 @@ func (ic *ContainerEngine) ContainerRestart(ctx context.Context, namesOrIds []st
}
func (ic *ContainerEngine) removeContainer(ctx context.Context, ctr *libpod.Container, options entities.RmOptions) error {
- err := ic.Libpod.RemoveContainer(ctx, ctr, options.Force, options.Volumes)
+ err := ic.Libpod.RemoveContainer(ctx, ctr, options.Force, options.Volumes, options.Timeout)
if err == nil {
return nil
}
@@ -963,7 +963,8 @@ func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.Conta
return &report, nil
}
if opts.Rm {
- if deleteError := ic.Libpod.RemoveContainer(ctx, ctr, true, false); deleteError != nil {
+ var timeout *uint
+ if deleteError := ic.Libpod.RemoveContainer(ctx, ctr, true, false, timeout); deleteError != nil {
logrus.Debugf("unable to remove container %s after failing to start and attach to it", ctr.ID())
}
}
@@ -977,7 +978,8 @@ func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.Conta
}
report.ExitCode = ic.GetContainerExitCode(ctx, ctr)
if opts.Rm && !ctr.ShouldRestart(ctx) {
- if err := ic.Libpod.RemoveContainer(ctx, ctr, false, true); err != nil {
+ var timeout *uint
+ if err := ic.Libpod.RemoveContainer(ctx, ctr, false, true, timeout); err != nil {
if errors.Cause(err) == define.ErrNoSuchCtr ||
errors.Cause(err) == define.ErrCtrRemoved {
logrus.Infof("Container %s was already removed, skipping --rm", ctr.ID())
@@ -1082,7 +1084,8 @@ func (ic *ContainerEngine) ContainerCleanup(ctx context.Context, namesOrIds []st
}
if options.Remove && !ctr.ShouldRestart(ctx) {
- err = ic.Libpod.RemoveContainer(ctx, ctr, false, true)
+ var timeout *uint
+ err = ic.Libpod.RemoveContainer(ctx, ctr, false, true, timeout)
if err != nil {
report.RmErr = errors.Wrapf(err, "failed to cleanup and remove container %v", ctr.ID())
}
diff --git a/pkg/domain/infra/abi/containers_runlabel.go b/pkg/domain/infra/abi/containers_runlabel.go
index add82f0fb..b0aae4b76 100644
--- a/pkg/domain/infra/abi/containers_runlabel.go
+++ b/pkg/domain/infra/abi/containers_runlabel.go
@@ -92,7 +92,8 @@ func (ic *ContainerEngine) ContainerRunlabel(ctx context.Context, label string,
}
} else {
logrus.Debugf("Runlabel --replace option given. Container %s will be deleted. The new container will be named %s", ctr.ID(), name)
- if err := ic.Libpod.RemoveContainer(ctx, ctr, true, false); err != nil {
+ var timeout *uint
+ if err := ic.Libpod.RemoveContainer(ctx, ctr, true, false, timeout); err != nil {
return err
}
}
diff --git a/pkg/domain/infra/abi/network.go b/pkg/domain/infra/abi/network.go
index d792226a8..ee7403ed5 100644
--- a/pkg/domain/infra/abi/network.go
+++ b/pkg/domain/infra/abi/network.go
@@ -91,10 +91,10 @@ func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, o
if err != nil {
return reports, err
}
- if err := ic.Libpod.RemovePod(ctx, pod, true, true); err != nil {
+ if err := ic.Libpod.RemovePod(ctx, pod, true, true, options.Timeout); err != nil {
return reports, err
}
- } else if err := ic.Libpod.RemoveContainer(ctx, c, true, true); err != nil && errors.Cause(err) != define.ErrNoSuchCtr {
+ } else if err := ic.Libpod.RemoveContainer(ctx, c, true, true, options.Timeout); err != nil && errors.Cause(err) != define.ErrNoSuchCtr {
return reports, err
}
}
diff --git a/pkg/domain/infra/abi/pods.go b/pkg/domain/infra/abi/pods.go
index 6b432c214..028de9e81 100644
--- a/pkg/domain/infra/abi/pods.go
+++ b/pkg/domain/infra/abi/pods.go
@@ -259,7 +259,7 @@ func (ic *ContainerEngine) PodRm(ctx context.Context, namesOrIds []string, optio
reports := make([]*entities.PodRmReport, 0, len(pods))
for _, p := range pods {
report := entities.PodRmReport{Id: p.ID()}
- err := ic.Libpod.RemovePod(ctx, p, true, options.Force)
+ err := ic.Libpod.RemovePod(ctx, p, true, options.Force, options.Timeout)
if err != nil {
report.Err = err
}
diff --git a/pkg/domain/infra/abi/volumes.go b/pkg/domain/infra/abi/volumes.go
index 1610c0b48..e514631db 100644
--- a/pkg/domain/infra/abi/volumes.go
+++ b/pkg/domain/infra/abi/volumes.go
@@ -66,7 +66,7 @@ func (ic *ContainerEngine) VolumeRm(ctx context.Context, namesOrIds []string, op
}
for _, vol := range vols {
reports = append(reports, &entities.VolumeRmReport{
- Err: ic.Libpod.RemoveVolume(ctx, vol, opts.Force),
+ Err: ic.Libpod.RemoveVolume(ctx, vol, opts.Force, opts.Timeout),
Id: vol.Name(),
})
}
diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go
index 9fe2d163c..3f78ba7bc 100644
--- a/pkg/domain/infra/tunnel/containers.go
+++ b/pkg/domain/infra/tunnel/containers.go
@@ -185,7 +185,9 @@ func (ic *ContainerEngine) ContainerRestart(ctx context.Context, namesOrIds []st
func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string, opts entities.RmOptions) ([]*entities.RmReport, error) {
// TODO there is no endpoint for container eviction. Need to discuss
options := new(containers.RemoveOptions).WithForce(opts.Force).WithVolumes(opts.Volumes).WithIgnore(opts.Ignore)
-
+ if opts.Timeout != nil {
+ options = options.WithTimeout(*opts.Timeout)
+ }
if opts.All {
ctrs, err := getContainersByContext(ic.ClientCtx, opts.All, opts.Ignore, namesOrIds)
if err != nil {
diff --git a/pkg/domain/infra/tunnel/network.go b/pkg/domain/infra/tunnel/network.go
index 6f227f565..79fba1943 100644
--- a/pkg/domain/infra/tunnel/network.go
+++ b/pkg/domain/infra/tunnel/network.go
@@ -47,6 +47,9 @@ func (ic *ContainerEngine) NetworkReload(ctx context.Context, names []string, op
func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, opts entities.NetworkRmOptions) ([]*entities.NetworkRmReport, error) {
reports := make([]*entities.NetworkRmReport, 0, len(namesOrIds))
options := new(network.RemoveOptions).WithForce(opts.Force)
+ if opts.Timeout != nil {
+ options = options.WithTimeout(*opts.Timeout)
+ }
for _, name := range namesOrIds {
response, err := network.Remove(ic.ClientCtx, name, options)
if err != nil {
diff --git a/pkg/domain/infra/tunnel/pods.go b/pkg/domain/infra/tunnel/pods.go
index 8139216b3..bd3df1aa7 100644
--- a/pkg/domain/infra/tunnel/pods.go
+++ b/pkg/domain/infra/tunnel/pods.go
@@ -169,6 +169,9 @@ func (ic *ContainerEngine) PodRm(ctx context.Context, namesOrIds []string, opts
}
reports := make([]*entities.PodRmReport, 0, len(foundPods))
options := new(pods.RemoveOptions).WithForce(opts.Force)
+ if opts.Timeout != nil {
+ options = options.WithTimeout(*opts.Timeout)
+ }
for _, p := range foundPods {
response, err := pods.Remove(ic.ClientCtx, p.Id, options)
if err != nil {
diff --git a/pkg/domain/infra/tunnel/volumes.go b/pkg/domain/infra/tunnel/volumes.go
index 2b2b2c2a1..cfd1574c3 100644
--- a/pkg/domain/infra/tunnel/volumes.go
+++ b/pkg/domain/infra/tunnel/volumes.go
@@ -31,6 +31,9 @@ func (ic *ContainerEngine) VolumeRm(ctx context.Context, namesOrIds []string, op
reports := make([]*entities.VolumeRmReport, 0, len(namesOrIds))
for _, id := range namesOrIds {
options := new(volumes.RemoveOptions).WithForce(opts.Force)
+ if opts.Timeout != nil {
+ options = options.WithTimeout(*opts.Timeout)
+ }
reports = append(reports, &entities.VolumeRmReport{
Err: volumes.Remove(ic.ClientCtx, id, options),
Id: id,