Enable pod restore with crun

`CRRuntimeSupportsPodCheckpointRestore()` is used to check if the current
container runtime (e.g., runc or crun) can restore a container into an
existing Pod. It does this by processing output message to check if the
`--lsm-mount-context` option is supported.  This option was recently
added to crun [1], however, crun and runc have slightly different output
messages:

```
$ crun restore--lsm-mount-contextt
restore: option '--lsm-mount-context' requires an argument
Try `restore --help' or `restore --usage' for more information.
```

```
$ runc restore --lsm-mount-context
ERRO[0000] flag needs an argument: -lsm-mount-context
```

This patch updates the function to support both runtimes.

[1] https://github.com/containers/crun/pull/1578

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
This commit is contained in:
Radostin Stoyanov
2024-10-21 17:23:09 +01:00
parent e4d6fa7740
commit 642b61a091

View File

@ -229,7 +229,18 @@ func CRRuntimeSupportsCheckpointRestore(runtimePath string) bool {
func CRRuntimeSupportsPodCheckpointRestore(runtimePath string) bool {
cmd := exec.Command(runtimePath, "restore", "--lsm-mount-context")
out, _ := cmd.CombinedOutput()
return bytes.Contains(out, []byte("flag needs an argument"))
// check for runc
if bytes.Contains(out, []byte("flag needs an argument")) {
return true
}
// check for crun
if bytes.Contains(out, []byte("requires an argument")) {
return true
}
return false
}
// CRGetRuntimeFromArchive extracts the checkpoint metadata from the