From a0ebfbf18a3094bc1e0f1c9109bb2ca742319eb8 Mon Sep 17 00:00:00 2001 From: stevenhorsman Date: Tue, 8 Aug 2023 14:00:21 +0100 Subject: [PATCH] runtime: Re-added hypervisor annotations - Add support for setting the sandbox name and namespace in the hypervisor config, which is needed in the remote hypervisor implementation to get the pod name and namespace for the remote pod create request Fixes: #7588 Co-authored-by: Pradipta Banerjee Co-authored-by: Yohei Ueda Signed-off-by: stevenhorsman --- src/runtime/virtcontainers/sandbox.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/runtime/virtcontainers/sandbox.go b/src/runtime/virtcontainers/sandbox.go index a1fcfb79b7..d055750b82 100644 --- a/src/runtime/virtcontainers/sandbox.go +++ b/src/runtime/virtcontainers/sandbox.go @@ -25,6 +25,8 @@ import ( v1 "github.com/containerd/cgroups/stats/v1" v2 "github.com/containerd/cgroups/v2/stats" + cri "github.com/containerd/containerd/pkg/cri/annotations" + crio "github.com/containers/podman/v4/pkg/annotations" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -609,6 +611,8 @@ func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor return nil, err } + setHypervisorConfigAnnotations(&sandboxConfig) + coldPlugVFIO, err := s.coldOrHotPlugVFIO(&sandboxConfig) if err != nil { return nil, err @@ -638,6 +642,23 @@ func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor return s, nil } +func setHypervisorConfigAnnotations(sandboxConfig *SandboxConfig) { + if len(sandboxConfig.Containers) > 0 { + // These values are required by remote hypervisor + for _, a := range []string{cri.SandboxName, crio.SandboxName} { + if value, ok := sandboxConfig.Containers[0].Annotations[a]; ok { + sandboxConfig.HypervisorConfig.SandboxName = value + } + } + + for _, a := range []string{cri.SandboxNamespace, crio.Namespace} { + if value, ok := sandboxConfig.Containers[0].Annotations[a]; ok { + sandboxConfig.HypervisorConfig.SandboxNamespace = value + } + } + } +} + func (s *Sandbox) coldOrHotPlugVFIO(sandboxConfig *SandboxConfig) (bool, error) { // If we have a confidential guest we need to cold-plug the PCIe VFIO devices // until we have TDISP/IDE PCIe support.