Skip to content

CRI: Pass sandbox annotations to _other platforms#8060

Merged
mxpv merged 2 commits intocontainerd:mainfrom
dcantah:cri-annots-other
Feb 15, 2023
Merged

CRI: Pass sandbox annotations to _other platforms#8060
mxpv merged 2 commits intocontainerd:mainfrom
dcantah:cri-annots-other

Conversation

@dcantah
Copy link
Copy Markdown
Member

@dcantah dcantah commented Feb 7, 2023

!windows and !linux weren't getting passed the sandbox annotations.

This additionally adds in a commit on top to refactor how these annotations were getting passed. All of the CRI sandbox and container specs all get assigned almost the exact same default annotations (sandboxID, name, metadata, container type etc.) so I added a helper to return the right set for a sandbox or regular workload container.

@k8s-ci-robot
Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@dcantah dcantah marked this pull request as ready for review February 7, 2023 12:06
@dcantah dcantah added kind/enhancement area/cri Container Runtime Interface (CRI) easy-to-review Easy to review labels Feb 7, 2023
@dcantah dcantah added this to the 1.7 milestone Feb 7, 2023
@ruiwen-zhao
Copy link
Copy Markdown
Member

LGTM. Does it make sense to add checks to unit tests like in

t.Logf("Check PodSandbox annotations")
assert.Contains(t, spec.Annotations, annotations.SandboxID)
assert.EqualValues(t, spec.Annotations[annotations.SandboxID], id)
assert.Contains(t, spec.Annotations, annotations.ContainerType)
assert.EqualValues(t, spec.Annotations[annotations.ContainerType], annotations.ContainerTypeSandbox)
assert.Contains(t, spec.Annotations, annotations.SandboxNamespace)
assert.EqualValues(t, spec.Annotations[annotations.SandboxNamespace], "test-ns")
assert.Contains(t, spec.Annotations, annotations.SandboxUID)
assert.EqualValues(t, spec.Annotations[annotations.SandboxUID], "test-uid")
assert.Contains(t, spec.Annotations, annotations.SandboxName)
assert.EqualValues(t, spec.Annotations[annotations.SandboxName], "test-name")
assert.Contains(t, spec.Annotations, annotations.SandboxLogDir)
assert.EqualValues(t, spec.Annotations[annotations.SandboxLogDir], "test-log-directory")

and

t.Logf("Check PodSandbox annotations")
assert.Contains(t, spec.Annotations, annotations.SandboxID)
assert.EqualValues(t, spec.Annotations[annotations.SandboxID], sandboxID)
assert.Contains(t, spec.Annotations, annotations.ContainerType)
assert.EqualValues(t, spec.Annotations[annotations.ContainerType], annotations.ContainerTypeContainer)
assert.Contains(t, spec.Annotations, annotations.SandboxNamespace)
assert.EqualValues(t, spec.Annotations[annotations.SandboxNamespace], "test-sandbox-ns")
assert.Contains(t, spec.Annotations, annotations.SandboxUID)
assert.EqualValues(t, spec.Annotations[annotations.SandboxUID], "test-sandbox-uid")
assert.Contains(t, spec.Annotations, annotations.SandboxName)
assert.EqualValues(t, spec.Annotations[annotations.SandboxName], "test-sandbox-name")
assert.Contains(t, spec.Annotations, annotations.ImageName)
assert.EqualValues(t, spec.Annotations[annotations.ImageName], testImageName)

Copy link
Copy Markdown
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change LGTM although it seems like this could be extracted out so every platform can reuse the same code (maybe? I didn't peak through the other paltform files but I assume it's the same).

@dcantah
Copy link
Copy Markdown
Member Author

dcantah commented Feb 10, 2023

@ruiwen-zhao Let me take a look later today. @cpuguy83 it likely can, these should get passed on all platforms so this was the lazy approach thinking about it. I'll make a generic func that'll return these all and have all the platforms call it.

Copy link
Copy Markdown
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@estesp
Copy link
Copy Markdown
Member

estesp commented Feb 13, 2023

Needs a rebase; conflict in container_create_linux.go

Comment thread pkg/cri/sbserver/container_create.go Outdated
!windows and !linux weren't getting passed the sandbox annotations.

Signed-off-by: Danny Canter <[email protected]>
Comment thread pkg/cri/annotations/annotations.go
All of the CRI sandbox and container specs all get assigned
almost the exact same default annotations (sandboxID, name, metadata,
container type etc.) so lets make a helper to return the right set for
a sandbox or regular workload container.

Signed-off-by: Danny Canter <[email protected]>
Copy link
Copy Markdown
Member

@mxpv mxpv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once green!

@mxpv mxpv merged commit 3548f59 into containerd:main Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cri Container Runtime Interface (CRI) easy-to-review Easy to review kind/enhancement

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants