summaryrefslogtreecommitdiff
path: root/cmd/podman/pods
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/pods')
-rw-r--r--cmd/podman/pods/clone.go92
-rw-r--r--cmd/podman/pods/create.go17
-rw-r--r--cmd/podman/pods/inspect.go6
-rw-r--r--cmd/podman/pods/logs.go9
-rw-r--r--cmd/podman/pods/ps.go10
-rw-r--r--cmd/podman/pods/rm.go8
-rw-r--r--cmd/podman/pods/top.go4
7 files changed, 118 insertions, 28 deletions
diff --git a/cmd/podman/pods/clone.go b/cmd/podman/pods/clone.go
new file mode 100644
index 000000000..9558c6aed
--- /dev/null
+++ b/cmd/podman/pods/clone.go
@@ -0,0 +1,92 @@
+package pods
+
+import (
+ "context"
+ "fmt"
+
+ "github.com/containers/common/pkg/completion"
+ "github.com/containers/podman/v4/cmd/podman/common"
+ "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/spf13/cobra"
+)
+
+var (
+ podCloneDescription = `Create an exact copy of a pod and the containers within it`
+
+ podCloneCommand = &cobra.Command{
+ Use: "clone [options] POD NAME",
+ Short: "Clone an existing pod",
+ Long: podCloneDescription,
+ RunE: clone,
+ Args: cobra.RangeArgs(1, 2),
+ ValidArgsFunction: common.AutocompleteClone,
+ Example: `podman pod clone pod_name new_name`,
+ }
+)
+
+var (
+ podClone entities.PodCloneOptions
+)
+
+func cloneFlags(cmd *cobra.Command) {
+ flags := cmd.Flags()
+
+ destroyFlagName := "destroy"
+ flags.BoolVar(&podClone.Destroy, destroyFlagName, false, "destroy the original pod")
+
+ startFlagName := "start"
+ flags.BoolVar(&podClone.Start, startFlagName, false, "start the new pod")
+
+ nameFlagName := "name"
+ flags.StringVarP(&podClone.CreateOpts.Name, nameFlagName, "n", "", "name the new pod")
+ _ = podCloneCommand.RegisterFlagCompletionFunc(nameFlagName, completion.AutocompleteNone)
+
+ common.DefineCreateDefaults(&podClone.InfraOptions)
+ common.DefineCreateFlags(cmd, &podClone.InfraOptions, true, false)
+
+ podClone.InfraOptions.MemorySwappiness = -1 // this is not implemented for pods yet, need to set -1 default manually
+
+ // need to fill an empty ctr create option for each container for sane defaults
+ // for now, these cannot be used. The flag names conflict too much
+ // this makes sense since this is a pod command not a container command
+ // TODO: add support for container specific arguments/flags
+ common.DefineCreateDefaults(&podClone.PerContainerOptions)
+}
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Command: podCloneCommand,
+ Parent: podCmd,
+ })
+
+ cloneFlags(podCloneCommand)
+}
+
+func clone(cmd *cobra.Command, args []string) error {
+ switch len(args) {
+ case 0:
+ return fmt.Errorf("must specify at least 1 argument: %w", define.ErrInvalidArg)
+ case 2:
+ podClone.CreateOpts.Name = args[1]
+ }
+
+ podClone.ID = args[0]
+
+ if cmd.Flag("shm-size").Changed {
+ podClone.InfraOptions.ShmSize = cmd.Flag("shm-size").Value.String()
+ }
+
+ podClone.PerContainerOptions.IsClone = true
+ rep, err := registry.ContainerEngine().PodClone(context.Background(), podClone)
+ if err != nil {
+ if rep != nil {
+ fmt.Printf("pod %s created but error after creation\n", rep.Id)
+ }
+ return err
+ }
+
+ fmt.Println(rep.Id)
+
+ return nil
+}
diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go
index e2f80bdbc..45ad2dfd0 100644
--- a/cmd/podman/pods/create.go
+++ b/cmd/podman/pods/create.go
@@ -2,6 +2,7 @@ package pods
import (
"context"
+ "errors"
"fmt"
"io/ioutil"
"os"
@@ -23,7 +24,6 @@ import (
"github.com/containers/podman/v4/pkg/specgenutil"
"github.com/containers/podman/v4/pkg/util"
"github.com/docker/docker/pkg/parsers"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
@@ -64,6 +64,7 @@ func init() {
})
flags := createCommand.Flags()
flags.SetInterspersed(false)
+ common.DefineCreateDefaults(&infraOptions)
common.DefineCreateFlags(createCommand, &infraOptions, true, false)
common.DefineNetFlags(createCommand)
@@ -126,7 +127,7 @@ func create(cmd *cobra.Command, args []string) error {
labels = infraOptions.Label
createOptions.Labels, err = parse.GetAllLabels(labelFile, labels)
if err != nil {
- return errors.Wrapf(err, "unable to process labels")
+ return fmt.Errorf("unable to process labels: %w", err)
}
if cmd.Flag("infra-image").Changed {
@@ -164,7 +165,7 @@ func create(cmd *cobra.Command, args []string) error {
return err
}
if strings.Contains(share, "cgroup") && shareParent {
- return errors.Wrapf(define.ErrInvalidArg, "cannot define the pod as the cgroup parent at the same time as joining the infra container's cgroupNS")
+ return fmt.Errorf("cannot define the pod as the cgroup parent at the same time as joining the infra container's cgroupNS: %w", define.ErrInvalidArg)
}
if strings.HasPrefix(share, "+") {
@@ -192,10 +193,10 @@ func create(cmd *cobra.Command, args []string) error {
if cmd.Flag("pod-id-file").Changed {
podIDFD, err = util.OpenExclusiveFile(podIDFile)
if err != nil && os.IsExist(err) {
- return errors.Errorf("pod id file exists. Ensure another pod is not using it or delete %s", podIDFile)
+ return fmt.Errorf("pod id file exists. Ensure another pod is not using it or delete %s", podIDFile)
}
if err != nil {
- return errors.Errorf("opening pod-id-file %s", podIDFile)
+ return fmt.Errorf("opening pod-id-file %s", podIDFile)
}
defer errorhandling.CloseQuiet(podIDFD)
defer errorhandling.SyncQuiet(podIDFD)
@@ -203,7 +204,7 @@ func create(cmd *cobra.Command, args []string) error {
if len(createOptions.Net.PublishPorts) > 0 {
if !createOptions.Infra {
- return errors.Errorf("you must have an infra container to publish port bindings to the host")
+ return fmt.Errorf("you must have an infra container to publish port bindings to the host")
}
}
@@ -230,7 +231,7 @@ func create(cmd *cobra.Command, args []string) error {
ret, err := parsers.ParseUintList(copy)
copy = ""
if err != nil {
- return errors.Wrapf(err, "could not parse list")
+ return fmt.Errorf("could not parse list: %w", err)
}
var vals []int
for ind, val := range ret {
@@ -300,7 +301,7 @@ func create(cmd *cobra.Command, args []string) error {
if len(podIDFile) > 0 {
if err = ioutil.WriteFile(podIDFile, []byte(response.Id), 0644); err != nil {
- return errors.Wrapf(err, "failed to write pod ID to file")
+ return fmt.Errorf("failed to write pod ID to file: %w", err)
}
}
fmt.Println(response.Id)
diff --git a/cmd/podman/pods/inspect.go b/cmd/podman/pods/inspect.go
index bb30fe6e6..082e8d9a1 100644
--- a/cmd/podman/pods/inspect.go
+++ b/cmd/podman/pods/inspect.go
@@ -2,6 +2,7 @@ package pods
import (
"context"
+ "errors"
"os"
"text/template"
@@ -10,7 +11,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"
)
@@ -49,10 +49,10 @@ func init() {
func inspect(cmd *cobra.Command, args []string) error {
if len(args) < 1 && !inspectOptions.Latest {
- return errors.Errorf("you must provide the name or id of a running pod")
+ return errors.New("you must provide the name or id of a running pod")
}
if len(args) > 0 && inspectOptions.Latest {
- return errors.Errorf("--latest and containers cannot be used together")
+ return errors.New("--latest and containers cannot be used together")
}
if !inspectOptions.Latest {
diff --git a/cmd/podman/pods/logs.go b/cmd/podman/pods/logs.go
index 28e7b7a43..0102d4b71 100644
--- a/cmd/podman/pods/logs.go
+++ b/cmd/podman/pods/logs.go
@@ -1,6 +1,8 @@
package pods
import (
+ "errors"
+ "fmt"
"os"
"github.com/containers/common/pkg/completion"
@@ -10,7 +12,6 @@ import (
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/util"
- "github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -100,7 +101,7 @@ func logs(_ *cobra.Command, args []string) error {
// parse time, error out if something is wrong
since, err := util.ParseInputTime(logsPodOptions.SinceRaw, true)
if err != nil {
- return errors.Wrapf(err, "error parsing --since %q", logsPodOptions.SinceRaw)
+ return fmt.Errorf("error parsing --since %q: %w", logsPodOptions.SinceRaw, err)
}
logsPodOptions.Since = since
}
@@ -108,14 +109,14 @@ func logs(_ *cobra.Command, args []string) error {
// parse time, error out if something is wrong
until, err := util.ParseInputTime(logsPodOptions.UntilRaw, false)
if err != nil {
- return errors.Wrapf(err, "error parsing --until %q", logsPodOptions.UntilRaw)
+ return fmt.Errorf("error parsing --until %q: %w", logsPodOptions.UntilRaw, err)
}
logsPodOptions.Until = until
}
// Remote can only process one container at a time
if registry.IsRemote() && logsPodOptions.ContainerName == "" {
- return errors.Wrapf(define.ErrInvalidArg, "-c or --container cannot be empty")
+ return fmt.Errorf("-c or --container cannot be empty: %w", define.ErrInvalidArg)
}
logsPodOptions.StdoutWriter = os.Stdout
diff --git a/cmd/podman/pods/ps.go b/cmd/podman/pods/ps.go
index aa42e1983..681c9c42e 100644
--- a/cmd/podman/pods/ps.go
+++ b/cmd/podman/pods/ps.go
@@ -2,6 +2,7 @@ package pods
import (
"context"
+ "errors"
"fmt"
"os"
"sort"
@@ -15,7 +16,6 @@ import (
"github.com/containers/podman/v4/cmd/podman/validate"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/docker/go-units"
- "github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -80,7 +80,7 @@ func pods(cmd *cobra.Command, _ []string) error {
for _, f := range inputFilters {
split := strings.SplitN(f, "=", 2)
if len(split) < 2 {
- return errors.Errorf("filter input must be in the form of filter=value: %s is invalid", f)
+ return fmt.Errorf("filter input must be in the form of filter=value: %s is invalid", f)
}
psInput.Filters[split[0]] = append(psInput.Filters[split[0]], split[1])
}
@@ -211,7 +211,7 @@ func (l ListPodReporter) ID() string {
}
// Id returns the Pod id
-func (l ListPodReporter) Id() string { // nolint
+func (l ListPodReporter) Id() string { //nolint:revive,stylecheck
if noTrunc {
return l.ListPodsReport.Id
}
@@ -225,7 +225,7 @@ func (l ListPodReporter) InfraID() string {
// InfraId returns the infra container id for the pod
// depending on trunc
-func (l ListPodReporter) InfraId() string { // nolint
+func (l ListPodReporter) InfraId() string { //nolint:revive,stylecheck
if len(l.ListPodsReport.InfraId) == 0 {
return ""
}
@@ -276,7 +276,7 @@ func sortPodPsOutput(sortBy string, lprs []*entities.ListPodsReport) error {
case "status":
sort.Sort(podPsSortedStatus{lprs})
default:
- return errors.Errorf("invalid option for --sort, options are: id, names, or number")
+ return errors.New("invalid option for --sort, options are: id, names, or number")
}
return nil
}
diff --git a/cmd/podman/pods/rm.go b/cmd/podman/pods/rm.go
index 16b7191c9..2ffd968f9 100644
--- a/cmd/podman/pods/rm.go
+++ b/cmd/podman/pods/rm.go
@@ -2,6 +2,7 @@ package pods
import (
"context"
+ "errors"
"fmt"
"strings"
@@ -13,7 +14,6 @@ import (
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/specgenutil"
- "github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -112,11 +112,7 @@ func removePods(namesOrIDs []string, rmOptions entities.PodRmOptions, printIDs b
}
func setExitCode(err error) {
- cause := errors.Cause(err)
- switch {
- case cause == define.ErrNoSuchPod:
- registry.SetExitCode(1)
- case strings.Contains(cause.Error(), define.ErrNoSuchPod.Error()):
+ if errors.Is(err, define.ErrNoSuchPod) || strings.Contains(err.Error(), define.ErrNoSuchPod.Error()) {
registry.SetExitCode(1)
}
}
diff --git a/cmd/podman/pods/top.go b/cmd/podman/pods/top.go
index 4e9c7a3ee..34f3d1c33 100644
--- a/cmd/podman/pods/top.go
+++ b/cmd/podman/pods/top.go
@@ -2,6 +2,7 @@ package pods
import (
"context"
+ "errors"
"fmt"
"os"
"strings"
@@ -12,7 +13,6 @@ import (
"github.com/containers/podman/v4/cmd/podman/validate"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/util"
- "github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -67,7 +67,7 @@ func top(_ *cobra.Command, args []string) error {
}
if len(args) < 1 && !topOptions.Latest {
- return errors.Errorf("you must provide the name or id of a running pod")
+ return errors.New("you must provide the name or id of a running pod")
}
if topOptions.Latest {