Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Annotations: Provide container metadata for VM based runtimes #546

Merged
merged 1 commit into from
Jan 17, 2018

Conversation

jcvenegas
Copy link
Contributor

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]

@abhi
Copy link
Member

abhi commented Jan 16, 2018

@jcvenegas thank you for submitting the PR. Aren't these already available as labels and metadata ? Any reason to be passed as annotations ?

@abhi
Copy link
Member

abhi commented Jan 16, 2018

for e.g.:

"Labels": {
        "io.cri-containerd.kind": "container",
        "io.kubernetes.container.name": "kube-controller-manager",
        "io.kubernetes.pod.name": "kube-controller-manager-abhi-k8s-ubuntu-0",
        "io.kubernetes.pod.namespace": "kube-system",
        "io.kubernetes.pod.uid": "1985db349c24e16ece3f84cce82a7183"
    },

@Random-Liu
Copy link
Member

/ok-to-test

@Random-Liu
Copy link
Member

@abhi I think they need runc annotation instead of containerd label.

Copy link
Member

@mikebrow mikebrow left a 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.

ContainerTypeContainer = "container"

// ContainerType is the container type (sandbox or container) annotation
ContainerType = "io.kubernetes.cri-containerd.ContainerType"
Copy link
Member

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...

Copy link
Member

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 ?

Copy link
Member

@Random-Liu Random-Liu Jan 16, 2018

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mikebrow @abhi : "cri.containerType" sounds good to me. It is a more agnostic cri implementation.
About podID or sanboxID. What about PodSandbox tight to cri api definitions and includes both pod and sandbox to avoid confusions.

Copy link
Contributor Author

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.

@sameo
Copy link

sameo commented Jan 16, 2018

@abhi We need to get those as OCI annotations.

@@ -0,0 +1,19 @@
package annotations
Copy link

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.

Copy link
Member

@mikebrow mikebrow Jan 16, 2018

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.
*/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, added.

ContainerTypeContainer = "container"

// ContainerType is the container type (sandbox or container) annotation
ContainerType = "io.kubernetes.cri-containerd.ContainerType"
Copy link
Member

@Random-Liu Random-Liu Jan 16, 2018

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?

@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

  1. Can we do this in generateContainerSpec?
  2. 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?

Copy link
Contributor Author

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.

@@ -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)
Copy link
Member

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.

ContainerTypeContainer = "container"

// ContainerType is the container type (sandbox or container) annotation
ContainerType = "io.kubernetes.cri.ContainerType"
Copy link
Contributor Author

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

Copy link
Member

@Random-Liu Random-Liu Jan 17, 2018

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.

Copy link
Member

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)
Copy link
Contributor Author

@jcvenegas jcvenegas Jan 16, 2018

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.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

@abhi
Copy link
Member

abhi commented Jan 16, 2018

@jcvenegas there is lint failure.

I0116 21:34:34.878] pkg/server/container_create_test.go:302:120:warning: unused variable or constant too few arguments in call to c.generateContainerSpec (varcheck)
I0116 21:34:34.879] pkg/server/container_create_test.go:705:46:warning: unused variable or constant cannot use testPid (variable of type uint32) as string value in argument to c.generateContainerSpec (varcheck)
I0116 21:34:34.880] pkg/server/container_create_test.go:705:55:warning: unused variable or constant cannot use config (variable of type *github.com/containerd/cri-containerd/vendor/k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime.ContainerConfig) as uint32 value in argument to c.generateContainerSpec (varcheck)
I0116 21:34:34.882] pkg/server/container_create_test.go:705:63:warning: unused variable or constant cannot use sandboxConfig (variable of type *github.com/containerd/cri-containerd/vendor/k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime.PodSandboxConfig) as *github.com/containerd/cri-containerd/vendor/k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime.ContainerConfig value in argument to c.generateContainerSpec (varcheck)
I0116 21:34:34.883] pkg/server/container_create_test.go:705:78:warning: unused variable or constant cannot use imageConfig (variable of type *github.com/containerd/cri-containerd/vendor/github.com/opencontainers/image-spec/specs-go/v1.ImageConfig) as *github.com/containerd/cri-containerd/vendor/k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime.PodSandboxConfig value in argument to c.generateContainerSpec (varcheck)
I0116 21:34:34.884] pkg/server/container_create_test.go:705:94:warning: unused variable or constant too few arguments in call to c.generateContainerSpec (varcheck)
I0116 21:34:37.397] Makefile:67: recipe for target 'lint' failed

you can run make verify locally

Copy link
Member

@abhi abhi left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

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

/LGTM

ContainerTypeContainer = "container"

// ContainerType is the container type (sandbox or container) annotation
ContainerType = "io.kubernetes.cri.ContainerType"
Copy link
Member

@Random-Liu Random-Liu Jan 17, 2018

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.

ContainerType = "io.kubernetes.cri.ContainerType"

// SandboxID is the sandbox ID annotation
SandboxID = "io.kubernetes.cri.SandboxID"
Copy link
Member

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)
Copy link
Member

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"
Copy link
Member

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. :)

Copy link
Contributor Author

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

@Random-Liu Random-Liu self-assigned this Jan 17, 2018
@sameo
Copy link

sameo commented Jan 17, 2018

@guangxuli
Copy link

@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]>
@jcvenegas
Copy link
Contributor Author

jcvenegas commented Jan 17, 2018

@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"
Copy link
Contributor Author

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.

@Random-Liu
Copy link
Member

@jcvenegas Thanks for contributing this! :D

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants