aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/utils/utils.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-09-30 12:18:24 +0200
committerGitHub <noreply@github.com>2022-09-30 12:18:24 +0200
commit5aa194b1ed20fc8618c21ebba675d010cfa97ef2 (patch)
tree5861b3d45c50296ed94883491eb9627c2c7012e0 /cmd/podman/utils/utils.go
parent61068649fac22fd9ef4fe0b57b4c29b650f3c05c (diff)
parentebff193f8bf5d18b7dd72e3ae4ca0cb5eef6169f (diff)
downloadpodman-5aa194b1ed20fc8618c21ebba675d010cfa97ef2.tar.gz
podman-5aa194b1ed20fc8618c21ebba675d010cfa97ef2.tar.bz2
podman-5aa194b1ed20fc8618c21ebba675d010cfa97ef2.zip
Merge pull request #15868 from rst0git/podman-run-checkpoint-img
cmd/podman: add support for checkpoint images
Diffstat (limited to 'cmd/podman/utils/utils.go')
-rw-r--r--cmd/podman/utils/utils.go40
1 files changed, 40 insertions, 0 deletions
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
+}