Skip to content

Commit b6e3616

Browse files
author
ChengyuZhu6
committed
cri: add pause image name to annotations
We are currently in the process of developing a feature to facilitate guest image pulling on confidential-containers, and we would be grateful for containerd's support in this endeavor. It would greatly assist our efforts if containerd could provide the pause image name and add it into the annotations. Fixes: containerd#9418 Signed-off-by: ChengyuZhu6 <[email protected]>
1 parent 406e9e8 commit b6e3616

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

internal/cri/annotations/annotations.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ const (
7878
// ImageName is the name of the image used to create the container
7979
ImageName = "io.kubernetes.cri.image-name"
8080

81+
// SandboxImageName is the name of the sandbox image
82+
SandboxImageName = "io.kubernetes.cri.podsandbox.image-name"
83+
8184
// PodAnnotations are the annotations of the pod
8285
PodAnnotations = "io.kubernetes.cri.pod-annotations"
8386

@@ -110,11 +113,15 @@ func DefaultCRIAnnotations(
110113
ctrType := ContainerTypeContainer
111114
if sandbox {
112115
ctrType = ContainerTypeSandbox
113-
// Sandbox log dir only gets passed for sandboxes, the other metadata always
116+
// Sandbox log dir and sandbox image name get passed for sandboxes, the other metadata always
114117
// gets sent however.
115-
opts = append(opts, customopts.WithAnnotation(SandboxLogDir, config.GetLogDirectory()))
118+
opts = append(
119+
opts,
120+
customopts.WithAnnotation(SandboxLogDir, config.GetLogDirectory()),
121+
customopts.WithAnnotation(SandboxImageName, imageName),
122+
)
116123
} else {
117-
// Image name and container name only get passed for containers.s
124+
// Image name and container name get passed for containers.
118125
opts = append(
119126
opts,
120127
customopts.WithAnnotation(ContainerName, containerName),

internal/cri/server/podsandbox/sandbox_run.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ func (c *Controller) Start(ctx context.Context, id string) (cin sandbox.Controll
7575
labels = map[string]string{}
7676
)
7777

78-
sandboxImage := c.imageService.PinnedImage("sandbox")
79-
if sandboxImage == "" {
80-
sandboxImage = criconfig.DefaultSandboxImage
81-
}
78+
sandboxImage := c.getSandboxImageName()
8279
// Ensure sandbox container image snapshot.
8380
image, err := c.ensureImageExists(ctx, sandboxImage, config, metadata.RuntimeHandler)
8481
if err != nil {
@@ -321,3 +318,15 @@ func (c *Controller) ensureImageExists(ctx context.Context, ref string, config *
321318
}
322319
return &newImage, nil
323320
}
321+
322+
func (c *Controller) getSandboxImageName() string {
323+
// returns the name of the sandbox image used to scope pod shared resources used by the pod's containers,
324+
// if empty return the default sandbox image.
325+
if c.imageService != nil {
326+
sandboxImage := c.imageService.PinnedImage("sandbox")
327+
if sandboxImage != "" {
328+
return sandboxImage
329+
}
330+
}
331+
return criconfig.DefaultSandboxImage
332+
}

internal/cri/server/podsandbox/sandbox_run_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (c *Controller) sandboxContainerSpec(id string, config *runtime.PodSandboxC
193193
specOpts = append(specOpts, customopts.WithAnnotation(pKey, pValue))
194194
}
195195

196-
specOpts = append(specOpts, annotations.DefaultCRIAnnotations(id, "", "", config, true)...)
196+
specOpts = append(specOpts, annotations.DefaultCRIAnnotations(id, "", c.getSandboxImageName(), config, true)...)
197197

198198
return c.runtimeSpec(id, "", specOpts...)
199199
}

internal/cri/server/podsandbox/sandbox_run_other.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
func (c *Controller) sandboxContainerSpec(id string, config *runtime.PodSandboxConfig,
3131
imageConfig *imagespec.ImageConfig, nsPath string, runtimePodAnnotations []string) (_ *runtimespec.Spec, retErr error) {
32-
return c.runtimeSpec(id, "", annotations.DefaultCRIAnnotations(id, "", "", config, true)...)
32+
return c.runtimeSpec(id, "", annotations.DefaultCRIAnnotations(id, "", c.getSandboxImageName(), config, true)...)
3333
}
3434

3535
// sandboxContainerSpecOpts generates OCI spec options for

internal/cri/server/podsandbox/sandbox_run_windows.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ func (c *Controller) sandboxContainerSpec(id string, config *runtime.PodSandboxC
8181
}
8282

8383
specOpts = append(specOpts, customopts.WithAnnotation(annotations.WindowsHostProcess, strconv.FormatBool(config.GetWindows().GetSecurityContext().GetHostProcess())))
84+
8485
specOpts = append(specOpts,
85-
annotations.DefaultCRIAnnotations(id, "", "", config, true)...,
86+
annotations.DefaultCRIAnnotations(id, "", c.getSandboxImageName(), config, true)...,
8687
)
8788

8889
return c.runtimeSpec(id, "", specOpts...)

0 commit comments

Comments
 (0)