From 5aab634e14022a638ba1d65792f1328b1b7b4c7b Mon Sep 17 00:00:00 2001 From: Danny Canter Date: Tue, 7 Feb 2023 03:56:39 -0800 Subject: [PATCH] CRI: Pass sandbox annotations to _other platforms !windows and !linux weren't getting passed the sandbox annotations. Signed-off-by: Danny Canter --- pkg/cri/sbserver/podsandbox/sandbox_run_other.go | 12 +++++++++++- pkg/cri/server/container_create_other.go | 13 ++++++++++++- pkg/cri/server/sandbox_run_other.go | 12 +++++++++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/pkg/cri/sbserver/podsandbox/sandbox_run_other.go b/pkg/cri/sbserver/podsandbox/sandbox_run_other.go index b703c5117..584ccc21a 100644 --- a/pkg/cri/sbserver/podsandbox/sandbox_run_other.go +++ b/pkg/cri/sbserver/podsandbox/sandbox_run_other.go @@ -21,6 +21,8 @@ package podsandbox import ( "github.com/containerd/containerd" "github.com/containerd/containerd/oci" + "github.com/containerd/containerd/pkg/cri/annotations" + customopts "github.com/containerd/containerd/pkg/cri/opts" imagespec "github.com/opencontainers/image-spec/specs-go/v1" runtimespec "github.com/opencontainers/runtime-spec/specs-go" runtime "k8s.io/cri-api/pkg/apis/runtime/v1" @@ -28,7 +30,15 @@ import ( func (c *Controller) sandboxContainerSpec(id string, config *runtime.PodSandboxConfig, imageConfig *imagespec.ImageConfig, nsPath string, runtimePodAnnotations []string) (_ *runtimespec.Spec, retErr error) { - return c.runtimeSpec(id, "") + specOpts := []oci.SpecOpts{ + customopts.WithAnnotation(annotations.ContainerType, annotations.ContainerTypeSandbox), + customopts.WithAnnotation(annotations.SandboxID, id), + customopts.WithAnnotation(annotations.SandboxNamespace, config.GetMetadata().GetNamespace()), + customopts.WithAnnotation(annotations.SandboxUID, config.GetMetadata().GetUid()), + customopts.WithAnnotation(annotations.SandboxName, config.GetMetadata().GetName()), + customopts.WithAnnotation(annotations.SandboxLogDir, config.GetLogDirectory()), + } + return c.runtimeSpec(id, "", specOpts...) } // sandboxContainerSpecOpts generates OCI spec options for diff --git a/pkg/cri/server/container_create_other.go b/pkg/cri/server/container_create_other.go index acab67c11..c3a561b7d 100644 --- a/pkg/cri/server/container_create_other.go +++ b/pkg/cri/server/container_create_other.go @@ -25,7 +25,9 @@ import ( runtimespec "github.com/opencontainers/runtime-spec/specs-go" runtime "k8s.io/cri-api/pkg/apis/runtime/v1" + "github.com/containerd/containerd/pkg/cri/annotations" "github.com/containerd/containerd/pkg/cri/config" + customopts "github.com/containerd/containerd/pkg/cri/opts" ) // containerMounts sets up necessary container system file mounts @@ -47,7 +49,16 @@ func (c *criService) containerSpec( extraMounts []*runtime.Mount, ociRuntime config.Runtime, ) (_ *runtimespec.Spec, retErr error) { - return c.runtimeSpec(id, ociRuntime.BaseRuntimeSpec) + specOpts := []oci.SpecOpts{ + customopts.WithAnnotation(annotations.ContainerType, annotations.ContainerTypeContainer), + customopts.WithAnnotation(annotations.SandboxID, sandboxID), + customopts.WithAnnotation(annotations.SandboxNamespace, sandboxConfig.GetMetadata().GetNamespace()), + customopts.WithAnnotation(annotations.SandboxUID, sandboxConfig.GetMetadata().GetUid()), + customopts.WithAnnotation(annotations.SandboxName, sandboxConfig.GetMetadata().GetName()), + customopts.WithAnnotation(annotations.ContainerName, containerName), + customopts.WithAnnotation(annotations.ImageName, imageName), + } + return c.runtimeSpec(id, ociRuntime.BaseRuntimeSpec, specOpts...) } func (c *criService) containerSpecOpts(config *runtime.ContainerConfig, imageConfig *imagespec.ImageConfig) ([]oci.SpecOpts, error) { diff --git a/pkg/cri/server/sandbox_run_other.go b/pkg/cri/server/sandbox_run_other.go index 1676b4760..fa575be70 100644 --- a/pkg/cri/server/sandbox_run_other.go +++ b/pkg/cri/server/sandbox_run_other.go @@ -21,6 +21,8 @@ package server import ( "github.com/containerd/containerd" "github.com/containerd/containerd/oci" + "github.com/containerd/containerd/pkg/cri/annotations" + customopts "github.com/containerd/containerd/pkg/cri/opts" "github.com/containerd/containerd/snapshots" imagespec "github.com/opencontainers/image-spec/specs-go/v1" runtimespec "github.com/opencontainers/runtime-spec/specs-go" @@ -29,7 +31,15 @@ import ( func (c *criService) sandboxContainerSpec(id string, config *runtime.PodSandboxConfig, imageConfig *imagespec.ImageConfig, nsPath string, runtimePodAnnotations []string) (_ *runtimespec.Spec, retErr error) { - return c.runtimeSpec(id, "") + specOpts := []oci.SpecOpts{ + customopts.WithAnnotation(annotations.ContainerType, annotations.ContainerTypeSandbox), + customopts.WithAnnotation(annotations.SandboxID, id), + customopts.WithAnnotation(annotations.SandboxNamespace, config.GetMetadata().GetNamespace()), + customopts.WithAnnotation(annotations.SandboxUID, config.GetMetadata().GetUid()), + customopts.WithAnnotation(annotations.SandboxName, config.GetMetadata().GetName()), + customopts.WithAnnotation(annotations.SandboxLogDir, config.GetLogDirectory()), + } + return c.runtimeSpec(id, "", specOpts...) } // sandboxContainerSpecOpts generates OCI spec options for