Commit 73f30b18 authored by Yu-Ju Hong's avatar Yu-Ju Hong

dockershim: support filter containers by sandbox ID

parent 2f60b72d
...@@ -48,7 +48,7 @@ func (ds *dockerService) ListContainers(filter *runtimeApi.ContainerFilter) ([]* ...@@ -48,7 +48,7 @@ func (ds *dockerService) ListContainers(filter *runtimeApi.ContainerFilter) ([]*
f.Add("status", toDockerContainerStatus(filter.GetState())) f.Add("status", toDockerContainerStatus(filter.GetState()))
} }
if filter.PodSandboxId != nil { if filter.PodSandboxId != nil {
// TODO: implement this after sandbox functions are implemented. f.AddLabel(sandboxIDLabelKey, *filter.PodSandboxId)
} }
if filter.LabelSelector != nil { if filter.LabelSelector != nil {
...@@ -91,6 +91,8 @@ func (ds *dockerService) CreateContainer(podSandboxID string, config *runtimeApi ...@@ -91,6 +91,8 @@ func (ds *dockerService) CreateContainer(podSandboxID string, config *runtimeApi
labels := makeLabels(config.GetLabels(), config.GetAnnotations()) labels := makeLabels(config.GetLabels(), config.GetAnnotations())
// Apply a the container type label. // Apply a the container type label.
labels[containerTypeLabelKey] = containerTypeLabelContainer labels[containerTypeLabelKey] = containerTypeLabelContainer
// Write the sandbox ID in the labels.
labels[sandboxIDLabelKey] = podSandboxID
image := "" image := ""
if iSpec := config.GetImage(); iSpec != nil { if iSpec := config.GetImage(); iSpec != nil {
......
...@@ -47,8 +47,11 @@ const ( ...@@ -47,8 +47,11 @@ const (
containerTypeLabelKey = "io.kubernetes.docker.type" containerTypeLabelKey = "io.kubernetes.docker.type"
containerTypeLabelSandbox = "podsandbox" containerTypeLabelSandbox = "podsandbox"
containerTypeLabelContainer = "container" containerTypeLabelContainer = "container"
sandboxIDLabelKey = "io.kubernetes.sandbox.id"
) )
var internalLabelKeys []string = []string{containerTypeLabelKey, sandboxIDLabelKey}
func NewDockerService(client dockertools.DockerInterface) DockerLegacyService { func NewDockerService(client dockertools.DockerInterface) DockerLegacyService {
return &dockerService{ return &dockerService{
client: dockertools.NewInstrumentedDockerInterface(client), client: dockertools.NewInstrumentedDockerInterface(client),
......
...@@ -84,11 +84,20 @@ func extractLabels(input map[string]string) (map[string]string, map[string]strin ...@@ -84,11 +84,20 @@ func extractLabels(input map[string]string) (map[string]string, map[string]strin
annotations := make(map[string]string) annotations := make(map[string]string)
for k, v := range input { for k, v := range input {
// Check if the key is used internally by the shim. // Check if the key is used internally by the shim.
// TODO: containerTypeLabelKey is the only internal label the shim uses internal := false
// right now. Expand this to a list later. for _, internalKey := range internalLabelKeys {
if k == containerTypeLabelKey { // TODO: containerTypeLabelKey is the only internal label the shim uses
// right now. Expand this to a list later.
if k == internalKey {
internal = true
break
}
}
if internal {
continue continue
} }
// Check if the label should be treated as an annotation.
if strings.HasPrefix(k, annotationPrefix) { if strings.HasPrefix(k, annotationPrefix) {
annotations[strings.TrimPrefix(k, annotationPrefix)] = v annotations[strings.TrimPrefix(k, annotationPrefix)] = v
continue continue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment