-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from adrianreber/2024-03-12-common
Add functions which are used in Podman, CRI-O and containerd
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package utils | ||
|
||
// MinCriuVersion for Podman at least CRIU 3.11 is required | ||
const MinCriuVersionPodman = 31100 | ||
|
||
// PodCriuVersion is the version of CRIU needed for | ||
// checkpointing and restoring containers out of and into Pods. | ||
const PodCriuVersion = 31600 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/checkpoint-restore/go-criu/v7" | ||
"github.com/checkpoint-restore/go-criu/v7/rpc" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
// CheckForCRIU checks if CRIU is available and if it is as least the | ||
// version as specified in the "version" parameter. | ||
func CheckForCriu(version int) error { | ||
criuVersion, err := GetCriuVersion() | ||
if err != nil { | ||
return fmt.Errorf("failed to check for criu version: %w", err) | ||
} | ||
|
||
if criuVersion >= version { | ||
return nil | ||
} | ||
return fmt.Errorf("checkpoint/restore requires at least CRIU %d, current version is %d", version, criuVersion) | ||
} | ||
|
||
// Convenience function to easily check if memory tracking is supported. | ||
func IsMemTrack() bool { | ||
features, err := criu.MakeCriu().FeatureCheck( | ||
&rpc.CriuFeatures{ | ||
MemTrack: proto.Bool(true), | ||
}, | ||
) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
return features.GetMemTrack() | ||
} | ||
|
||
func GetCriuVersion() (int, error) { | ||
c := criu.MakeCriu() | ||
return c.GetCriuVersion() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//go:build !linux | ||
// +build !linux | ||
|
||
package utils | ||
|
||
import "fmt" | ||
|
||
func CheckForCriu(version int) error { | ||
return fmt.Errorf("CRIU not supported on this platform") | ||
} | ||
|
||
func IsMemTrack() bool { | ||
return false | ||
} | ||
|
||
func GetCriuVersion() (int, error) { | ||
return 0, fmt.Errorf("CRIU not supported in this platform") | ||
} |