diff --git a/pkg/kubelet/dockershim/docker_container.go b/pkg/kubelet/dockershim/docker_container.go index 5d9fd05df1f..b05c390b238 100644 --- a/pkg/kubelet/dockershim/docker_container.go +++ b/pkg/kubelet/dockershim/docker_container.go @@ -48,7 +48,7 @@ func (ds *dockerService) ListContainers(filter *runtimeApi.ContainerFilter) ([]* f.Add("status", toDockerContainerStatus(filter.GetState())) } if filter.PodSandboxId != nil { - // TODO: implement this after sandbox functions are implemented. + f.AddLabel(sandboxIDLabelKey, *filter.PodSandboxId) } if filter.LabelSelector != nil { @@ -91,6 +91,8 @@ func (ds *dockerService) CreateContainer(podSandboxID string, config *runtimeApi labels := makeLabels(config.GetLabels(), config.GetAnnotations()) // Apply a the container type label. labels[containerTypeLabelKey] = containerTypeLabelContainer + // Write the sandbox ID in the labels. + labels[sandboxIDLabelKey] = podSandboxID image := "" if iSpec := config.GetImage(); iSpec != nil { diff --git a/pkg/kubelet/dockershim/docker_service.go b/pkg/kubelet/dockershim/docker_service.go index 168f5e14c0b..9923a94b3e4 100644 --- a/pkg/kubelet/dockershim/docker_service.go +++ b/pkg/kubelet/dockershim/docker_service.go @@ -47,8 +47,11 @@ const ( containerTypeLabelKey = "io.kubernetes.docker.type" containerTypeLabelSandbox = "podsandbox" containerTypeLabelContainer = "container" + sandboxIDLabelKey = "io.kubernetes.sandbox.id" ) +var internalLabelKeys []string = []string{containerTypeLabelKey, sandboxIDLabelKey} + func NewDockerService(client dockertools.DockerInterface) DockerLegacyService { return &dockerService{ client: dockertools.NewInstrumentedDockerInterface(client), diff --git a/pkg/kubelet/dockershim/helpers.go b/pkg/kubelet/dockershim/helpers.go index 5a3099cc1f8..61a5cd3f2aa 100644 --- a/pkg/kubelet/dockershim/helpers.go +++ b/pkg/kubelet/dockershim/helpers.go @@ -84,11 +84,20 @@ func extractLabels(input map[string]string) (map[string]string, map[string]strin annotations := make(map[string]string) for k, v := range input { // Check if the key is used internally by the shim. - // TODO: containerTypeLabelKey is the only internal label the shim uses - // right now. Expand this to a list later. - if k == containerTypeLabelKey { + internal := false + for _, internalKey := range internalLabelKeys { + // 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 } + + // Check if the label should be treated as an annotation. if strings.HasPrefix(k, annotationPrefix) { annotations[strings.TrimPrefix(k, annotationPrefix)] = v continue