aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/containers/restore.go28
-rw-r--r--cmd/podman/containers/run.go29
-rw-r--r--cmd/podman/pods/logs.go7
-rw-r--r--cmd/podman/system/service_abi.go2
-rw-r--r--cmd/podman/utils/utils.go40
5 files changed, 81 insertions, 25 deletions
diff --git a/cmd/podman/containers/restore.go b/cmd/podman/containers/restore.go
index ee01e19b8..144925a54 100644
--- a/cmd/podman/containers/restore.go
+++ b/cmd/podman/containers/restore.go
@@ -10,7 +10,6 @@ import (
"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/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/rootless"
"github.com/spf13/cobra"
@@ -94,7 +93,7 @@ func init() {
func restore(cmd *cobra.Command, args []string) error {
var (
- e error
+ err error
errs utils.OutputErrors
)
podmanStart := time.Now()
@@ -105,9 +104,9 @@ func restore(cmd *cobra.Command, args []string) error {
// Check if the container exists (#15055)
exists := &entities.BoolReport{Value: false}
for _, ctr := range args {
- exists, e = registry.ContainerEngine().ContainerExists(registry.GetContext(), ctr, entities.ContainerExistsOptions{})
- if e != nil {
- return e
+ exists, err = registry.ContainerEngine().ContainerExists(registry.GetContext(), ctr, entities.ContainerExistsOptions{})
+ if err != nil {
+ return err
}
if exists.Value {
break
@@ -116,27 +115,10 @@ func restore(cmd *cobra.Command, args []string) error {
if !exists.Value {
// Find out if this is an image
- inspectOpts := entities.InspectOptions{}
- imgData, _, err := registry.ImageEngine().Inspect(context.Background(), args, inspectOpts)
- if err != nil {
- return err
- }
-
- hostInfo, err := registry.ContainerEngine().Info(context.Background())
+ restoreOptions.CheckpointImage, err = utils.IsCheckpointImage(context.Background(), args)
if err != nil {
return err
}
-
- for i := range imgData {
- restoreOptions.CheckpointImage = true
- checkpointRuntimeName, found := imgData[i].Annotations[define.CheckpointAnnotationRuntimeName]
- if !found {
- return fmt.Errorf("image is not a checkpoint: %s", imgData[i].ID)
- }
- if hostInfo.Host.OCIRuntime.Name != checkpointRuntimeName {
- return fmt.Errorf("container image \"%s\" requires runtime: \"%s\"", imgData[i].ID, checkpointRuntimeName)
- }
- }
}
notImport := (!restoreOptions.CheckpointImage && restoreOptions.Import == "")
diff --git a/cmd/podman/containers/run.go b/cmd/podman/containers/run.go
index f66d4d4d3..d8d020c63 100644
--- a/cmd/podman/containers/run.go
+++ b/cmd/podman/containers/run.go
@@ -148,6 +148,35 @@ func run(cmd *cobra.Command, args []string) error {
imageName = name
}
+ // If this is a checkpoint image, invoke container restore.
+ // We do not return `err` when checkpointImage is false, because the value
+ // of `err` could be "image is not a checkpoint". In this case, the run
+ // command should continue as usual, preserving backwards compatibility.
+ checkpointImage, err := utils.IsCheckpointImage(registry.GetContext(), []string{imageName})
+ if checkpointImage {
+ if err != nil {
+ return err
+ }
+ var restoreOptions entities.RestoreOptions
+ responses, err := registry.ContainerEngine().ContainerRestore(registry.GetContext(), []string{imageName}, restoreOptions)
+ if err != nil {
+ return err
+ }
+
+ var errs utils.OutputErrors
+ for _, r := range responses {
+ switch {
+ case r.Err != nil:
+ errs = append(errs, r.Err)
+ case r.RawInput != "":
+ fmt.Println(r.RawInput)
+ default:
+ fmt.Println(r.Id)
+ }
+ }
+ return errs.PrintErrors()
+ }
+
if cliVals.Replace {
if err := replaceContainer(cliVals.Name); err != nil {
return err
diff --git a/cmd/podman/pods/logs.go b/cmd/podman/pods/logs.go
index 7093a7fa8..a0ec16976 100644
--- a/cmd/podman/pods/logs.go
+++ b/cmd/podman/pods/logs.go
@@ -121,5 +121,10 @@ func logs(_ *cobra.Command, args []string) error {
logsPodOptions.StdoutWriter = os.Stdout
logsPodOptions.StderrWriter = os.Stderr
- return registry.ContainerEngine().PodLogs(registry.GetContext(), args[0], logsPodOptions.PodLogsOptions)
+
+ podName := ""
+ if len(args) > 0 {
+ podName = args[0]
+ }
+ return registry.ContainerEngine().PodLogs(registry.GetContext(), podName, logsPodOptions.PodLogsOptions)
}
diff --git a/cmd/podman/system/service_abi.go b/cmd/podman/system/service_abi.go
index 68ac8902b..82419ff1a 100644
--- a/cmd/podman/system/service_abi.go
+++ b/cmd/podman/system/service_abi.go
@@ -89,7 +89,7 @@ func restService(flags *pflag.FlagSet, cfg *entities.PodmanConfig, opts entities
return fmt.Errorf("unable to create socket %v: %w", host, err)
}
default:
- logrus.Debugf("Attempting API Service endpoint scheme %q", uri.Scheme)
+ return fmt.Errorf("API Service endpoint scheme %q is not supported. Try tcp://%s or unix:/%s", uri.Scheme, opts.URI, opts.URI)
}
libpodRuntime.SetRemoteURI(uri.String())
}
diff --git a/cmd/podman/utils/utils.go b/cmd/podman/utils/utils.go
index a265faf51..8063f4309 100644
--- a/cmd/podman/utils/utils.go
+++ b/cmd/podman/utils/utils.go
@@ -1,9 +1,12 @@
package utils
import (
+ "context"
"fmt"
"os"
+ "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/containers/podman/v4/pkg/domain/entities/reports"
)
@@ -99,3 +102,40 @@ func PrintNetworkPruneResults(networkPruneReport []*entities.NetworkPruneReport,
}
return errs.PrintErrors()
}
+
+// IsCheckpointImage returns true with no error only if all values in
+// namesOrIDs correspond to checkpoint images AND these images are
+// compatible with the container runtime that is currently in use,
+// e.g., crun or runc.
+//
+// IsCheckpointImage returns false with no error when none of the values
+// in namesOrIDs corresponds to an ID or name of an image.
+//
+// Otherwise, IsCheckpointImage returns false with appropriate error.
+func IsCheckpointImage(ctx context.Context, namesOrIDs []string) (bool, error) {
+ inspectOpts := entities.InspectOptions{}
+ imgData, _, err := registry.ImageEngine().Inspect(ctx, namesOrIDs, inspectOpts)
+ if err != nil {
+ return false, err
+ }
+ if len(imgData) == 0 {
+ return false, nil
+ }
+ imgID := imgData[0].ID
+
+ hostInfo, err := registry.ContainerEngine().Info(ctx)
+ if err != nil {
+ return false, err
+ }
+
+ for i := range imgData {
+ checkpointRuntimeName, found := imgData[i].Annotations[define.CheckpointAnnotationRuntimeName]
+ if !found {
+ return false, fmt.Errorf("image is not a checkpoint: %s", imgID)
+ }
+ if hostInfo.Host.OCIRuntime.Name != checkpointRuntimeName {
+ return false, fmt.Errorf("container image \"%s\" requires runtime: \"%s\"", imgID, checkpointRuntimeName)
+ }
+ }
+ return true, nil
+}