summaryrefslogtreecommitdiff
path: root/pkg/domain/infra/abi
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/domain/infra/abi')
-rw-r--r--pkg/domain/infra/abi/containers.go3
-rw-r--r--pkg/domain/infra/abi/generate.go9
-rw-r--r--pkg/domain/infra/abi/images_list.go14
-rw-r--r--pkg/domain/infra/abi/parse/parse.go18
-rw-r--r--pkg/domain/infra/abi/pods_stats.go4
-rw-r--r--pkg/domain/infra/abi/system.go29
-rw-r--r--pkg/domain/infra/abi/terminal/terminal.go14
-rw-r--r--pkg/domain/infra/abi/terminal/terminal_linux.go14
-rw-r--r--pkg/domain/infra/abi/trust.go15
9 files changed, 60 insertions, 60 deletions
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index 1688be57e..23a591604 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -101,6 +101,9 @@ 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()}
+ if options.Condition == nil {
+ options.Condition = []define.ContainerStatus{define.ContainerStateStopped, define.ContainerStateExited}
+ }
exitCode, err := c.WaitForConditionWithInterval(ctx, options.Interval, options.Condition...)
if err != nil {
response.Error = err
diff --git a/pkg/domain/infra/abi/generate.go b/pkg/domain/infra/abi/generate.go
index 8b2193cb2..31885ce54 100644
--- a/pkg/domain/infra/abi/generate.go
+++ b/pkg/domain/infra/abi/generate.go
@@ -12,7 +12,6 @@ import (
k8sAPI "github.com/containers/podman/v4/pkg/k8s.io/api/core/v1"
"github.com/containers/podman/v4/pkg/systemd/generate"
"github.com/ghodss/yaml"
- "github.com/pkg/errors"
)
func (ic *ContainerEngine) GenerateSystemd(ctx context.Context, nameOrID string, options entities.GenerateSystemdOptions) (*entities.GenerateSystemdReport, error) {
@@ -30,8 +29,8 @@ func (ic *ContainerEngine) GenerateSystemd(ctx context.Context, nameOrID string,
// If it's not a container, we either have a pod or garbage.
pod, err := ic.Libpod.LookupPod(nameOrID)
if err != nil {
- err = errors.Wrap(ctrErr, err.Error())
- return nil, errors.Wrapf(err, "%s does not refer to a container or pod", nameOrID)
+ err = fmt.Errorf("%v: %w", err.Error(), ctrErr)
+ return nil, fmt.Errorf("%s does not refer to a container or pod: %w", nameOrID, err)
}
// Generate the units for the pod and all its containers.
@@ -64,7 +63,7 @@ func (ic *ContainerEngine) GenerateKube(ctx context.Context, nameOrIDs []string,
// now that infra holds NS data, we need to support dependencies.
// we cannot deal with ctrs already in a pod.
if len(ctr.PodID()) > 0 {
- return nil, errors.Errorf("container %s is associated with pod %s: use generate on the pod itself", ctr.ID(), ctr.PodID())
+ return nil, fmt.Errorf("container %s is associated with pod %s: use generate on the pod itself", ctr.ID(), ctr.PodID())
}
ctrs = append(ctrs, ctr)
continue
@@ -104,7 +103,7 @@ func (ic *ContainerEngine) GenerateKube(ctx context.Context, nameOrIDs []string,
}
// If it reaches here is because the name or id did not exist.
- return nil, errors.Errorf("Name or ID %q not found", nameOrID)
+ return nil, fmt.Errorf("name or ID %q not found", nameOrID)
}
if !defaultKubeNS {
diff --git a/pkg/domain/infra/abi/images_list.go b/pkg/domain/infra/abi/images_list.go
index 8f5591e92..96e99fbf0 100644
--- a/pkg/domain/infra/abi/images_list.go
+++ b/pkg/domain/infra/abi/images_list.go
@@ -2,10 +2,10 @@ package abi
import (
"context"
+ "fmt"
"github.com/containers/common/libimage"
"github.com/containers/podman/v4/pkg/domain/entities"
- "github.com/pkg/errors"
)
func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) ([]*entities.ImageSummary, error) {
@@ -28,11 +28,11 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions)
for _, img := range images {
repoDigests, err := img.RepoDigests()
if err != nil {
- return nil, errors.Wrapf(err, "getting repoDigests from image %q", img.ID())
+ return nil, fmt.Errorf("getting repoDigests from image %q: %w", img.ID(), err)
}
isDangling, err := img.IsDangling(ctx)
if err != nil {
- return nil, errors.Wrapf(err, "error checking if image %q is dangling", img.ID())
+ return nil, fmt.Errorf("error checking if image %q is dangling: %w", img.ID(), err)
}
e := entities.ImageSummary{
@@ -49,18 +49,18 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions)
}
e.Labels, err = img.Labels(ctx)
if err != nil {
- return nil, errors.Wrapf(err, "error retrieving label for image %q: you may need to remove the image to resolve the error", img.ID())
+ return nil, fmt.Errorf("error retrieving label for image %q: you may need to remove the image to resolve the error: %w", img.ID(), err)
}
ctnrs, err := img.Containers()
if err != nil {
- return nil, errors.Wrapf(err, "error retrieving containers for image %q: you may need to remove the image to resolve the error", img.ID())
+ return nil, fmt.Errorf("error retrieving containers for image %q: you may need to remove the image to resolve the error: %w", img.ID(), err)
}
e.Containers = len(ctnrs)
sz, err := img.Size()
if err != nil {
- return nil, errors.Wrapf(err, "error retrieving size of image %q: you may need to remove the image to resolve the error", img.ID())
+ return nil, fmt.Errorf("error retrieving size of image %q: you may need to remove the image to resolve the error: %w", img.ID(), err)
}
e.Size = sz
// This is good enough for now, but has to be
@@ -69,7 +69,7 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions)
parent, err := img.Parent(ctx)
if err != nil {
- return nil, errors.Wrapf(err, "error retrieving parent of image %q: you may need to remove the image to resolve the error", img.ID())
+ return nil, fmt.Errorf("error retrieving parent of image %q: you may need to remove the image to resolve the error: %w", img.ID(), err)
}
if parent != nil {
e.ParentId = parent.ID()
diff --git a/pkg/domain/infra/abi/parse/parse.go b/pkg/domain/infra/abi/parse/parse.go
index 4e8c2e508..19699589b 100644
--- a/pkg/domain/infra/abi/parse/parse.go
+++ b/pkg/domain/infra/abi/parse/parse.go
@@ -1,13 +1,13 @@
package parse
import (
+ "fmt"
"strconv"
"strings"
"github.com/containers/podman/v4/libpod"
"github.com/containers/podman/v4/libpod/define"
units "github.com/docker/go-units"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -32,7 +32,7 @@ func VolumeOptions(opts map[string]string) ([]libpod.VolumeCreateOption, error)
case "size":
size, err := units.FromHumanSize(splitO[1])
if err != nil {
- return nil, errors.Wrapf(err, "cannot convert size %s to integer", splitO[1])
+ return nil, fmt.Errorf("cannot convert size %s to integer: %w", splitO[1], err)
}
libpodOptions = append(libpodOptions, libpod.WithVolumeSize(uint64(size)))
finalVal = append(finalVal, o)
@@ -41,7 +41,7 @@ func VolumeOptions(opts map[string]string) ([]libpod.VolumeCreateOption, error)
case "inodes":
inodes, err := strconv.ParseUint(splitO[1], 10, 64)
if err != nil {
- return nil, errors.Wrapf(err, "cannot convert inodes %s to integer", splitO[1])
+ return nil, fmt.Errorf("cannot convert inodes %s to integer: %w", splitO[1], err)
}
libpodOptions = append(libpodOptions, libpod.WithVolumeInodes(inodes))
finalVal = append(finalVal, o)
@@ -49,11 +49,11 @@ func VolumeOptions(opts map[string]string) ([]libpod.VolumeCreateOption, error)
volumeOptions["INODES"] = splitO[1]
case "uid":
if len(splitO) != 2 {
- return nil, errors.Wrapf(define.ErrInvalidArg, "uid option must provide a UID")
+ return nil, fmt.Errorf("uid option must provide a UID: %w", define.ErrInvalidArg)
}
intUID, err := strconv.Atoi(splitO[1])
if err != nil {
- return nil, errors.Wrapf(err, "cannot convert UID %s to integer", splitO[1])
+ return nil, fmt.Errorf("cannot convert UID %s to integer: %w", splitO[1], err)
}
logrus.Debugf("Removing uid= from options and adding WithVolumeUID for UID %d", intUID)
libpodOptions = append(libpodOptions, libpod.WithVolumeUID(intUID), libpod.WithVolumeNoChown())
@@ -62,11 +62,11 @@ func VolumeOptions(opts map[string]string) ([]libpod.VolumeCreateOption, error)
volumeOptions["UID"] = splitO[1]
case "gid":
if len(splitO) != 2 {
- return nil, errors.Wrapf(define.ErrInvalidArg, "gid option must provide a GID")
+ return nil, fmt.Errorf("gid option must provide a GID: %w", define.ErrInvalidArg)
}
intGID, err := strconv.Atoi(splitO[1])
if err != nil {
- return nil, errors.Wrapf(err, "cannot convert GID %s to integer", splitO[1])
+ return nil, fmt.Errorf("cannot convert GID %s to integer: %w", splitO[1], err)
}
logrus.Debugf("Removing gid= from options and adding WithVolumeGID for GID %d", intGID)
libpodOptions = append(libpodOptions, libpod.WithVolumeGID(intGID), libpod.WithVolumeNoChown())
@@ -80,11 +80,11 @@ func VolumeOptions(opts map[string]string) ([]libpod.VolumeCreateOption, error)
volumeOptions["NOQUOTA"] = "true"
case "timeout":
if len(splitO) != 2 {
- return nil, errors.Wrapf(define.ErrInvalidArg, "timeout option must provide a valid timeout in seconds")
+ return nil, fmt.Errorf("timeout option must provide a valid timeout in seconds: %w", define.ErrInvalidArg)
}
intTimeout, err := strconv.Atoi(splitO[1])
if err != nil {
- return nil, errors.Wrapf(err, "cannot convert Timeout %s to an integer", splitO[1])
+ return nil, fmt.Errorf("cannot convert Timeout %s to an integer: %w", splitO[1], err)
}
logrus.Debugf("Removing timeout from options and adding WithTimeout for Timeout %d", intTimeout)
libpodOptions = append(libpodOptions, libpod.WithVolumeDriverTimeout(intTimeout))
diff --git a/pkg/domain/infra/abi/pods_stats.go b/pkg/domain/infra/abi/pods_stats.go
index 6123027b8..a270db769 100644
--- a/pkg/domain/infra/abi/pods_stats.go
+++ b/pkg/domain/infra/abi/pods_stats.go
@@ -2,6 +2,7 @@ package abi
import (
"context"
+ "errors"
"fmt"
"github.com/containers/common/pkg/cgroups"
@@ -10,7 +11,6 @@ import (
"github.com/containers/podman/v4/pkg/rootless"
"github.com/containers/podman/v4/utils"
"github.com/docker/go-units"
- "github.com/pkg/errors"
)
// PodStats implements printing stats about pods.
@@ -28,7 +28,7 @@ func (ic *ContainerEngine) PodStats(ctx context.Context, namesOrIds []string, op
// Get the (running) pods and convert them to the entities format.
pods, err := getPodsByContext(options.All, options.Latest, namesOrIds, ic.Libpod)
if err != nil {
- return nil, errors.Wrap(err, "unable to get list of pods")
+ return nil, fmt.Errorf("unable to get list of pods: %w", err)
}
return ic.podsToStatsReport(pods)
}
diff --git a/pkg/domain/infra/abi/system.go b/pkg/domain/infra/abi/system.go
index 96690afef..0faae01c8 100644
--- a/pkg/domain/infra/abi/system.go
+++ b/pkg/domain/infra/abi/system.go
@@ -157,15 +157,15 @@ func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.Sys
// TODO: Figure out cleaner way to handle all of the different PruneOptions
// Remove all unused pods.
- podPruneReport, err := ic.prunePodHelper(ctx)
+ podPruneReports, err := ic.prunePodHelper(ctx)
if err != nil {
return nil, err
}
- if len(podPruneReport) > 0 {
+ if len(podPruneReports) > 0 {
found = true
}
- systemPruneReport.PodPruneReport = append(systemPruneReport.PodPruneReport, podPruneReport...)
+ systemPruneReport.PodPruneReport = append(systemPruneReport.PodPruneReport, podPruneReports...)
// Remove all unused containers.
containerPruneOptions := entities.ContainerPruneOptions{}
@@ -201,38 +201,35 @@ func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.Sys
networkPruneOptions := entities.NetworkPruneOptions{}
networkPruneOptions.Filters = options.Filters
- networkPruneReport, err := ic.NetworkPrune(ctx, networkPruneOptions)
+ networkPruneReports, err := ic.NetworkPrune(ctx, networkPruneOptions)
if err != nil {
return nil, err
}
- if len(networkPruneReport) > 0 {
+ if len(networkPruneReports) > 0 {
found = true
}
- for _, net := range networkPruneReport {
- systemPruneReport.NetworkPruneReports = append(systemPruneReport.NetworkPruneReports, &reports.PruneReport{
- Id: net.Name,
- Err: net.Error,
- Size: 0,
- })
- }
+
+ // Networks reclaimedSpace are always '0'.
+ systemPruneReport.NetworkPruneReports = append(systemPruneReport.NetworkPruneReports, networkPruneReports...)
// Remove unused volume data.
if options.Volume {
volumePruneOptions := entities.VolumePruneOptions{}
volumePruneOptions.Filters = (url.Values)(options.Filters)
- volumePruneReport, err := ic.VolumePrune(ctx, volumePruneOptions)
+ volumePruneReports, err := ic.VolumePrune(ctx, volumePruneOptions)
if err != nil {
return nil, err
}
- if len(volumePruneReport) > 0 {
+ if len(volumePruneReports) > 0 {
found = true
}
- reclaimedSpace += reports.PruneReportsSize(volumePruneReport)
- systemPruneReport.VolumePruneReports = append(systemPruneReport.VolumePruneReports, volumePruneReport...)
+ reclaimedSpace += reports.PruneReportsSize(volumePruneReports)
+ systemPruneReport.VolumePruneReports = append(systemPruneReport.VolumePruneReports, volumePruneReports...)
}
}
+
systemPruneReport.ReclaimedSpace = reclaimedSpace
return systemPruneReport, nil
}
diff --git a/pkg/domain/infra/abi/terminal/terminal.go b/pkg/domain/infra/abi/terminal/terminal.go
index 692f8dcd5..37dadd92a 100644
--- a/pkg/domain/infra/abi/terminal/terminal.go
+++ b/pkg/domain/infra/abi/terminal/terminal.go
@@ -2,13 +2,13 @@ package terminal
import (
"context"
+ "fmt"
"os"
"os/signal"
- "github.com/containers/podman/v4/libpod/define"
+ "github.com/containers/common/pkg/resize"
lsignal "github.com/containers/podman/v4/pkg/signal"
"github.com/moby/term"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -18,20 +18,20 @@ type RawTtyFormatter struct {
// getResize returns a TerminalSize command matching stdin's current
// size on success, and nil on errors.
-func getResize() *define.TerminalSize {
+func getResize() *resize.TerminalSize {
winsize, err := term.GetWinsize(os.Stdin.Fd())
if err != nil {
logrus.Warnf("Could not get terminal size %v", err)
return nil
}
- return &define.TerminalSize{
+ return &resize.TerminalSize{
Width: winsize.Width,
Height: winsize.Height,
}
}
// Helper for prepareAttach - set up a goroutine to generate terminal resize events
-func resizeTty(ctx context.Context, resize chan define.TerminalSize) {
+func resizeTty(ctx context.Context, resize chan resize.TerminalSize) {
sigchan := make(chan os.Signal, 1)
signal.Notify(sigchan, lsignal.SIGWINCH)
go func() {
@@ -78,7 +78,7 @@ func (f *RawTtyFormatter) Format(entry *logrus.Entry) ([]byte, error) {
return bytes, err
}
-func handleTerminalAttach(ctx context.Context, resize chan define.TerminalSize) (context.CancelFunc, *term.State, error) {
+func handleTerminalAttach(ctx context.Context, resize chan resize.TerminalSize) (context.CancelFunc, *term.State, error) {
logrus.Debugf("Handling terminal attach")
subCtx, cancel := context.WithCancel(ctx)
@@ -89,7 +89,7 @@ func handleTerminalAttach(ctx context.Context, resize chan define.TerminalSize)
if err != nil {
// allow caller to not have to do any cleaning up if we error here
cancel()
- return nil, nil, errors.Wrapf(err, "unable to save terminal state")
+ return nil, nil, fmt.Errorf("unable to save terminal state: %w", err)
}
logrus.SetFormatter(&RawTtyFormatter{})
diff --git a/pkg/domain/infra/abi/terminal/terminal_linux.go b/pkg/domain/infra/abi/terminal/terminal_linux.go
index 62d36f28d..222590871 100644
--- a/pkg/domain/infra/abi/terminal/terminal_linux.go
+++ b/pkg/domain/infra/abi/terminal/terminal_linux.go
@@ -6,23 +6,23 @@ import (
"fmt"
"os"
+ "github.com/containers/common/pkg/resize"
"github.com/containers/podman/v4/libpod"
"github.com/containers/podman/v4/libpod/define"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/term"
)
// ExecAttachCtr execs and attaches to a container
func ExecAttachCtr(ctx context.Context, ctr *libpod.Container, execConfig *libpod.ExecConfig, streams *define.AttachStreams) (int, error) {
- var resize chan define.TerminalSize
+ var resizechan chan resize.TerminalSize
haveTerminal := term.IsTerminal(int(os.Stdin.Fd()))
// Check if we are attached to a terminal. If we are, generate resize
// events, and set the terminal to raw mode
if haveTerminal && execConfig.Terminal {
- resize = make(chan define.TerminalSize)
- cancel, oldTermState, err := handleTerminalAttach(ctx, resize)
+ resizechan = make(chan resize.TerminalSize)
+ cancel, oldTermState, err := handleTerminalAttach(ctx, resizechan)
if err != nil {
return -1, err
}
@@ -33,14 +33,14 @@ func ExecAttachCtr(ctx context.Context, ctr *libpod.Container, execConfig *libpo
}
}()
}
- return ctr.Exec(execConfig, streams, resize)
+ return ctr.Exec(execConfig, streams, resizechan)
}
// StartAttachCtr starts and (if required) attaches to a container
// if you change the signature of this function from os.File to io.Writer, it will trigger a downstream
// error. we may need to just lint disable this one.
func StartAttachCtr(ctx context.Context, ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys string, sigProxy bool, startContainer bool) error { //nolint: interfacer
- resize := make(chan define.TerminalSize)
+ resize := make(chan resize.TerminalSize)
haveTerminal := term.IsTerminal(int(os.Stdin.Fd()))
@@ -103,7 +103,7 @@ func StartAttachCtr(ctx context.Context, ctr *libpod.Container, stdout, stderr,
err = <-attachChan
if err != nil {
- return errors.Wrapf(err, "error attaching to container %s", ctr.ID())
+ return fmt.Errorf("error attaching to container %s: %w", ctr.ID(), err)
}
return nil
diff --git a/pkg/domain/infra/abi/trust.go b/pkg/domain/infra/abi/trust.go
index 58f099bb6..0e3d8fad9 100644
--- a/pkg/domain/infra/abi/trust.go
+++ b/pkg/domain/infra/abi/trust.go
@@ -3,13 +3,14 @@ package abi
import (
"context"
"encoding/json"
+ "errors"
+ "fmt"
"io/ioutil"
"os"
"strings"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/trust"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -35,11 +36,11 @@ func (ir *ImageEngine) ShowTrust(ctx context.Context, args []string, options ent
}
policyContentStruct, err := trust.GetPolicy(policyPath)
if err != nil {
- return nil, errors.Wrapf(err, "could not read trust policies")
+ return nil, fmt.Errorf("could not read trust policies: %w", err)
}
report.Policies, err = getPolicyShowOutput(policyContentStruct, report.SystemRegistriesDirPath)
if err != nil {
- return nil, errors.Wrapf(err, "could not show trust policies")
+ return nil, fmt.Errorf("could not show trust policies: %w", err)
}
return &report, nil
}
@@ -56,7 +57,7 @@ func (ir *ImageEngine) SetTrust(ctx context.Context, args []string, options enti
pubkeysfile := options.PubKeysFile
if len(pubkeysfile) == 0 && trustType == "signedBy" {
- return errors.Errorf("At least one public key must be defined for type 'signedBy'")
+ return errors.New("at least one public key must be defined for type 'signedBy'")
}
policyPath := trust.DefaultPolicyPath(ir.Libpod.SystemContext())
@@ -70,7 +71,7 @@ func (ir *ImageEngine) SetTrust(ctx context.Context, args []string, options enti
return err
}
if err := json.Unmarshal(policyContent, &policyContentStruct); err != nil {
- return errors.Errorf("could not read trust policies")
+ return errors.New("could not read trust policies")
}
}
if len(pubkeysfile) != 0 {
@@ -84,7 +85,7 @@ func (ir *ImageEngine) SetTrust(ctx context.Context, args []string, options enti
policyContentStruct.Default = newReposContent
} else {
if len(policyContentStruct.Default) == 0 {
- return errors.Errorf("default trust policy must be set")
+ return errors.New("default trust policy must be set")
}
registryExists := false
for transport, transportval := range policyContentStruct.Transports {
@@ -107,7 +108,7 @@ func (ir *ImageEngine) SetTrust(ctx context.Context, args []string, options enti
data, err := json.MarshalIndent(policyContentStruct, "", " ")
if err != nil {
- return errors.Wrapf(err, "error setting trust policy")
+ return fmt.Errorf("error setting trust policy: %w", err)
}
return ioutil.WriteFile(policyPath, data, 0644)
}