diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2017-11-01 11:24:59 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@gmail.com> | 2017-11-01 11:24:59 -0400 |
commit | a031b83a09a8628435317a03f199cdc18b78262f (patch) | |
tree | bc017a96769ce6de33745b8b0b1304ccf38e9df0 /vendor/k8s.io/kubernetes/pkg/kubelet/util | |
parent | 2b74391cd5281f6fdf391ff8ad50fd1490f6bf89 (diff) | |
download | podman-a031b83a09a8628435317a03f199cdc18b78262f.tar.gz podman-a031b83a09a8628435317a03f199cdc18b78262f.tar.bz2 podman-a031b83a09a8628435317a03f199cdc18b78262f.zip |
Initial checkin from CRI-O repo
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Diffstat (limited to 'vendor/k8s.io/kubernetes/pkg/kubelet/util')
3 files changed, 145 insertions, 0 deletions
diff --git a/vendor/k8s.io/kubernetes/pkg/kubelet/util/format/pod.go b/vendor/k8s.io/kubernetes/pkg/kubelet/util/format/pod.go new file mode 100644 index 000000000..da20d42e8 --- /dev/null +++ b/vendor/k8s.io/kubernetes/pkg/kubelet/util/format/pod.go @@ -0,0 +1,72 @@ +/* +Copyright 2015 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 format + +import ( + "fmt" + "strings" + "time" + + "k8s.io/apimachinery/pkg/types" + "k8s.io/kubernetes/pkg/api/v1" +) + +type podHandler func(*v1.Pod) string + +// Pod returns a string representing a pod in a consistent human readable format, +// with pod UID as part of the string. +func Pod(pod *v1.Pod) string { + return PodDesc(pod.Name, pod.Namespace, pod.UID) +} + +// PodDesc returns a string representing a pod in a consistent human readable format, +// with pod UID as part of the string. +func PodDesc(podName, podNamespace string, podUID types.UID) string { + // Use underscore as the delimiter because it is not allowed in pod name + // (DNS subdomain format), while allowed in the container name format. + return fmt.Sprintf("%s_%s(%s)", podName, podNamespace, podUID) +} + +// PodWithDeletionTimestamp is the same as Pod. In addition, it prints the +// deletion timestamp of the pod if it's not nil. +func PodWithDeletionTimestamp(pod *v1.Pod) string { + var deletionTimestamp string + if pod.DeletionTimestamp != nil { + deletionTimestamp = ":DeletionTimestamp=" + pod.DeletionTimestamp.UTC().Format(time.RFC3339) + } + return Pod(pod) + deletionTimestamp +} + +// Pods returns a string representating a list of pods in a human +// readable format. +func Pods(pods []*v1.Pod) string { + return aggregatePods(pods, Pod) +} + +// PodsWithDeletiontimestamps is the same as Pods. In addition, it prints the +// deletion timestamps of the pods if they are not nil. +func PodsWithDeletiontimestamps(pods []*v1.Pod) string { + return aggregatePods(pods, PodWithDeletionTimestamp) +} + +func aggregatePods(pods []*v1.Pod, handler podHandler) string { + podStrings := make([]string, 0, len(pods)) + for _, pod := range pods { + podStrings = append(podStrings, handler(pod)) + } + return fmt.Sprintf(strings.Join(podStrings, ", ")) +} diff --git a/vendor/k8s.io/kubernetes/pkg/kubelet/util/format/resources.go b/vendor/k8s.io/kubernetes/pkg/kubelet/util/format/resources.go new file mode 100644 index 000000000..bc50bc9c6 --- /dev/null +++ b/vendor/k8s.io/kubernetes/pkg/kubelet/util/format/resources.go @@ -0,0 +1,36 @@ +/* +Copyright 2016 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 format + +import ( + "fmt" + "sort" + "strings" + + "k8s.io/kubernetes/pkg/api/v1" +) + +// ResourceList returns a string representation of a resource list in a human readable format. +func ResourceList(resources v1.ResourceList) string { + resourceStrings := make([]string, 0, len(resources)) + for key, value := range resources { + resourceStrings = append(resourceStrings, fmt.Sprintf("%v=%v", key, value.String())) + } + // sort the results for consistent log output + sort.Strings(resourceStrings) + return strings.Join(resourceStrings, ",") +} diff --git a/vendor/k8s.io/kubernetes/pkg/kubelet/util/ioutils/ioutils.go b/vendor/k8s.io/kubernetes/pkg/kubelet/util/ioutils/ioutils.go new file mode 100644 index 000000000..42f1998c7 --- /dev/null +++ b/vendor/k8s.io/kubernetes/pkg/kubelet/util/ioutils/ioutils.go @@ -0,0 +1,37 @@ +/* +Copyright 2016 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 ioutils + +import "io" + +// writeCloserWrapper represents a WriteCloser whose closer operation is noop. +type writeCloserWrapper struct { + Writer io.Writer +} + +func (w *writeCloserWrapper) Write(buf []byte) (int, error) { + return w.Writer.Write(buf) +} + +func (w *writeCloserWrapper) Close() error { + return nil +} + +// WriteCloserWrapper returns a writeCloserWrapper. +func WriteCloserWrapper(w io.Writer) io.WriteCloser { + return &writeCloserWrapper{w} +} |