Skip to content

Commit

Permalink
feature: compatible with both k8s and cri-o annotations
Browse files Browse the repository at this point in the history
write both of these two annotations
1. compatible with old container
2. enable runtime recognize the container type
using popular annotation
3. these two annotation is only read by runtime, not used by pouch

Signed-off-by: zhuangqh <zhuangqhc@gmail.com>
  • Loading branch information
zhuangqh authored and fuweid committed May 5, 2019
1 parent 5008d8d commit 921464b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
16 changes: 11 additions & 5 deletions cri/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ const (
// ContainerTypeContainer represents a container running within a pod
ContainerTypeContainer = "container"

// CRIOContainerType is the container type (sandbox or container) annotation
CRIOContainerType = "io.kubernetes.cri-o.ContainerType"

// ContainerType is the container type (sandbox or container) annotation
ContainerType = "io.kubernetes.cri-o.ContainerType"
ContainerType = "io.kubernetes.cri.container-type"

// CRIOSandboxName is the sandbox name annotation
CRIOSandboxName = "io.kubernetes.cri-o.SandboxName"

// SandboxName is the sandbox name annotation
SandboxName = "io.kubernetes.cri-o.SandboxName"
// CRIOSandboxID is the sandbox id annotation
CRIOSandboxID = "io.kubernetes.cri-o.SandboxID"

// SandboxID is the sandbox id annotation
SandboxID = "io.kubernetes.cri-o.SandboxID"
// SandboxID is the sandbox ID annotation
SandboxID = "io.kubernetes.cri.sandbox-id"

// KubernetesRuntime is the runtime
KubernetesRuntime = "io.kubernetes.runtime"
Expand Down
5 changes: 4 additions & 1 deletion cri/v1alpha2/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,12 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
image = iSpec.Image
}

// compatible with both kubernetes and cri-o annotations
specAnnotation := make(map[string]string)
specAnnotation[anno.CRIOContainerType] = anno.ContainerTypeContainer
specAnnotation[anno.ContainerType] = anno.ContainerTypeContainer
specAnnotation[anno.SandboxName] = podSandboxID
specAnnotation[anno.CRIOSandboxName] = podSandboxID
specAnnotation[anno.CRIOSandboxID] = podSandboxID
specAnnotation[anno.SandboxID] = podSandboxID

resources := r.GetConfig().GetLinux().GetResources()
Expand Down
11 changes: 8 additions & 3 deletions cri/v1alpha2/cri_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ func makeSandboxPouchConfig(config *runtime.PodSandboxConfig, sandboxMeta *metat
// Apply a label to distinguish sandboxes from regular containers.
labels[containerTypeLabelKey] = containerTypeLabelSandbox

specAnnotation := make(map[string]string)
specAnnotation[anno.CRIOContainerType] = anno.ContainerTypeSandbox
specAnnotation[anno.ContainerType] = anno.ContainerTypeSandbox

hc := &apitypes.HostConfig{}

if sandboxMeta.NetNS == "" {
Expand All @@ -352,9 +356,10 @@ func makeSandboxPouchConfig(config *runtime.PodSandboxConfig, sandboxMeta *metat

createConfig := &apitypes.ContainerCreateConfig{
ContainerConfig: apitypes.ContainerConfig{
Hostname: strfmt.Hostname(config.Hostname),
Image: image,
Labels: labels,
Hostname: strfmt.Hostname(config.Hostname),
Image: image,
Labels: labels,
SpecAnnotation: specAnnotation,
},
HostConfig: hc,
NetworkingConfig: &apitypes.NetworkingConfig{},
Expand Down

0 comments on commit 921464b

Please sign in to comment.