-
Notifications
You must be signed in to change notification settings - Fork 348
Annotations: Provide container metadata for VM based runtimes #546
Conversation
@jcvenegas thank you for submitting the PR. Aren't these already available as labels and metadata ? Any reason to be passed as annotations ? |
for e.g.:
|
/ok-to-test |
@abhi I think they need runc annotation instead of containerd label. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good.. just a nit on the label names.
pkg/annotations/annotations.go
Outdated
ContainerTypeContainer = "container" | ||
|
||
// ContainerType is the container type (sandbox or container) annotation | ||
ContainerType = "io.kubernetes.cri-containerd.ContainerType" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about cri.containerType, cri.sandboxID, cri.sandboxName.
Might want to substitute sandbox for pod, since these labels might get printed out and most folks won't know that sandbox is the internal name for pod...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or may be io.kubernetes.containerd.ContainerType and so on below ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcvenegas Same question here. Are we going to have different annotation key for cri-o, cri-containerd or dockershim? Shouldn't that be a standard name? Will katacontainers be looking at different annotations from different container runtimes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Today kata is looking for different annotations
. I like the idea to go beyond and take a first step towards standardization.
@abhi We need to get those as OCI annotations. |
@@ -0,0 +1,19 @@ | |||
package annotations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcvenegas You need to add the Kubernetes boilerplate to this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/*
Copyright 2018 The Containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, added.
5061be3
to
bff9131
Compare
pkg/annotations/annotations.go
Outdated
ContainerTypeContainer = "container" | ||
|
||
// ContainerType is the container type (sandbox or container) annotation | ||
ContainerType = "io.kubernetes.cri-containerd.ContainerType" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcvenegas Same question here. Are we going to have different annotation key for cri-o, cri-containerd or dockershim? Shouldn't that be a standard name? Will katacontainers be looking at different annotations from different container runtimes?
pkg/server/container_create.go
Outdated
@@ -147,6 +148,9 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C | |||
if err != nil { | |||
return nil, fmt.Errorf("failed to generate container %q spec: %v", id, err) | |||
} | |||
spec.Annotations[annotations.SandboxID] = sandboxID | |||
spec.Annotations[annotations.SandboxName] = name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Can we do this in
generateContainerSpec
? name
is the name of the container, right? Not the sandbox name. What name do you need here? From the annotation you applied on sandbox, it seems that you require the pod name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true this is pod name, I will provide the sandbox struct to generateContainerSpec and populate with the right value.
pkg/server/sandbox_run.go
Outdated
@@ -331,6 +332,10 @@ func (c *criContainerdService) generateSandboxContainerSpec(id string, config *r | |||
g.SetLinuxResourcesCPUShares(uint64(defaultSandboxCPUshares)) | |||
g.SetProcessOOMScoreAdj(int(defaultSandboxOOMAdj)) | |||
|
|||
g.AddAnnotation(annotations.ContainerType, annotations.ContainerTypeSandbox) | |||
g.AddAnnotation(annotations.SandboxID, id) | |||
g.AddAnnotation(annotations.SandboxName, config.Metadata.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto. It's not very clear to me what kind of sandbox name do you need.
bff9131
to
072b1ed
Compare
pkg/annotations/annotations.go
Outdated
ContainerTypeContainer = "container" | ||
|
||
// ContainerType is the container type (sandbox or container) annotation | ||
ContainerType = "io.kubernetes.cri.ContainerType" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikebrow changed namespace annotations to io.kubernetes.cri
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use io.kubernetes.cri.container-type
or io.kubernetes.cri.containertype
.
The Kubernetes naming convention https://github.com/kubernetes/community/blob/master/contributors/design-proposals/architecture/identifiers.md
Basically for label key, we want it to be DNS subdomain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest to correct this.
@@ -365,6 +367,9 @@ func (c *criContainerdService) generateContainerSpec(id string, sandboxPid uint3 | |||
g.AddProcessAdditionalGid(uint32(group)) | |||
} | |||
|
|||
g.AddAnnotation(annotations.ContainerType, annotations.ContainerTypeContainer) | |||
g.AddAnnotation(annotations.SandboxID, sandboxID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Random-Liu moved annotation to generateContainerSpec
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
072b1ed
to
dc52d81
Compare
@jcvenegas there is lint failure.
you can run |
dc52d81
to
f051cb5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/LGTM
pkg/annotations/annotations.go
Outdated
ContainerTypeContainer = "container" | ||
|
||
// ContainerType is the container type (sandbox or container) annotation | ||
ContainerType = "io.kubernetes.cri.ContainerType" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use io.kubernetes.cri.container-type
or io.kubernetes.cri.containertype
.
The Kubernetes naming convention https://github.com/kubernetes/community/blob/master/contributors/design-proposals/architecture/identifiers.md
Basically for label key, we want it to be DNS subdomain.
pkg/annotations/annotations.go
Outdated
ContainerType = "io.kubernetes.cri.ContainerType" | ||
|
||
// SandboxID is the sandbox ID annotation | ||
SandboxID = "io.kubernetes.cri.SandboxID" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
@@ -365,6 +367,9 @@ func (c *criContainerdService) generateContainerSpec(id string, sandboxPid uint3 | |||
g.AddProcessAdditionalGid(uint32(group)) | |||
} | |||
|
|||
g.AddAnnotation(annotations.ContainerType, annotations.ContainerTypeContainer) | |||
g.AddAnnotation(annotations.SandboxID, sandboxID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@@ -177,13 +177,15 @@ func TestGeneralContainerSpec(t *testing.T) { | |||
testPid := uint32(1234) | |||
config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData() | |||
c := newTestCRIContainerdService() | |||
spec, err := c.generateContainerSpec(testID, testPid, config, sandboxConfig, imageConfig, nil) | |||
testSandboxID := "SandboxID" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to check whether the annotations are set properly in default specCheck
. However, if you don't have to do that, I can send a following up PR to do that. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah agree - not worries, adding proper checks to specCheck
@sameo SGTM, cool work. BTW, is this a first step cri-containerd support cc/kata runtime? |
For hypervisor-based container runtimes (like Kata Containers, Clear Containers or runv) a pod will be created in a VM and then create containers within the VM. When a runtime is requested for container commands like create and start, both the instal "pause" container and next containers need to be added to the pod namespace (same VM). A runtime does not know if it needs to create/start a VM or if it needs to add a container to an already running VM pod. This patch adds a way to provide this information through container annotations. When starting a container or a sandbox, 2 annotations are added: - type (Container or Sandbox) - sandbox name This allow to a VM based runtime to decide if they need to create a pod VM or container within the VM pod. Signed-off-by: Jose Carlos Venegas Munoz <[email protected]>
f051cb5
to
b383b02
Compare
@guangxuli that is right this is the brings initial support to allow kata and other hypervisor based runtime containers work with cri-containerd :) |
ContainerTypeContainer = "container" | ||
|
||
// ContainerType is the container type (sandbox or container) annotation | ||
ContainerType = "io.kubernetes.cri.container-type" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Random-Liu @yanxuean updated annotations values according to the Kubernetes naming convention.
@jcvenegas Thanks for contributing this! :D |
For hypervisor-based container runtimes (like Kata Containers, Clear Containers
or runv) a pod will be created in a VM and then create containers within the VM.
When a runtime is requested for container commands like create and start, both
the instal "pause" container and next containers need to be added to the pod
namespace (same VM).
A runtime does not know if it needs to create/start a VM or if it needs to add a
container to an already running VM pod.
This patch adds a way to provide this information through container annotations.
When starting a container or a sandbox, 2 annotations are added:
This allow to a VM based runtime to decide if they need to create a pod VM or
container within the VM pod.
Signed-off-by: Jose Carlos Venegas Munoz [email protected]