From 7dc288dbed6a15b163a59e340869d72713aba28e Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Thu, 20 Jun 2024 12:55:22 +0100 Subject: [PATCH] restore: fix container restore into pod Currently, when Podman restores a container into a Pod, it always fails with the following error: Error: cannot add container f96670b26e53e70f7f451191ea39a093c940c6c48b47218aeeef1396cb860042 to pod h2-pod: no such pod This error occurs because r.state.Pod() is called in setupContainer() with the Pod name instead of ID. This patch fixes this problem by setting ctrConfig.Pod to pod.ID(). Reported-by: Stanislav Kosorin Signed-off-by: Radostin Stoyanov --- pkg/checkpoint/checkpoint_restore.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/checkpoint/checkpoint_restore.go b/pkg/checkpoint/checkpoint_restore.go index e80e1cf1f3..3fae15764c 100644 --- a/pkg/checkpoint/checkpoint_restore.go +++ b/pkg/checkpoint/checkpoint_restore.go @@ -102,17 +102,18 @@ func CRImportCheckpoint(ctx context.Context, runtime *libpod.Runtime, restoreOpt if !crutils.CRRuntimeSupportsPodCheckpointRestore(runtime.GetOCIRuntimePath()) { return nil, fmt.Errorf("runtime %s does not support pod restore", runtime.GetOCIRuntimePath()) } - // Restoring into an existing Pod - ctrConfig.Pod = restoreOptions.Pod // According to podman pod create a pod can share the following namespaces: // cgroup, ipc, net, pid, uts // Let's make sure we are restoring into a pod with the same shared namespaces. - pod, err := runtime.LookupPod(ctrConfig.Pod) + pod, err := runtime.LookupPod(restoreOptions.Pod) if err != nil { return nil, fmt.Errorf("pod %q cannot be retrieved: %w", ctrConfig.Pod, err) } + // Restoring into an existing Pod + ctrConfig.Pod = pod.ID() + infraContainer, err := pod.InfraContainer() if err != nil { return nil, fmt.Errorf("cannot retrieve infra container from pod %q: %w", ctrConfig.Pod, err)