Merge pull request #18857 from Luap99/criu-version-error

criu: return error when checking for min version
This commit is contained in:
OpenShift Merge Robot
2023-06-12 12:02:45 -04:00
committed by GitHub
6 changed files with 25 additions and 16 deletions

View File

@ -1135,8 +1135,8 @@ func (c *Container) exportCheckpoint(options ContainerCheckpointOptions) error {
} }
func (c *Container) checkpointRestoreSupported(version int) error { func (c *Container) checkpointRestoreSupported(version int) error {
if !criu.CheckForCriu(version) { if err := criu.CheckForCriu(version); err != nil {
return fmt.Errorf("checkpoint/restore requires at least CRIU %d", version) return err
} }
if !c.ociRuntime.SupportsCheckpoint() { if !c.ociRuntime.SupportsCheckpoint() {
return errors.New("configured runtime does not support checkpoint/restore") return errors.New("configured runtime does not support checkpoint/restore")

View File

@ -93,8 +93,8 @@ func CRImportCheckpoint(ctx context.Context, runtime *libpod.Runtime, restoreOpt
if restoreOptions.Pod != "" { if restoreOptions.Pod != "" {
// Restoring into a Pod requires much newer versions of CRIU // Restoring into a Pod requires much newer versions of CRIU
if !criu.CheckForCriu(criu.PodCriuVersion) { if err := criu.CheckForCriu(criu.PodCriuVersion); err != nil {
return nil, fmt.Errorf("restoring containers into pods requires at least CRIU %d", criu.PodCriuVersion) return nil, fmt.Errorf("restoring containers into pod: %w", err)
} }
// The runtime also has to support it // The runtime also has to support it
if !crutils.CRRuntimeSupportsPodCheckpointRestore(runtime.GetOCIRuntimePath()) { if !crutils.CRRuntimeSupportsPodCheckpointRestore(runtime.GetOCIRuntimePath()) {

View File

@ -4,6 +4,8 @@
package criu package criu
import ( import (
"fmt"
"github.com/checkpoint-restore/go-criu/v6" "github.com/checkpoint-restore/go-criu/v6"
"github.com/checkpoint-restore/go-criu/v6/rpc" "github.com/checkpoint-restore/go-criu/v6/rpc"
@ -12,13 +14,17 @@ import (
// CheckForCriu uses CRIU's go bindings to check if the CRIU // CheckForCriu uses CRIU's go bindings to check if the CRIU
// binary exists and if it at least the version Podman needs. // binary exists and if it at least the version Podman needs.
func CheckForCriu(version int) bool { func CheckForCriu(version int) error {
c := criu.MakeCriu() c := criu.MakeCriu()
result, err := c.IsCriuAtLeast(version) criuVersion, err := c.GetCriuVersion()
if err != nil { if err != nil {
return false return fmt.Errorf("failed to check for criu version: %w", err)
} }
return result
if criuVersion >= version {
return nil
}
return fmt.Errorf("checkpoint/restore requires at least CRIU %d, current version is %d", version, criuVersion)
} }
func MemTrack() bool { func MemTrack() bool {

View File

@ -3,8 +3,10 @@
package criu package criu
func CheckForCriu(version int) bool { import "fmt"
return false
func CheckForCriu(version int) error {
return fmt.Errorf("CheckForCriu not supported on this platform")
} }
func MemTrack() bool { func MemTrack() bool {

View File

@ -1,6 +1,7 @@
package integration package integration
import ( import (
"fmt"
"os/exec" "os/exec"
"strconv" "strconv"
"strings" "strings"
@ -27,8 +28,8 @@ var _ = Describe("Podman checkpoint", func() {
Skip("OCI runtime does not support checkpoint/restore") Skip("OCI runtime does not support checkpoint/restore")
} }
if !criu.CheckForCriu(criu.MinCriuVersion) { if err := criu.CheckForCriu(criu.MinCriuVersion); err != nil {
Skip("CRIU is missing or too old.") Skip(fmt.Sprintf("check CRIU version error: %v", err))
} }
}) })

View File

@ -43,8 +43,8 @@ var _ = Describe("Podman checkpoint", func() {
Skip("OCI runtime does not support checkpoint/restore") Skip("OCI runtime does not support checkpoint/restore")
} }
if !criu.CheckForCriu(criu.MinCriuVersion) { if err := criu.CheckForCriu(criu.MinCriuVersion); err != nil {
Skip("CRIU is missing or too old.") Skip(fmt.Sprintf("check CRIU version error: %v", err))
} }
// Only Fedora 29 and newer has a new enough selinux-policy and // Only Fedora 29 and newer has a new enough selinux-policy and
// container-selinux package to support CRIU in correctly // container-selinux package to support CRIU in correctly
@ -1121,8 +1121,8 @@ var _ = Describe("Podman checkpoint", func() {
share := share // copy into local scope, for use inside function share := share // copy into local scope, for use inside function
It(testName, func() { It(testName, func() {
if !criu.CheckForCriu(criu.PodCriuVersion) { if err := criu.CheckForCriu(criu.PodCriuVersion); err != nil {
Skip("CRIU is missing or too old.") Skip(fmt.Sprintf("check CRIU pod version error: %v", err))
} }
if !crutils.CRRuntimeSupportsPodCheckpointRestore(podmanTest.OCIRuntime) { if !crutils.CRRuntimeSupportsPodCheckpointRestore(podmanTest.OCIRuntime) {
Skip("runtime does not support pod restore: " + podmanTest.OCIRuntime) Skip("runtime does not support pod restore: " + podmanTest.OCIRuntime)