summaryrefslogtreecommitdiff
path: root/cmd/podman/volumes
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/volumes')
-rw-r--r--cmd/podman/volumes/create.go5
-rw-r--r--cmd/podman/volumes/export.go2
-rw-r--r--cmd/podman/volumes/import.go2
-rw-r--r--cmd/podman/volumes/inspect.go3
-rw-r--r--cmd/podman/volumes/list.go4
-rw-r--r--cmd/podman/volumes/reload.go52
-rw-r--r--cmd/podman/volumes/rm.go12
7 files changed, 63 insertions, 17 deletions
diff --git a/cmd/podman/volumes/create.go b/cmd/podman/volumes/create.go
index b47ae16ce..0d19fab47 100644
--- a/cmd/podman/volumes/create.go
+++ b/cmd/podman/volumes/create.go
@@ -8,7 +8,6 @@ import (
"github.com/containers/podman/v4/cmd/podman/parse"
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/pkg/domain/entities"
- "github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -65,11 +64,11 @@ func create(cmd *cobra.Command, args []string) error {
}
createOpts.Label, err = parse.GetAllLabels([]string{}, opts.Label)
if err != nil {
- return errors.Wrapf(err, "unable to process labels")
+ return fmt.Errorf("unable to process labels: %w", err)
}
createOpts.Options, err = parse.GetAllLabels([]string{}, opts.Opts)
if err != nil {
- return errors.Wrapf(err, "unable to process options")
+ return fmt.Errorf("unable to process options: %w", err)
}
response, err := registry.ContainerEngine().VolumeCreate(context.Background(), createOpts)
if err != nil {
diff --git a/cmd/podman/volumes/export.go b/cmd/podman/volumes/export.go
index 113f79a0b..f9e08be87 100644
--- a/cmd/podman/volumes/export.go
+++ b/cmd/podman/volumes/export.go
@@ -2,6 +2,7 @@ package volumes
import (
"context"
+ "errors"
"fmt"
"github.com/containers/common/pkg/completion"
@@ -10,7 +11,6 @@ import (
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/errorhandling"
"github.com/containers/podman/v4/utils"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
diff --git a/cmd/podman/volumes/import.go b/cmd/podman/volumes/import.go
index 76a311643..8f3c7f27e 100644
--- a/cmd/podman/volumes/import.go
+++ b/cmd/podman/volumes/import.go
@@ -1,6 +1,7 @@
package volumes
import (
+ "errors"
"fmt"
"os"
@@ -10,7 +11,6 @@ import (
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/errorhandling"
"github.com/containers/podman/v4/utils"
- "github.com/pkg/errors"
"github.com/spf13/cobra"
)
diff --git a/cmd/podman/volumes/inspect.go b/cmd/podman/volumes/inspect.go
index 7cf363f36..68ba2976a 100644
--- a/cmd/podman/volumes/inspect.go
+++ b/cmd/podman/volumes/inspect.go
@@ -1,12 +1,13 @@
package volumes
import (
+ "errors"
+
"github.com/containers/podman/v4/cmd/podman/common"
"github.com/containers/podman/v4/cmd/podman/inspect"
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/domain/entities"
- "github.com/pkg/errors"
"github.com/spf13/cobra"
)
diff --git a/cmd/podman/volumes/list.go b/cmd/podman/volumes/list.go
index c14cf08bd..06118513d 100644
--- a/cmd/podman/volumes/list.go
+++ b/cmd/podman/volumes/list.go
@@ -2,6 +2,7 @@ package volumes
import (
"context"
+ "errors"
"fmt"
"os"
@@ -12,7 +13,6 @@ import (
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/cmd/podman/validate"
"github.com/containers/podman/v4/pkg/domain/entities"
- "github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -119,7 +119,7 @@ func outputTemplate(cmd *cobra.Command, responses []*entities.VolumeListReport)
if !(noHeading || cliOpts.Quiet || cmd.Flag("format").Changed) {
if err := tmpl.Execute(w, headers); err != nil {
- return errors.Wrapf(err, "failed to write report column headers")
+ return fmt.Errorf("failed to write report column headers: %w", err)
}
}
return tmpl.Execute(w, responses)
diff --git a/cmd/podman/volumes/reload.go b/cmd/podman/volumes/reload.go
new file mode 100644
index 000000000..d0d76fb88
--- /dev/null
+++ b/cmd/podman/volumes/reload.go
@@ -0,0 +1,52 @@
+package volumes
+
+import (
+ "fmt"
+
+ "github.com/containers/common/pkg/completion"
+ "github.com/containers/podman/v4/cmd/podman/registry"
+ "github.com/containers/podman/v4/cmd/podman/utils"
+ "github.com/containers/podman/v4/cmd/podman/validate"
+ "github.com/spf13/cobra"
+)
+
+var (
+ reloadDescription = `Check all configured volume plugins and update the libpod database with all available volumes.
+
+ Existing volumes are also removed from the database when they are no longer present in the plugin.`
+ reloadCommand = &cobra.Command{
+ Use: "reload",
+ Args: validate.NoArgs,
+ Short: "reload all volumes from volume plugins",
+ Long: reloadDescription,
+ RunE: reload,
+ ValidArgsFunction: completion.AutocompleteNone,
+ }
+)
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Command: reloadCommand,
+ Parent: volumeCmd,
+ })
+}
+
+func reload(cmd *cobra.Command, args []string) error {
+ report, err := registry.ContainerEngine().VolumeReload(registry.Context())
+ if err != nil {
+ return err
+ }
+ printReload("Added", report.Added)
+ printReload("Removed", report.Removed)
+ errs := (utils.OutputErrors)(report.Errors)
+ return errs.PrintErrors()
+}
+
+func printReload(typ string, values []string) {
+ if len(values) > 0 {
+ fmt.Println(typ + ":")
+ for _, name := range values {
+ fmt.Println(name)
+ }
+ }
+}
diff --git a/cmd/podman/volumes/rm.go b/cmd/podman/volumes/rm.go
index 2012b7d3a..c160b8623 100644
--- a/cmd/podman/volumes/rm.go
+++ b/cmd/podman/volumes/rm.go
@@ -2,6 +2,7 @@ package volumes
import (
"context"
+ "errors"
"fmt"
"strings"
@@ -11,7 +12,6 @@ import (
"github.com/containers/podman/v4/cmd/podman/utils"
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/domain/entities"
- "github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -80,15 +80,9 @@ func rm(cmd *cobra.Command, args []string) error {
}
func setExitCode(err error) {
- cause := errors.Cause(err)
- switch {
- case cause == define.ErrNoSuchVolume:
+ if errors.Is(err, define.ErrNoSuchVolume) || strings.Contains(err.Error(), define.ErrNoSuchVolume.Error()) {
registry.SetExitCode(1)
- case strings.Contains(cause.Error(), define.ErrNoSuchVolume.Error()):
- registry.SetExitCode(1)
- case cause == define.ErrVolumeBeingUsed:
- registry.SetExitCode(2)
- case strings.Contains(cause.Error(), define.ErrVolumeBeingUsed.Error()):
+ } else if errors.Is(err, define.ErrVolumeBeingUsed) || strings.Contains(err.Error(), define.ErrVolumeBeingUsed.Error()) {
registry.SetExitCode(2)
}
}