Add server side container label filtering

Signed-off-by: Mrunal Patel <mpatel@redhat.com>
This commit is contained in:
Mrunal Patel 2016-10-13 17:01:31 -07:00
parent 50cc7ce940
commit d2cae34243

View file

@ -15,6 +15,7 @@ import (
"github.com/opencontainers/runc/libcontainer/label" "github.com/opencontainers/runc/libcontainer/label"
"github.com/opencontainers/runtime-tools/generate" "github.com/opencontainers/runtime-tools/generate"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/kubernetes/pkg/fields"
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
) )
@ -419,7 +420,12 @@ func filterContainer(c *pb.Container, filter *pb.ContainerFilter) bool {
return false return false
} }
} }
// TODO(mrunalp): Add support for label filtering if filter.LabelSelector != nil {
sel := fields.SelectorFromSet(filter.LabelSelector)
if !sel.Matches(fields.Set(c.Labels)) {
return false
}
}
} }
return true return true
} }
@ -473,6 +479,7 @@ func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersReque
Id: &cID, Id: &cID,
PodSandboxId: &podSandboxID, PodSandboxId: &podSandboxID,
CreatedAt: int64Ptr(created), CreatedAt: int64Ptr(created),
Labels: ctr.Labels(),
} }
switch cState.Status { switch cState.Status {