From cd335191066979dad43eea78223062fd11c9182f Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Thu, 8 Nov 2018 18:21:28 -0800 Subject: [PATCH] Use metadata to filter instead of using labels. Signed-off-by: Lantao Liu --- cmd/crictl/constants.go | 25 ------------------------- cmd/crictl/container.go | 2 +- cmd/crictl/sandbox.go | 4 ++-- 3 files changed, 3 insertions(+), 28 deletions(-) delete mode 100644 cmd/crictl/constants.go diff --git a/cmd/crictl/constants.go b/cmd/crictl/constants.go deleted file mode 100644 index 9934ccdef0..0000000000 --- a/cmd/crictl/constants.go +++ /dev/null @@ -1,25 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package main - -const ( - // This labels are copied from kubelet directly, and may change - // without warning in the future. - kubePodNameLabel = "io.kubernetes.pod.name" - kubePodNamespaceLabel = "io.kubernetes.pod.namespace" - kubeContainerNameLabel = "io.kubernetes.container.name" -) diff --git a/cmd/crictl/container.go b/cmd/crictl/container.go index 9d3fdde5fc..44d3f049b1 100644 --- a/cmd/crictl/container.go +++ b/cmd/crictl/container.go @@ -624,7 +624,7 @@ func ListContainers(client pb.RuntimeServiceClient, opts listOptions) error { } for _, c := range r.Containers { // Filter by pod name/namespace regular expressions. - if !matchesRegex(opts.nameRegexp, c.Labels[kubeContainerNameLabel]) { + if !matchesRegex(opts.nameRegexp, c.Metadata.Name) { continue } if opts.quiet { diff --git a/cmd/crictl/sandbox.go b/cmd/crictl/sandbox.go index e79396a657..209240d56a 100644 --- a/cmd/crictl/sandbox.go +++ b/cmd/crictl/sandbox.go @@ -434,10 +434,10 @@ func ListPodSandboxes(client pb.RuntimeServiceClient, opts listOptions) error { } for _, pod := range r.Items { // Filter by pod name/namespace regular expressions. - if !matchesRegex(opts.nameRegexp, pod.Labels[kubePodNameLabel]) { + if !matchesRegex(opts.nameRegexp, pod.Metadata.Name) { continue } - if !matchesRegex(opts.podNamespaceRegexp, pod.Labels[kubePodNamespaceLabel]) { + if !matchesRegex(opts.podNamespaceRegexp, pod.Metadata.Namespace) { continue }