cri: add annotations for pod name and namespace
cri-o has annotations for pod name, namespace and container name:
https://github.com/containers/podman/blob/master/pkg/annotations/annotations.go
But so far containerd had only the container name.
This patch will be useful for seccomp agents to have a different
behaviour depending on the pod (see runtime-spec PR 1074 and runc PR
2682). This should simplify the code in:
b2d423695d/pkg/kuberesolver/kuberesolver.go (L16-L27)
Signed-off-by: Alban Crequy <alban@kinvolk.io>
This commit is contained in:
parent
20346607b9
commit
28e4fb25f4
@ -45,6 +45,12 @@ const (
|
|||||||
// workload can only run on dedicated runtime for untrusted workload.
|
// workload can only run on dedicated runtime for untrusted workload.
|
||||||
UntrustedWorkload = "io.kubernetes.cri.untrusted-workload"
|
UntrustedWorkload = "io.kubernetes.cri.untrusted-workload"
|
||||||
|
|
||||||
// containerName is the name of the container in the pod
|
// SandboxNamespace is the name of the namespace of the sandbox (pod)
|
||||||
|
SandboxNamespace = "io.kubernetes.cri.sandbox-namespace"
|
||||||
|
|
||||||
|
// SandboxName is the name of the sandbox (pod)
|
||||||
|
SandboxName = "io.kubernetes.cri.sandbox-name"
|
||||||
|
|
||||||
|
// ContainerName is the name of the container in the pod
|
||||||
ContainerName = "io.kubernetes.cri.container-name"
|
ContainerName = "io.kubernetes.cri.container-name"
|
||||||
)
|
)
|
||||||
|
@ -260,6 +260,8 @@ func (c *criService) containerSpec(id string, sandboxID string, sandboxPid uint3
|
|||||||
customopts.WithSupplementalGroups(supplementalGroups),
|
customopts.WithSupplementalGroups(supplementalGroups),
|
||||||
customopts.WithAnnotation(annotations.ContainerType, annotations.ContainerTypeContainer),
|
customopts.WithAnnotation(annotations.ContainerType, annotations.ContainerTypeContainer),
|
||||||
customopts.WithAnnotation(annotations.SandboxID, sandboxID),
|
customopts.WithAnnotation(annotations.SandboxID, sandboxID),
|
||||||
|
customopts.WithAnnotation(annotations.SandboxNamespace, sandboxConfig.GetMetadata().GetNamespace()),
|
||||||
|
customopts.WithAnnotation(annotations.SandboxName, sandboxConfig.GetMetadata().GetName()),
|
||||||
customopts.WithAnnotation(annotations.ContainerName, containerName),
|
customopts.WithAnnotation(annotations.ContainerName, containerName),
|
||||||
)
|
)
|
||||||
// cgroupns is used for hiding /sys/fs/cgroup from containers.
|
// cgroupns is used for hiding /sys/fs/cgroup from containers.
|
||||||
|
@ -174,6 +174,12 @@ func getCreateContainerTestData() (*runtime.ContainerConfig, *runtime.PodSandbox
|
|||||||
|
|
||||||
assert.Contains(t, spec.Annotations, annotations.ContainerType)
|
assert.Contains(t, spec.Annotations, annotations.ContainerType)
|
||||||
assert.EqualValues(t, spec.Annotations[annotations.ContainerType], annotations.ContainerTypeContainer)
|
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.SandboxName)
|
||||||
|
assert.EqualValues(t, spec.Annotations[annotations.SandboxName], "test-sandbox-name")
|
||||||
}
|
}
|
||||||
return config, sandboxConfig, imageConfig, specCheck
|
return config, sandboxConfig, imageConfig, specCheck
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,8 @@ func (c *criService) containerSpec(id string, sandboxID string, sandboxPid uint3
|
|||||||
specOpts = append(specOpts,
|
specOpts = append(specOpts,
|
||||||
customopts.WithAnnotation(annotations.ContainerType, annotations.ContainerTypeContainer),
|
customopts.WithAnnotation(annotations.ContainerType, annotations.ContainerTypeContainer),
|
||||||
customopts.WithAnnotation(annotations.SandboxID, sandboxID),
|
customopts.WithAnnotation(annotations.SandboxID, sandboxID),
|
||||||
|
customopts.WithAnnotation(annotations.SandboxNamespace, sandboxConfig.GetMetadata().GetNamespace()),
|
||||||
|
customopts.WithAnnotation(annotations.SandboxName, sandboxConfig.GetMetadata().GetName()),
|
||||||
customopts.WithAnnotation(annotations.ContainerName, containerName),
|
customopts.WithAnnotation(annotations.ContainerName, containerName),
|
||||||
)
|
)
|
||||||
return c.runtimeSpec(id, ociRuntime.BaseRuntimeSpec, specOpts...)
|
return c.runtimeSpec(id, ociRuntime.BaseRuntimeSpec, specOpts...)
|
||||||
|
@ -126,6 +126,12 @@ func getCreateContainerTestData() (*runtime.ContainerConfig, *runtime.PodSandbox
|
|||||||
|
|
||||||
assert.Contains(t, spec.Annotations, annotations.ContainerType)
|
assert.Contains(t, spec.Annotations, annotations.ContainerType)
|
||||||
assert.EqualValues(t, spec.Annotations[annotations.ContainerType], annotations.ContainerTypeContainer)
|
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.SandboxName)
|
||||||
|
assert.EqualValues(t, spec.Annotations[annotations.SandboxName], "test-sandbox-name")
|
||||||
}
|
}
|
||||||
return config, sandboxConfig, imageConfig, specCheck
|
return config, sandboxConfig, imageConfig, specCheck
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,8 @@ func (c *criService) sandboxContainerSpec(id string, config *runtime.PodSandboxC
|
|||||||
specOpts = append(specOpts,
|
specOpts = append(specOpts,
|
||||||
customopts.WithAnnotation(annotations.ContainerType, annotations.ContainerTypeSandbox),
|
customopts.WithAnnotation(annotations.ContainerType, annotations.ContainerTypeSandbox),
|
||||||
customopts.WithAnnotation(annotations.SandboxID, id),
|
customopts.WithAnnotation(annotations.SandboxID, id),
|
||||||
|
customopts.WithAnnotation(annotations.SandboxNamespace, config.GetMetadata().GetNamespace()),
|
||||||
|
customopts.WithAnnotation(annotations.SandboxName, config.GetMetadata().GetName()),
|
||||||
customopts.WithAnnotation(annotations.SandboxLogDir, config.GetLogDirectory()),
|
customopts.WithAnnotation(annotations.SandboxLogDir, config.GetLogDirectory()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -73,6 +73,12 @@ func getRunPodSandboxTestData() (*runtime.PodSandboxConfig, *imagespec.ImageConf
|
|||||||
assert.Contains(t, spec.Annotations, annotations.ContainerType)
|
assert.Contains(t, spec.Annotations, annotations.ContainerType)
|
||||||
assert.EqualValues(t, spec.Annotations[annotations.ContainerType], annotations.ContainerTypeSandbox)
|
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.SandboxName)
|
||||||
|
assert.EqualValues(t, spec.Annotations[annotations.SandboxName], "test-name")
|
||||||
|
|
||||||
assert.Contains(t, spec.Annotations, annotations.SandboxLogDir)
|
assert.Contains(t, spec.Annotations, annotations.SandboxLogDir)
|
||||||
assert.EqualValues(t, spec.Annotations[annotations.SandboxLogDir], "test-log-directory")
|
assert.EqualValues(t, spec.Annotations[annotations.SandboxLogDir], "test-log-directory")
|
||||||
|
|
||||||
|
@ -64,6 +64,8 @@ func (c *criService) sandboxContainerSpec(id string, config *runtime.PodSandboxC
|
|||||||
specOpts = append(specOpts,
|
specOpts = append(specOpts,
|
||||||
customopts.WithAnnotation(annotations.ContainerType, annotations.ContainerTypeSandbox),
|
customopts.WithAnnotation(annotations.ContainerType, annotations.ContainerTypeSandbox),
|
||||||
customopts.WithAnnotation(annotations.SandboxID, id),
|
customopts.WithAnnotation(annotations.SandboxID, id),
|
||||||
|
customopts.WithAnnotation(annotations.SandboxNamespace, config.GetMetadata().GetNamespace()),
|
||||||
|
customopts.WithAnnotation(annotations.SandboxName, config.GetMetadata().GetName()),
|
||||||
customopts.WithAnnotation(annotations.SandboxLogDir, config.GetLogDirectory()),
|
customopts.WithAnnotation(annotations.SandboxLogDir, config.GetLogDirectory()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -64,6 +64,12 @@ func getRunPodSandboxTestData() (*runtime.PodSandboxConfig, *imagespec.ImageConf
|
|||||||
assert.Contains(t, spec.Annotations, annotations.ContainerType)
|
assert.Contains(t, spec.Annotations, annotations.ContainerType)
|
||||||
assert.EqualValues(t, spec.Annotations[annotations.ContainerType], annotations.ContainerTypeSandbox)
|
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.SandboxName)
|
||||||
|
assert.EqualValues(t, spec.Annotations[annotations.SandboxName], "test-name")
|
||||||
|
|
||||||
assert.Contains(t, spec.Annotations, annotations.SandboxLogDir)
|
assert.Contains(t, spec.Annotations, annotations.SandboxLogDir)
|
||||||
assert.EqualValues(t, spec.Annotations[annotations.SandboxLogDir], "test-log-directory")
|
assert.EqualValues(t, spec.Annotations[annotations.SandboxLogDir], "test-log-directory")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user