Bumping k8s dependencies to 1.13
This commit is contained in:
280
vendor/k8s.io/kubernetes/pkg/printers/internalversion/describe.go
generated
vendored
280
vendor/k8s.io/kubernetes/pkg/printers/internalversion/describe.go
generated
vendored
@@ -44,6 +44,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/duration"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/client-go/dynamic"
|
||||
@@ -275,19 +276,22 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte
|
||||
func smartLabelFor(field string) string {
|
||||
commonAcronyms := []string{"API", "URL", "UID", "OSB", "GUID"}
|
||||
|
||||
splitted := camelcase.Split(field)
|
||||
for i := 0; i < len(splitted); i++ {
|
||||
part := splitted[i]
|
||||
parts := camelcase.Split(field)
|
||||
result := make([]string, 0, len(parts))
|
||||
for _, part := range parts {
|
||||
if part == "_" {
|
||||
continue
|
||||
}
|
||||
|
||||
if slice.ContainsString(commonAcronyms, strings.ToUpper(part), nil) {
|
||||
part = strings.ToUpper(part)
|
||||
} else {
|
||||
part = strings.Title(part)
|
||||
}
|
||||
splitted[i] = part
|
||||
result = append(result, part)
|
||||
}
|
||||
|
||||
return strings.Join(splitted, " ")
|
||||
return strings.Join(result, " ")
|
||||
}
|
||||
|
||||
// DefaultObjectDescriber can describe the default Kubernetes objects.
|
||||
@@ -639,7 +643,7 @@ func describePod(pod *api.Pod, events *api.EventList) (string, error) {
|
||||
printLabelsMultiline(w, "Labels", pod.Labels)
|
||||
printAnnotationsMultiline(w, "Annotations", pod.Annotations)
|
||||
if pod.DeletionTimestamp != nil {
|
||||
w.Write(LEVEL_0, "Status:\tTerminating (lasts %s)\n", translateTimestamp(*pod.DeletionTimestamp))
|
||||
w.Write(LEVEL_0, "Status:\tTerminating (lasts %s)\n", translateTimestampUntil(*pod.DeletionTimestamp))
|
||||
w.Write(LEVEL_0, "Termination Grace Period:\t%ds\n", *pod.DeletionGracePeriodSeconds)
|
||||
} else {
|
||||
w.Write(LEVEL_0, "Status:\t%s\n", string(pod.Status.Phase))
|
||||
@@ -1125,6 +1129,48 @@ func printCSIPersistentVolumeSource(csi *api.CSIPersistentVolumeSource, w Prefix
|
||||
" VolumeHandle:\t%v\n"+
|
||||
" ReadOnly:\t%v\n",
|
||||
csi.Driver, csi.VolumeHandle, csi.ReadOnly)
|
||||
printCSIPersistentVolumeAttributesMultiline(w, "VolumeAttributes", csi.VolumeAttributes)
|
||||
}
|
||||
|
||||
func printCSIPersistentVolumeAttributesMultiline(w PrefixWriter, title string, annotations map[string]string) {
|
||||
printCSIPersistentVolumeAttributesMultilineIndent(w, "", title, "\t", annotations, sets.NewString())
|
||||
}
|
||||
|
||||
func printCSIPersistentVolumeAttributesMultilineIndent(w PrefixWriter, initialIndent, title, innerIndent string, attributes map[string]string, skip sets.String) {
|
||||
w.Write(LEVEL_2, "%s%s:%s", initialIndent, title, innerIndent)
|
||||
|
||||
if len(attributes) == 0 {
|
||||
w.WriteLine("<none>")
|
||||
return
|
||||
}
|
||||
|
||||
// to print labels in the sorted order
|
||||
keys := make([]string, 0, len(attributes))
|
||||
for key := range attributes {
|
||||
if skip.Has(key) {
|
||||
continue
|
||||
}
|
||||
keys = append(keys, key)
|
||||
}
|
||||
if len(attributes) == 0 {
|
||||
w.WriteLine("<none>")
|
||||
return
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
for i, key := range keys {
|
||||
if i != 0 {
|
||||
w.Write(LEVEL_2, initialIndent)
|
||||
w.Write(LEVEL_2, innerIndent)
|
||||
}
|
||||
line := fmt.Sprintf("%s=%s", key, attributes[key])
|
||||
if len(line) > maxAnnotationLen {
|
||||
w.Write(LEVEL_2, "%s...\n", line[:maxAnnotationLen])
|
||||
} else {
|
||||
w.Write(LEVEL_2, "%s\n", line)
|
||||
}
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
type PersistentVolumeDescriber struct {
|
||||
@@ -1193,12 +1239,12 @@ func describePersistentVolume(pv *api.PersistentVolume, events *api.EventList) (
|
||||
return tabbedString(func(out io.Writer) error {
|
||||
w := NewPrefixWriter(out)
|
||||
w.Write(LEVEL_0, "Name:\t%s\n", pv.Name)
|
||||
printLabelsMultiline(w, "Labels", pv.Labels)
|
||||
printAnnotationsMultiline(w, "Annotations", pv.Annotations)
|
||||
printLabelsMultiline(w, "Labels", pv.ObjectMeta.Labels)
|
||||
printAnnotationsMultiline(w, "Annotations", pv.ObjectMeta.Annotations)
|
||||
w.Write(LEVEL_0, "Finalizers:\t%v\n", pv.ObjectMeta.Finalizers)
|
||||
w.Write(LEVEL_0, "StorageClass:\t%s\n", helper.GetPersistentVolumeClass(pv))
|
||||
if pv.ObjectMeta.DeletionTimestamp != nil {
|
||||
w.Write(LEVEL_0, "Status:\tTerminating (lasts %s)\n", translateTimestamp(*pv.ObjectMeta.DeletionTimestamp))
|
||||
w.Write(LEVEL_0, "Status:\tTerminating (lasts %s)\n", translateTimestampUntil(*pv.ObjectMeta.DeletionTimestamp))
|
||||
} else {
|
||||
w.Write(LEVEL_0, "Status:\t%v\n", pv.Status.Phase)
|
||||
}
|
||||
@@ -1287,19 +1333,59 @@ func (d *PersistentVolumeClaimDescriber) Describe(namespace, name string, descri
|
||||
return "", err
|
||||
}
|
||||
|
||||
pc := d.Core().Pods(namespace)
|
||||
|
||||
mountPods, err := getMountPods(pc, pvc.Name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
events, _ := d.Core().Events(namespace).Search(legacyscheme.Scheme, pvc)
|
||||
|
||||
return describePersistentVolumeClaim(pvc, events)
|
||||
return describePersistentVolumeClaim(pvc, events, mountPods)
|
||||
}
|
||||
|
||||
func describePersistentVolumeClaim(pvc *api.PersistentVolumeClaim, events *api.EventList) (string, error) {
|
||||
func getMountPods(c coreclient.PodInterface, pvcName string) ([]api.Pod, error) {
|
||||
nsPods, err := c.List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return []api.Pod{}, err
|
||||
}
|
||||
|
||||
var pods []api.Pod
|
||||
|
||||
for _, pod := range nsPods.Items {
|
||||
pvcs := getPvcs(pod.Spec.Volumes)
|
||||
|
||||
for _, pvc := range pvcs {
|
||||
if pvc.PersistentVolumeClaim.ClaimName == pvcName {
|
||||
pods = append(pods, pod)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pods, nil
|
||||
}
|
||||
|
||||
func getPvcs(volumes []api.Volume) []api.Volume {
|
||||
var pvcs []api.Volume
|
||||
|
||||
for _, volume := range volumes {
|
||||
if volume.VolumeSource.PersistentVolumeClaim != nil {
|
||||
pvcs = append(pvcs, volume)
|
||||
}
|
||||
}
|
||||
|
||||
return pvcs
|
||||
}
|
||||
|
||||
func describePersistentVolumeClaim(pvc *api.PersistentVolumeClaim, events *api.EventList, mountPods []api.Pod) (string, error) {
|
||||
return tabbedString(func(out io.Writer) error {
|
||||
w := NewPrefixWriter(out)
|
||||
w.Write(LEVEL_0, "Name:\t%s\n", pvc.Name)
|
||||
w.Write(LEVEL_0, "Namespace:\t%s\n", pvc.Namespace)
|
||||
w.Write(LEVEL_0, "StorageClass:\t%s\n", helper.GetPersistentVolumeClaimClass(pvc))
|
||||
if pvc.ObjectMeta.DeletionTimestamp != nil {
|
||||
w.Write(LEVEL_0, "Status:\tTerminating (lasts %s)\n", translateTimestamp(*pvc.ObjectMeta.DeletionTimestamp))
|
||||
w.Write(LEVEL_0, "Status:\tTerminating (lasts %s)\n", translateTimestampUntil(*pvc.ObjectMeta.DeletionTimestamp))
|
||||
} else {
|
||||
w.Write(LEVEL_0, "Status:\t%v\n", pvc.Status.Phase)
|
||||
}
|
||||
@@ -1338,6 +1424,8 @@ func describePersistentVolumeClaim(pvc *api.PersistentVolumeClaim, events *api.E
|
||||
DescribeEvents(events, w)
|
||||
}
|
||||
|
||||
printPodsMultiline(w, "Mounted By", mountPods)
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1423,13 +1511,17 @@ func describeContainerCommand(container api.Container, w PrefixWriter) {
|
||||
if len(container.Command) > 0 {
|
||||
w.Write(LEVEL_2, "Command:\n")
|
||||
for _, c := range container.Command {
|
||||
w.Write(LEVEL_3, "%s\n", c)
|
||||
for _, s := range strings.Split(c, "\n") {
|
||||
w.Write(LEVEL_3, "%s\n", s)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(container.Args) > 0 {
|
||||
w.Write(LEVEL_2, "Args:\n")
|
||||
for _, arg := range container.Args {
|
||||
w.Write(LEVEL_3, "%s\n", arg)
|
||||
for _, s := range strings.Split(arg, "\n") {
|
||||
w.Write(LEVEL_3, "%s\n", s)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1512,7 +1604,13 @@ func describeContainerEnvVars(container api.Container, resolverFn EnvVarResolver
|
||||
|
||||
for _, e := range container.Env {
|
||||
if e.ValueFrom == nil {
|
||||
w.Write(LEVEL_3, "%s:\t%s\n", e.Name, e.Value)
|
||||
for i, s := range strings.Split(e.Value, "\n") {
|
||||
if i == 0 {
|
||||
w.Write(LEVEL_3, "%s:\t%s\n", e.Name, s)
|
||||
} else {
|
||||
w.Write(LEVEL_3, "\t%s\n", s)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -1598,7 +1696,12 @@ type EnvVarResolverFunc func(e api.EnvVar) string
|
||||
// EnvValueFrom is exported for use by describers in other packages
|
||||
func EnvValueRetriever(pod *api.Pod) EnvVarResolverFunc {
|
||||
return func(e api.EnvVar) string {
|
||||
internalFieldPath, _, err := legacyscheme.Scheme.ConvertFieldLabel(e.ValueFrom.FieldRef.APIVersion, "Pod", e.ValueFrom.FieldRef.FieldPath, "")
|
||||
gv, err := schema.ParseGroupVersion(e.ValueFrom.FieldRef.APIVersion)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
gvk := gv.WithKind("Pod")
|
||||
internalFieldPath, _, err := legacyscheme.Scheme.ConvertFieldLabel(gvk, e.ValueFrom.FieldRef.FieldPath, "")
|
||||
if err != nil {
|
||||
return "" // pod validation should catch this on create
|
||||
}
|
||||
@@ -1852,6 +1955,12 @@ func describeJob(job *batch.Job, events *api.EventList) (string, error) {
|
||||
if job.Status.StartTime != nil {
|
||||
w.Write(LEVEL_0, "Start Time:\t%s\n", job.Status.StartTime.Time.Format(time.RFC1123Z))
|
||||
}
|
||||
if job.Status.CompletionTime != nil {
|
||||
w.Write(LEVEL_0, "Completed At:\t%s\n", job.Status.CompletionTime.Time.Format(time.RFC1123Z))
|
||||
}
|
||||
if job.Status.StartTime != nil && job.Status.CompletionTime != nil {
|
||||
w.Write(LEVEL_0, "Duration:\t%s\n", duration.HumanDuration(job.Status.CompletionTime.Sub(job.Status.StartTime.Time)))
|
||||
}
|
||||
if job.Spec.ActiveDeadlineSeconds != nil {
|
||||
w.Write(LEVEL_0, "Active Deadline Seconds:\t%ds\n", *job.Spec.ActiveDeadlineSeconds)
|
||||
}
|
||||
@@ -2905,50 +3014,50 @@ func describeHorizontalPodAutoscaler(hpa *autoscaling.HorizontalPodAutoscaler, e
|
||||
for i, metric := range hpa.Spec.Metrics {
|
||||
switch metric.Type {
|
||||
case autoscaling.ExternalMetricSourceType:
|
||||
if metric.External.TargetAverageValue != nil {
|
||||
if metric.External.Target.AverageValue != nil {
|
||||
current := "<unknown>"
|
||||
if len(hpa.Status.CurrentMetrics) > i && hpa.Status.CurrentMetrics[i].External != nil &&
|
||||
hpa.Status.CurrentMetrics[i].External.CurrentAverageValue != nil {
|
||||
current = hpa.Status.CurrentMetrics[i].External.CurrentAverageValue.String()
|
||||
&hpa.Status.CurrentMetrics[i].External.Current.AverageValue != nil {
|
||||
current = hpa.Status.CurrentMetrics[i].External.Current.AverageValue.String()
|
||||
}
|
||||
w.Write(LEVEL_1, "%q (target average value):\t%s / %s\n", metric.External.MetricName, current, metric.External.TargetAverageValue.String())
|
||||
w.Write(LEVEL_1, "%q (target average value):\t%s / %s\n", metric.External.Metric.Name, current, metric.External.Target.AverageValue.String())
|
||||
} else {
|
||||
current := "<unknown>"
|
||||
if len(hpa.Status.CurrentMetrics) > i && hpa.Status.CurrentMetrics[i].External != nil {
|
||||
current = hpa.Status.CurrentMetrics[i].External.CurrentValue.String()
|
||||
current = hpa.Status.CurrentMetrics[i].External.Current.Value.String()
|
||||
}
|
||||
w.Write(LEVEL_1, "%q (target value):\t%s / %s\n", metric.External.MetricName, current, metric.External.TargetValue.String())
|
||||
w.Write(LEVEL_1, "%q (target value):\t%s / %s\n", metric.External.Metric.Name, current, metric.External.Target.Value.String())
|
||||
|
||||
}
|
||||
case autoscaling.PodsMetricSourceType:
|
||||
current := "<unknown>"
|
||||
if len(hpa.Status.CurrentMetrics) > i && hpa.Status.CurrentMetrics[i].Pods != nil {
|
||||
current = hpa.Status.CurrentMetrics[i].Pods.CurrentAverageValue.String()
|
||||
current = hpa.Status.CurrentMetrics[i].Pods.Current.AverageValue.String()
|
||||
}
|
||||
w.Write(LEVEL_1, "%q on pods:\t%s / %s\n", metric.Pods.MetricName, current, metric.Pods.TargetAverageValue.String())
|
||||
w.Write(LEVEL_1, "%q on pods:\t%s / %s\n", metric.Pods.Metric.Name, current, metric.Pods.Target.AverageValue.String())
|
||||
case autoscaling.ObjectMetricSourceType:
|
||||
current := "<unknown>"
|
||||
if len(hpa.Status.CurrentMetrics) > i && hpa.Status.CurrentMetrics[i].Object != nil {
|
||||
current = hpa.Status.CurrentMetrics[i].Object.CurrentValue.String()
|
||||
current = hpa.Status.CurrentMetrics[i].Object.Current.Value.String()
|
||||
}
|
||||
w.Write(LEVEL_1, "%q on %s/%s:\t%s / %s\n", metric.Object.MetricName, metric.Object.Target.Kind, metric.Object.Target.Name, current, metric.Object.TargetValue.String())
|
||||
w.Write(LEVEL_1, "%q on %s/%s:\t%s / %s\n", metric.Object.Metric.Name, metric.Object.DescribedObject.Kind, metric.Object.DescribedObject.Name, current, metric.Object.Target.Value.String())
|
||||
case autoscaling.ResourceMetricSourceType:
|
||||
w.Write(LEVEL_1, "resource %s on pods", string(metric.Resource.Name))
|
||||
if metric.Resource.TargetAverageValue != nil {
|
||||
if metric.Resource.Target.AverageValue != nil {
|
||||
current := "<unknown>"
|
||||
if len(hpa.Status.CurrentMetrics) > i && hpa.Status.CurrentMetrics[i].Resource != nil {
|
||||
current = hpa.Status.CurrentMetrics[i].Resource.CurrentAverageValue.String()
|
||||
current = hpa.Status.CurrentMetrics[i].Resource.Current.AverageValue.String()
|
||||
}
|
||||
w.Write(LEVEL_0, ":\t%s / %s\n", current, metric.Resource.TargetAverageValue.String())
|
||||
w.Write(LEVEL_0, ":\t%s / %s\n", current, metric.Resource.Target.AverageValue.String())
|
||||
} else {
|
||||
current := "<unknown>"
|
||||
if len(hpa.Status.CurrentMetrics) > i && hpa.Status.CurrentMetrics[i].Resource != nil && hpa.Status.CurrentMetrics[i].Resource.CurrentAverageUtilization != nil {
|
||||
current = fmt.Sprintf("%d%% (%s)", *hpa.Status.CurrentMetrics[i].Resource.CurrentAverageUtilization, hpa.Status.CurrentMetrics[i].Resource.CurrentAverageValue.String())
|
||||
if len(hpa.Status.CurrentMetrics) > i && hpa.Status.CurrentMetrics[i].Resource != nil && hpa.Status.CurrentMetrics[i].Resource.Current.AverageUtilization != nil {
|
||||
current = fmt.Sprintf("%d%% (%s)", *hpa.Status.CurrentMetrics[i].Resource.Current.AverageUtilization, hpa.Status.CurrentMetrics[i].Resource.Current.AverageValue.String())
|
||||
}
|
||||
|
||||
target := "<auto>"
|
||||
if metric.Resource.TargetAverageUtilization != nil {
|
||||
target = fmt.Sprintf("%d%%", *metric.Resource.TargetAverageUtilization)
|
||||
if metric.Resource.Target.AverageUtilization != nil {
|
||||
target = fmt.Sprintf("%d%%", *metric.Resource.Target.AverageUtilization)
|
||||
}
|
||||
w.Write(LEVEL_1, "(as a percentage of request):\t%s / %s\n", current, target)
|
||||
}
|
||||
@@ -3073,9 +3182,9 @@ func DescribeEvents(el *api.EventList, w PrefixWriter) {
|
||||
for _, e := range el.Items {
|
||||
var interval string
|
||||
if e.Count > 1 {
|
||||
interval = fmt.Sprintf("%s (x%d over %s)", translateTimestamp(e.LastTimestamp), e.Count, translateTimestamp(e.FirstTimestamp))
|
||||
interval = fmt.Sprintf("%s (x%d over %s)", translateTimestampSince(e.LastTimestamp), e.Count, translateTimestampSince(e.FirstTimestamp))
|
||||
} else {
|
||||
interval = translateTimestamp(e.FirstTimestamp)
|
||||
interval = translateTimestampSince(e.FirstTimestamp)
|
||||
}
|
||||
w.Write(LEVEL_1, "%v\t%v\t%s\t%v\t%v\n",
|
||||
e.Type,
|
||||
@@ -3407,6 +3516,9 @@ func describeStorageClass(sc *storage.StorageClass, events *api.EventList) (stri
|
||||
if sc.VolumeBindingMode != nil {
|
||||
w.Write(LEVEL_0, "VolumeBindingMode:\t%s\n", *sc.VolumeBindingMode)
|
||||
}
|
||||
if sc.AllowedTopologies != nil {
|
||||
printAllowedTopologies(w, sc.AllowedTopologies)
|
||||
}
|
||||
if events != nil {
|
||||
DescribeEvents(events, w)
|
||||
}
|
||||
@@ -3415,6 +3527,38 @@ func describeStorageClass(sc *storage.StorageClass, events *api.EventList) (stri
|
||||
})
|
||||
}
|
||||
|
||||
func printAllowedTopologies(w PrefixWriter, topologies []api.TopologySelectorTerm) {
|
||||
w.Write(LEVEL_0, "AllowedTopologies:\t")
|
||||
if len(topologies) == 0 {
|
||||
w.WriteLine("<none>")
|
||||
return
|
||||
}
|
||||
w.WriteLine("")
|
||||
for i, term := range topologies {
|
||||
printTopologySelectorTermsMultilineWithIndent(w, LEVEL_1, fmt.Sprintf("Term %d", i), "\t", term.MatchLabelExpressions)
|
||||
}
|
||||
}
|
||||
|
||||
func printTopologySelectorTermsMultilineWithIndent(w PrefixWriter, indentLevel int, title, innerIndent string, reqs []api.TopologySelectorLabelRequirement) {
|
||||
w.Write(indentLevel, "%s:%s", title, innerIndent)
|
||||
|
||||
if len(reqs) == 0 {
|
||||
w.WriteLine("<none>")
|
||||
return
|
||||
}
|
||||
|
||||
for i, req := range reqs {
|
||||
if i != 0 {
|
||||
w.Write(indentLevel, "%s", innerIndent)
|
||||
}
|
||||
exprStr := fmt.Sprintf("%s %s", req.Key, "in")
|
||||
if len(req.Values) > 0 {
|
||||
exprStr = fmt.Sprintf("%s [%s]", exprStr, strings.Join(req.Values, ", "))
|
||||
}
|
||||
w.Write(LEVEL_0, "%s\n", exprStr)
|
||||
}
|
||||
}
|
||||
|
||||
type PodDisruptionBudgetDescriber struct {
|
||||
clientset.Interface
|
||||
}
|
||||
@@ -3530,6 +3674,12 @@ func describePodSecurityPolicy(psp *policy.PodSecurityPolicy) (string, error) {
|
||||
if len(psp.Spec.AllowedFlexVolumes) > 0 {
|
||||
w.Write(LEVEL_1, "Allowed FlexVolume Types:\t%s\n", flexVolumesToString(psp.Spec.AllowedFlexVolumes))
|
||||
}
|
||||
if len(psp.Spec.AllowedUnsafeSysctls) > 0 {
|
||||
w.Write(LEVEL_1, "Allowed Unsafe Sysctls:\t%s\n", sysctlsToString(psp.Spec.AllowedUnsafeSysctls))
|
||||
}
|
||||
if len(psp.Spec.ForbiddenSysctls) > 0 {
|
||||
w.Write(LEVEL_1, "Forbidden Sysctls:\t%s\n", sysctlsToString(psp.Spec.ForbiddenSysctls))
|
||||
}
|
||||
w.Write(LEVEL_1, "Allow Host Network:\t%t\n", psp.Spec.HostNetwork)
|
||||
w.Write(LEVEL_1, "Allow Host Ports:\t%s\n", hostPortRangeToString(psp.Spec.HostPorts))
|
||||
w.Write(LEVEL_1, "Allow Host PID:\t%t\n", psp.Spec.HostPID)
|
||||
@@ -3589,6 +3739,10 @@ func flexVolumesToString(flexVolumes []policy.AllowedFlexVolume) string {
|
||||
return stringOrDefaultValue(strings.Join(volumes, ","), "<all>")
|
||||
}
|
||||
|
||||
func sysctlsToString(sysctls []string) string {
|
||||
return stringOrNone(strings.Join(sysctls, ","))
|
||||
}
|
||||
|
||||
func hostPortRangeToString(ranges []policy.HostPortRange) string {
|
||||
formattedString := ""
|
||||
if ranges != nil {
|
||||
@@ -3847,6 +4001,37 @@ func printTaintsMultilineWithIndent(w PrefixWriter, initialIndent, title, innerI
|
||||
}
|
||||
}
|
||||
|
||||
// printPodsMultiline prints multiple pods with a proper alignment.
|
||||
func printPodsMultiline(w PrefixWriter, title string, pods []api.Pod) {
|
||||
printPodsMultilineWithIndent(w, "", title, "\t", pods)
|
||||
}
|
||||
|
||||
// printPodsMultilineWithIndent prints multiple pods with a user-defined alignment.
|
||||
func printPodsMultilineWithIndent(w PrefixWriter, initialIndent, title, innerIndent string, pods []api.Pod) {
|
||||
w.Write(LEVEL_0, "%s%s:%s", initialIndent, title, innerIndent)
|
||||
|
||||
if pods == nil || len(pods) == 0 {
|
||||
w.WriteLine("<none>")
|
||||
return
|
||||
}
|
||||
|
||||
// to print pods in the sorted order
|
||||
sort.Slice(pods, func(i, j int) bool {
|
||||
cmpKey := func(pod api.Pod) string {
|
||||
return pod.Name
|
||||
}
|
||||
return cmpKey(pods[i]) < cmpKey(pods[j])
|
||||
})
|
||||
|
||||
for i, pod := range pods {
|
||||
if i != 0 {
|
||||
w.Write(LEVEL_0, "%s", initialIndent)
|
||||
w.Write(LEVEL_0, "%s", innerIndent)
|
||||
}
|
||||
w.Write(LEVEL_0, "%s\n", pod.Name)
|
||||
}
|
||||
}
|
||||
|
||||
// printPodTolerationsMultiline prints multiple tolerations with a proper alignment.
|
||||
func printPodTolerationsMultiline(w PrefixWriter, title string, tolerations []api.Toleration) {
|
||||
printTolerationsMultilineWithIndent(w, "", title, "\t", tolerations)
|
||||
@@ -3970,7 +4155,7 @@ func (list SortableVolumeDevices) Less(i, j int) bool {
|
||||
return list[i].DevicePath < list[j].DevicePath
|
||||
}
|
||||
|
||||
var maxAnnotationLen = 200
|
||||
var maxAnnotationLen = 140
|
||||
|
||||
// printAnnotationsMultilineWithFilter prints filtered multiple annotations with a proper alignment.
|
||||
func printAnnotationsMultilineWithFilter(w PrefixWriter, title string, annotations map[string]string, skip sets.String) {
|
||||
@@ -4006,18 +4191,27 @@ func printAnnotationsMultilineWithIndent(w PrefixWriter, initialIndent, title, i
|
||||
return
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
indent := initialIndent + innerIndent
|
||||
for i, key := range keys {
|
||||
if i != 0 {
|
||||
w.Write(LEVEL_0, initialIndent)
|
||||
w.Write(LEVEL_0, innerIndent)
|
||||
w.Write(LEVEL_0, indent)
|
||||
}
|
||||
line := fmt.Sprintf("%s=%s", key, annotations[key])
|
||||
if len(line) > maxAnnotationLen {
|
||||
w.Write(LEVEL_0, "%s...\n", line[:maxAnnotationLen])
|
||||
value := strings.TrimSuffix(annotations[key], "\n")
|
||||
if (len(value)+len(key)+2) > maxAnnotationLen || strings.Contains(value, "\n") {
|
||||
w.Write(LEVEL_0, "%s:\n", key)
|
||||
for _, s := range strings.Split(value, "\n") {
|
||||
w.Write(LEVEL_0, "%s %s\n", indent, shorten(s, maxAnnotationLen-2))
|
||||
}
|
||||
} else {
|
||||
w.Write(LEVEL_0, "%s\n", line)
|
||||
w.Write(LEVEL_0, "%s: %s\n", key, value)
|
||||
}
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
func shorten(s string, maxLength int) string {
|
||||
if len(s) > maxLength {
|
||||
return s[:maxLength] + "..."
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
Reference in New Issue
Block a user