From eec6456f514be169928209d4e3ac3f7e9640735b Mon Sep 17 00:00:00 2001 From: Yifan Gu Date: Fri, 20 Mar 2015 14:16:55 -0700 Subject: [PATCH] kubelet.container: Add helpers in container runtime to filter pod/containers. --- pkg/kubelet/container/runtime.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pkg/kubelet/container/runtime.go b/pkg/kubelet/container/runtime.go index 657c05471e3..ceb19fe5d71 100644 --- a/pkg/kubelet/container/runtime.go +++ b/pkg/kubelet/container/runtime.go @@ -81,4 +81,33 @@ type Container struct { // Hash of the container, used for comparison. Optional for containers // not managed by kubelet. Hash uint64 + // The timestamp of the creation time of the container. + // TODO(yifan): Consider to move it to api.ContainerStatus. + Created int64 +} + +type Pods []*Pod + +// FindPodByID returns a pod in the pod list by UID. It will return an empty pod +// if not found. +// TODO(yifan): Use a map? +func (p Pods) FindPodByID(podUID types.UID) Pod { + for i := range p { + if p[i].ID == podUID { + return *p[i] + } + } + return Pod{} +} + +// FindContainerByName returns a container in the pod with the given name. +// When there are multiple containers with the same name, the first match will +// be returned. +func (p *Pod) FindContainerByName(containerName string) *Container { + for _, c := range p.Containers { + if c.Name == containerName { + return c + } + } + return nil }