2014-10-06 01:24:19 +00:00
|
|
|
/*
|
2017-02-19 03:40:38 +00:00
|
|
|
Copyright 2017 The Kubernetes Authors.
|
2014-10-06 01:24:19 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2017-02-19 03:40:38 +00:00
|
|
|
package internalversion
|
2014-10-06 01:24:19 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2017-02-21 14:21:00 +00:00
|
|
|
"net"
|
2014-12-16 22:20:51 +00:00
|
|
|
"sort"
|
2017-02-21 14:21:00 +00:00
|
|
|
"strconv"
|
2014-10-06 01:24:19 +00:00
|
|
|
"strings"
|
2014-12-16 22:20:51 +00:00
|
|
|
"time"
|
2014-10-06 01:24:19 +00:00
|
|
|
|
2017-01-11 14:09:48 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/labels"
|
|
|
|
"k8s.io/apimachinery/pkg/util/sets"
|
2016-04-26 14:33:47 +00:00
|
|
|
"k8s.io/kubernetes/federation/apis/federation"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2016-09-15 15:56:40 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/events"
|
2017-04-10 17:49:54 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/helper"
|
2016-04-15 22:30:15 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/apps"
|
2016-05-05 10:27:24 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
2016-04-18 15:44:19 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/batch"
|
2016-08-05 21:46:20 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/certificates"
|
2015-10-09 22:04:41 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
2017-03-13 14:31:16 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/networking"
|
2016-10-21 11:57:49 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/policy"
|
2016-06-06 23:59:19 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/rbac"
|
2017-04-21 02:11:01 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/settings"
|
2016-09-01 15:29:26 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/storage"
|
2016-10-12 19:49:16 +00:00
|
|
|
storageutil "k8s.io/kubernetes/pkg/apis/storage/util"
|
2017-02-19 22:37:24 +00:00
|
|
|
"k8s.io/kubernetes/pkg/printers"
|
2016-11-01 19:59:06 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/node"
|
2015-09-23 21:50:59 +00:00
|
|
|
)
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
const loadBalancerWidth = 16
|
2014-10-06 01:24:19 +00:00
|
|
|
|
2015-07-07 19:20:45 +00:00
|
|
|
// NOTE: When adding a new resource type here, please update the list
|
|
|
|
// pkg/kubectl/cmd/get.go to reflect the new resource type.
|
2016-09-20 08:56:25 +00:00
|
|
|
var (
|
2017-01-04 16:32:14 +00:00
|
|
|
podColumns = []string{"NAME", "READY", "STATUS", "RESTARTS", "AGE"}
|
|
|
|
podWideColumns = []string{"IP", "NODE"}
|
|
|
|
podTemplateColumns = []string{"TEMPLATE", "CONTAINER(S)", "IMAGE(S)", "PODLABELS"}
|
2017-05-15 23:50:23 +00:00
|
|
|
podDisruptionBudgetColumns = []string{"NAME", "MIN-AVAILABLE", "MAX-UNAVAILABLE", "ALLOWED-DISRUPTIONS", "AGE"}
|
2017-01-04 16:32:14 +00:00
|
|
|
replicationControllerColumns = []string{"NAME", "DESIRED", "CURRENT", "READY", "AGE"}
|
|
|
|
replicationControllerWideColumns = []string{"CONTAINER(S)", "IMAGE(S)", "SELECTOR"}
|
|
|
|
replicaSetColumns = []string{"NAME", "DESIRED", "CURRENT", "READY", "AGE"}
|
|
|
|
replicaSetWideColumns = []string{"CONTAINER(S)", "IMAGE(S)", "SELECTOR"}
|
|
|
|
jobColumns = []string{"NAME", "DESIRED", "SUCCESSFUL", "AGE"}
|
|
|
|
cronJobColumns = []string{"NAME", "SCHEDULE", "SUSPEND", "ACTIVE", "LAST-SCHEDULE"}
|
|
|
|
batchJobWideColumns = []string{"CONTAINER(S)", "IMAGE(S)", "SELECTOR"}
|
|
|
|
serviceColumns = []string{"NAME", "CLUSTER-IP", "EXTERNAL-IP", "PORT(S)", "AGE"}
|
|
|
|
serviceWideColumns = []string{"SELECTOR"}
|
|
|
|
ingressColumns = []string{"NAME", "HOSTS", "ADDRESS", "PORTS", "AGE"}
|
|
|
|
statefulSetColumns = []string{"NAME", "DESIRED", "CURRENT", "AGE"}
|
|
|
|
endpointColumns = []string{"NAME", "ENDPOINTS", "AGE"}
|
|
|
|
nodeColumns = []string{"NAME", "STATUS", "AGE", "VERSION"}
|
2016-12-16 05:42:59 +00:00
|
|
|
nodeWideColumns = []string{"EXTERNAL-IP", "OS-IMAGE", "KERNEL-VERSION"}
|
2017-03-09 21:24:07 +00:00
|
|
|
daemonSetColumns = []string{"NAME", "DESIRED", "CURRENT", "READY", "UP-TO-DATE", "AVAILABLE", "NODE-SELECTOR", "AGE"}
|
2017-01-04 16:32:14 +00:00
|
|
|
daemonSetWideColumns = []string{"CONTAINER(S)", "IMAGE(S)", "SELECTOR"}
|
|
|
|
eventColumns = []string{"LASTSEEN", "FIRSTSEEN", "COUNT", "NAME", "KIND", "SUBOBJECT", "TYPE", "REASON", "SOURCE", "MESSAGE"}
|
|
|
|
limitRangeColumns = []string{"NAME", "AGE"}
|
|
|
|
resourceQuotaColumns = []string{"NAME", "AGE"}
|
|
|
|
namespaceColumns = []string{"NAME", "STATUS", "AGE"}
|
|
|
|
secretColumns = []string{"NAME", "TYPE", "DATA", "AGE"}
|
|
|
|
serviceAccountColumns = []string{"NAME", "SECRETS", "AGE"}
|
2017-01-06 17:41:04 +00:00
|
|
|
persistentVolumeColumns = []string{"NAME", "CAPACITY", "ACCESSMODES", "RECLAIMPOLICY", "STATUS", "CLAIM", "STORAGECLASS", "REASON", "AGE"}
|
|
|
|
persistentVolumeClaimColumns = []string{"NAME", "STATUS", "VOLUME", "CAPACITY", "ACCESSMODES", "STORAGECLASS", "AGE"}
|
2017-01-04 16:32:14 +00:00
|
|
|
componentStatusColumns = []string{"NAME", "STATUS", "MESSAGE", "ERROR"}
|
|
|
|
thirdPartyResourceColumns = []string{"NAME", "DESCRIPTION", "VERSION(S)"}
|
|
|
|
roleColumns = []string{"NAME", "AGE"}
|
|
|
|
roleBindingColumns = []string{"NAME", "AGE"}
|
|
|
|
roleBindingWideColumns = []string{"ROLE", "USERS", "GROUPS", "SERVICEACCOUNTS"}
|
|
|
|
clusterRoleColumns = []string{"NAME", "AGE"}
|
|
|
|
clusterRoleBindingColumns = []string{"NAME", "AGE"}
|
|
|
|
clusterRoleBindingWideColumns = []string{"ROLE", "USERS", "GROUPS", "SERVICEACCOUNTS"}
|
|
|
|
storageClassColumns = []string{"NAME", "TYPE"}
|
|
|
|
statusColumns = []string{"STATUS", "REASON", "MESSAGE"}
|
2016-09-20 08:56:25 +00:00
|
|
|
|
|
|
|
// TODO: consider having 'KIND' for third party resource data
|
|
|
|
thirdPartyResourceDataColumns = []string{"NAME", "LABELS", "DATA"}
|
2016-11-30 20:58:58 +00:00
|
|
|
horizontalPodAutoscalerColumns = []string{"NAME", "REFERENCE", "TARGETS", "MINPODS", "MAXPODS", "REPLICAS", "AGE"}
|
2016-09-20 08:56:25 +00:00
|
|
|
deploymentColumns = []string{"NAME", "DESIRED", "CURRENT", "UP-TO-DATE", "AVAILABLE", "AGE"}
|
2017-01-04 16:32:14 +00:00
|
|
|
deploymentWideColumns = []string{"CONTAINER(S)", "IMAGE(S)", "SELECTOR"}
|
2016-09-20 08:56:25 +00:00
|
|
|
configMapColumns = []string{"NAME", "DATA", "AGE"}
|
2016-11-14 02:29:37 +00:00
|
|
|
podSecurityPolicyColumns = []string{"NAME", "PRIV", "CAPS", "SELINUX", "RUNASUSER", "FSGROUP", "SUPGROUP", "READONLYROOTFS", "VOLUMES"}
|
2016-09-20 08:56:25 +00:00
|
|
|
clusterColumns = []string{"NAME", "STATUS", "AGE"}
|
|
|
|
networkPolicyColumns = []string{"NAME", "POD-SELECTOR", "AGE"}
|
|
|
|
certificateSigningRequestColumns = []string{"NAME", "AGE", "REQUESTOR", "CONDITION"}
|
2017-04-21 02:11:01 +00:00
|
|
|
podPresetColumns = []string{"NAME", "AGE"}
|
2016-09-20 08:56:25 +00:00
|
|
|
)
|
2014-10-06 01:24:19 +00:00
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printPod(pod *api.Pod, w io.Writer, options printers.PrintOptions) error {
|
2016-07-13 16:00:33 +00:00
|
|
|
if err := printPodBase(pod, w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printPodList(podList *api.PodList, w io.Writer, options printers.PrintOptions) error {
|
2016-07-13 16:00:33 +00:00
|
|
|
for _, pod := range podList.Items {
|
|
|
|
if err := printPodBase(&pod, w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
// AddHandlers adds print handlers for default Kubernetes types dealing with internal versions.
|
|
|
|
func AddHandlers(h *printers.HumanReadablePrinter) {
|
|
|
|
h.Handler(podColumns, podWideColumns, printPodList)
|
|
|
|
h.Handler(podColumns, podWideColumns, printPod)
|
2017-01-04 16:32:14 +00:00
|
|
|
h.Handler(podTemplateColumns, nil, printPodTemplate)
|
|
|
|
h.Handler(podTemplateColumns, nil, printPodTemplateList)
|
|
|
|
h.Handler(podDisruptionBudgetColumns, nil, printPodDisruptionBudget)
|
|
|
|
h.Handler(podDisruptionBudgetColumns, nil, printPodDisruptionBudgetList)
|
|
|
|
h.Handler(replicationControllerColumns, replicationControllerWideColumns, printReplicationController)
|
|
|
|
h.Handler(replicationControllerColumns, replicationControllerWideColumns, printReplicationControllerList)
|
|
|
|
h.Handler(replicaSetColumns, replicaSetWideColumns, printReplicaSet)
|
|
|
|
h.Handler(replicaSetColumns, replicaSetWideColumns, printReplicaSetList)
|
|
|
|
h.Handler(daemonSetColumns, daemonSetWideColumns, printDaemonSet)
|
|
|
|
h.Handler(daemonSetColumns, daemonSetWideColumns, printDaemonSetList)
|
|
|
|
h.Handler(jobColumns, batchJobWideColumns, printJob)
|
|
|
|
h.Handler(jobColumns, batchJobWideColumns, printJobList)
|
|
|
|
h.Handler(cronJobColumns, batchJobWideColumns, printCronJob)
|
|
|
|
h.Handler(cronJobColumns, batchJobWideColumns, printCronJobList)
|
|
|
|
h.Handler(serviceColumns, serviceWideColumns, printService)
|
|
|
|
h.Handler(serviceColumns, serviceWideColumns, printServiceList)
|
|
|
|
h.Handler(ingressColumns, nil, printIngress)
|
|
|
|
h.Handler(ingressColumns, nil, printIngressList)
|
|
|
|
h.Handler(statefulSetColumns, nil, printStatefulSet)
|
|
|
|
h.Handler(statefulSetColumns, nil, printStatefulSetList)
|
|
|
|
h.Handler(endpointColumns, nil, printEndpoints)
|
|
|
|
h.Handler(endpointColumns, nil, printEndpointsList)
|
|
|
|
h.Handler(nodeColumns, nodeWideColumns, printNode)
|
|
|
|
h.Handler(nodeColumns, nodeWideColumns, printNodeList)
|
|
|
|
h.Handler(eventColumns, nil, printEvent)
|
|
|
|
h.Handler(eventColumns, nil, printEventList)
|
|
|
|
h.Handler(limitRangeColumns, nil, printLimitRange)
|
|
|
|
h.Handler(limitRangeColumns, nil, printLimitRangeList)
|
|
|
|
h.Handler(resourceQuotaColumns, nil, printResourceQuota)
|
|
|
|
h.Handler(resourceQuotaColumns, nil, printResourceQuotaList)
|
|
|
|
h.Handler(namespaceColumns, nil, printNamespace)
|
|
|
|
h.Handler(namespaceColumns, nil, printNamespaceList)
|
|
|
|
h.Handler(secretColumns, nil, printSecret)
|
|
|
|
h.Handler(secretColumns, nil, printSecretList)
|
|
|
|
h.Handler(serviceAccountColumns, nil, printServiceAccount)
|
|
|
|
h.Handler(serviceAccountColumns, nil, printServiceAccountList)
|
|
|
|
h.Handler(persistentVolumeClaimColumns, nil, printPersistentVolumeClaim)
|
|
|
|
h.Handler(persistentVolumeClaimColumns, nil, printPersistentVolumeClaimList)
|
|
|
|
h.Handler(persistentVolumeColumns, nil, printPersistentVolume)
|
|
|
|
h.Handler(persistentVolumeColumns, nil, printPersistentVolumeList)
|
|
|
|
h.Handler(componentStatusColumns, nil, printComponentStatus)
|
|
|
|
h.Handler(componentStatusColumns, nil, printComponentStatusList)
|
|
|
|
h.Handler(thirdPartyResourceColumns, nil, printThirdPartyResource)
|
|
|
|
h.Handler(thirdPartyResourceColumns, nil, printThirdPartyResourceList)
|
|
|
|
h.Handler(deploymentColumns, deploymentWideColumns, printDeployment)
|
|
|
|
h.Handler(deploymentColumns, deploymentWideColumns, printDeploymentList)
|
|
|
|
h.Handler(horizontalPodAutoscalerColumns, nil, printHorizontalPodAutoscaler)
|
|
|
|
h.Handler(horizontalPodAutoscalerColumns, nil, printHorizontalPodAutoscalerList)
|
|
|
|
h.Handler(configMapColumns, nil, printConfigMap)
|
|
|
|
h.Handler(configMapColumns, nil, printConfigMapList)
|
|
|
|
h.Handler(podSecurityPolicyColumns, nil, printPodSecurityPolicy)
|
|
|
|
h.Handler(podSecurityPolicyColumns, nil, printPodSecurityPolicyList)
|
|
|
|
h.Handler(thirdPartyResourceDataColumns, nil, printThirdPartyResourceData)
|
|
|
|
h.Handler(thirdPartyResourceDataColumns, nil, printThirdPartyResourceDataList)
|
|
|
|
h.Handler(clusterColumns, nil, printCluster)
|
|
|
|
h.Handler(clusterColumns, nil, printClusterList)
|
2017-03-13 14:31:16 +00:00
|
|
|
h.Handler(networkPolicyColumns, nil, printExtensionsNetworkPolicy)
|
|
|
|
h.Handler(networkPolicyColumns, nil, printExtensionsNetworkPolicyList)
|
2017-01-04 16:32:14 +00:00
|
|
|
h.Handler(networkPolicyColumns, nil, printNetworkPolicy)
|
|
|
|
h.Handler(networkPolicyColumns, nil, printNetworkPolicyList)
|
|
|
|
h.Handler(roleColumns, nil, printRole)
|
|
|
|
h.Handler(roleColumns, nil, printRoleList)
|
|
|
|
h.Handler(roleBindingColumns, roleBindingWideColumns, printRoleBinding)
|
|
|
|
h.Handler(roleBindingColumns, roleBindingWideColumns, printRoleBindingList)
|
|
|
|
h.Handler(clusterRoleColumns, nil, printClusterRole)
|
|
|
|
h.Handler(clusterRoleColumns, nil, printClusterRoleList)
|
|
|
|
h.Handler(clusterRoleBindingColumns, clusterRoleBindingWideColumns, printClusterRoleBinding)
|
|
|
|
h.Handler(clusterRoleBindingColumns, clusterRoleBindingWideColumns, printClusterRoleBindingList)
|
|
|
|
h.Handler(certificateSigningRequestColumns, nil, printCertificateSigningRequest)
|
|
|
|
h.Handler(certificateSigningRequestColumns, nil, printCertificateSigningRequestList)
|
|
|
|
h.Handler(storageClassColumns, nil, printStorageClass)
|
|
|
|
h.Handler(storageClassColumns, nil, printStorageClassList)
|
2017-04-21 02:11:01 +00:00
|
|
|
h.Handler(podPresetColumns, nil, printPodPreset)
|
|
|
|
h.Handler(podPresetColumns, nil, printPodPresetList)
|
2017-01-04 16:32:14 +00:00
|
|
|
h.Handler(statusColumns, nil, printStatus)
|
2014-10-06 01:24:19 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 05:17:51 +00:00
|
|
|
// Pass ports=nil for all ports.
|
2015-09-09 17:45:01 +00:00
|
|
|
func formatEndpoints(endpoints *api.Endpoints, ports sets.String) string {
|
2015-03-20 21:24:43 +00:00
|
|
|
if len(endpoints.Subsets) == 0 {
|
2015-02-21 23:13:28 +00:00
|
|
|
return "<none>"
|
2015-02-05 23:45:53 +00:00
|
|
|
}
|
2015-02-19 03:54:15 +00:00
|
|
|
list := []string{}
|
2015-03-20 21:24:43 +00:00
|
|
|
max := 3
|
|
|
|
more := false
|
2015-05-25 09:44:56 +00:00
|
|
|
count := 0
|
2015-03-20 21:24:43 +00:00
|
|
|
for i := range endpoints.Subsets {
|
|
|
|
ss := &endpoints.Subsets[i]
|
|
|
|
for i := range ss.Ports {
|
|
|
|
port := &ss.Ports[i]
|
2015-04-28 05:17:51 +00:00
|
|
|
if ports == nil || ports.Has(port.Name) {
|
2015-03-20 21:24:43 +00:00
|
|
|
for i := range ss.Addresses {
|
|
|
|
if len(list) == max {
|
|
|
|
more = true
|
|
|
|
}
|
|
|
|
addr := &ss.Addresses[i]
|
2015-05-25 09:44:56 +00:00
|
|
|
if !more {
|
2017-02-21 14:21:00 +00:00
|
|
|
hostPort := net.JoinHostPort(addr.IP, strconv.Itoa(int(port.Port)))
|
|
|
|
list = append(list, hostPort)
|
2015-05-25 09:44:56 +00:00
|
|
|
}
|
|
|
|
count++
|
2015-03-20 21:24:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret := strings.Join(list, ",")
|
|
|
|
if more {
|
2015-05-25 09:44:56 +00:00
|
|
|
return fmt.Sprintf("%s + %d more...", ret, count-max)
|
2015-02-23 21:53:21 +00:00
|
|
|
}
|
2015-03-20 21:24:43 +00:00
|
|
|
return ret
|
2015-02-05 23:45:53 +00:00
|
|
|
}
|
|
|
|
|
2015-04-20 23:38:21 +00:00
|
|
|
// translateTimestamp returns the elapsed time since timestamp in
|
|
|
|
// human-readable approximation.
|
2016-12-03 18:57:26 +00:00
|
|
|
func translateTimestamp(timestamp metav1.Time) string {
|
2015-08-13 08:23:10 +00:00
|
|
|
if timestamp.IsZero() {
|
|
|
|
return "<unknown>"
|
|
|
|
}
|
2017-02-19 22:37:24 +00:00
|
|
|
return printers.ShortHumanDuration(time.Now().Sub(timestamp.Time))
|
2015-04-20 23:38:21 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printPodBase(pod *api.Pod, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, pod.Name, options.WithKind)
|
2015-07-01 20:56:31 +00:00
|
|
|
namespace := pod.Namespace
|
2015-05-20 19:51:35 +00:00
|
|
|
|
2015-05-30 01:42:44 +00:00
|
|
|
restarts := 0
|
|
|
|
totalContainers := len(pod.Spec.Containers)
|
|
|
|
readyContainers := 0
|
2015-06-09 15:58:16 +00:00
|
|
|
|
2015-05-30 01:42:44 +00:00
|
|
|
reason := string(pod.Status.Phase)
|
2015-06-09 15:58:16 +00:00
|
|
|
if pod.Status.Reason != "" {
|
|
|
|
reason = pod.Status.Reason
|
|
|
|
}
|
2015-05-30 01:42:44 +00:00
|
|
|
|
2016-05-02 22:08:15 +00:00
|
|
|
initializing := false
|
|
|
|
for i := range pod.Status.InitContainerStatuses {
|
|
|
|
container := pod.Status.InitContainerStatuses[i]
|
2016-06-14 12:33:51 +00:00
|
|
|
restarts += int(container.RestartCount)
|
2016-05-02 22:08:15 +00:00
|
|
|
switch {
|
|
|
|
case container.State.Terminated != nil && container.State.Terminated.ExitCode == 0:
|
|
|
|
continue
|
|
|
|
case container.State.Terminated != nil:
|
|
|
|
// initialization is failed
|
|
|
|
if len(container.State.Terminated.Reason) == 0 {
|
|
|
|
if container.State.Terminated.Signal != 0 {
|
|
|
|
reason = fmt.Sprintf("Init:Signal:%d", container.State.Terminated.Signal)
|
|
|
|
} else {
|
|
|
|
reason = fmt.Sprintf("Init:ExitCode:%d", container.State.Terminated.ExitCode)
|
|
|
|
}
|
2015-05-30 01:42:44 +00:00
|
|
|
} else {
|
2016-05-02 22:08:15 +00:00
|
|
|
reason = "Init:" + container.State.Terminated.Reason
|
|
|
|
}
|
|
|
|
initializing = true
|
|
|
|
case container.State.Waiting != nil && len(container.State.Waiting.Reason) > 0 && container.State.Waiting.Reason != "PodInitializing":
|
|
|
|
reason = "Init:" + container.State.Waiting.Reason
|
|
|
|
initializing = true
|
|
|
|
default:
|
|
|
|
reason = fmt.Sprintf("Init:%d/%d", i, len(pod.Spec.InitContainers))
|
|
|
|
initializing = true
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if !initializing {
|
2016-06-14 12:33:51 +00:00
|
|
|
restarts = 0
|
2016-05-02 22:08:15 +00:00
|
|
|
for i := len(pod.Status.ContainerStatuses) - 1; i >= 0; i-- {
|
|
|
|
container := pod.Status.ContainerStatuses[i]
|
|
|
|
|
|
|
|
restarts += int(container.RestartCount)
|
|
|
|
if container.State.Waiting != nil && container.State.Waiting.Reason != "" {
|
|
|
|
reason = container.State.Waiting.Reason
|
|
|
|
} else if container.State.Terminated != nil && container.State.Terminated.Reason != "" {
|
|
|
|
reason = container.State.Terminated.Reason
|
|
|
|
} else if container.State.Terminated != nil && container.State.Terminated.Reason == "" {
|
|
|
|
if container.State.Terminated.Signal != 0 {
|
|
|
|
reason = fmt.Sprintf("Signal:%d", container.State.Terminated.Signal)
|
|
|
|
} else {
|
|
|
|
reason = fmt.Sprintf("ExitCode:%d", container.State.Terminated.ExitCode)
|
|
|
|
}
|
|
|
|
} else if container.Ready && container.State.Running != nil {
|
|
|
|
readyContainers++
|
2015-04-20 23:38:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-01 19:59:06 +00:00
|
|
|
|
|
|
|
if pod.DeletionTimestamp != nil && pod.Status.Reason == node.NodeUnreachablePodReason {
|
|
|
|
reason = "Unknown"
|
|
|
|
} else if pod.DeletionTimestamp != nil {
|
2015-08-20 01:52:34 +00:00
|
|
|
reason = "Terminating"
|
|
|
|
}
|
2015-04-20 23:38:21 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-07-01 20:56:31 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2015-06-16 16:30:11 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%d/%d\t%s\t%d\t%s",
|
2015-05-30 01:42:44 +00:00
|
|
|
name,
|
|
|
|
readyContainers,
|
|
|
|
totalContainers,
|
|
|
|
reason,
|
|
|
|
restarts,
|
2015-06-16 16:30:11 +00:00
|
|
|
translateTimestamp(pod.CreationTimestamp),
|
|
|
|
); err != nil {
|
2015-05-30 01:42:44 +00:00
|
|
|
return err
|
2014-11-15 00:20:43 +00:00
|
|
|
}
|
2015-06-29 18:36:06 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.Wide {
|
2015-06-29 18:36:06 +00:00
|
|
|
nodeName := pod.Spec.NodeName
|
2016-05-12 04:30:25 +00:00
|
|
|
podIP := pod.Status.PodIP
|
|
|
|
if podIP == "" {
|
|
|
|
podIP = "<none>"
|
|
|
|
}
|
2017-05-10 04:53:14 +00:00
|
|
|
if nodeName == "" {
|
|
|
|
nodeName = "<none>"
|
|
|
|
}
|
2016-05-12 04:30:25 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "\t%s\t%s",
|
|
|
|
podIP,
|
2015-06-29 18:36:06 +00:00
|
|
|
nodeName,
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(pod.Labels, options.ColumnLabels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, pod.Labels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2014-10-06 01:24:19 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printPodTemplate(pod *api.PodTemplate, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, pod.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-07-22 22:01:59 +00:00
|
|
|
namespace := pod.Namespace
|
2015-05-20 19:51:35 +00:00
|
|
|
|
2015-03-04 15:46:27 +00:00
|
|
|
containers := pod.Template.Spec.Containers
|
2015-06-16 16:30:11 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-07-01 20:56:31 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-03-11 05:29:37 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s", name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := layoutContainers(containers, w); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := fmt.Fprintf(w, "\t%s", labels.FormatLabels(pod.Template.Labels)); err != nil {
|
2015-06-16 16:30:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(pod.Labels, options.ColumnLabels)); err != nil {
|
2015-03-04 00:54:17 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, pod.Labels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-06-16 16:30:11 +00:00
|
|
|
|
2015-03-04 00:54:17 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printPodTemplateList(podList *api.PodTemplateList, w io.Writer, options printers.PrintOptions) error {
|
2015-03-04 00:54:17 +00:00
|
|
|
for _, pod := range podList.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printPodTemplate(&pod, w, options); err != nil {
|
2015-03-04 00:54:17 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printPodDisruptionBudget(pdb *policy.PodDisruptionBudget, w io.Writer, options printers.PrintOptions) error {
|
2017-05-15 23:50:23 +00:00
|
|
|
// name, minavailable, maxUnavailable, selector
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, pdb.Name, options.WithKind)
|
2016-10-21 11:57:49 +00:00
|
|
|
namespace := pdb.Namespace
|
|
|
|
|
|
|
|
if options.WithNamespace {
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2017-05-15 23:50:23 +00:00
|
|
|
|
|
|
|
var minAvailable string
|
|
|
|
var maxUnavailable string
|
|
|
|
if pdb.Spec.MinAvailable != nil {
|
|
|
|
minAvailable = pdb.Spec.MinAvailable.String()
|
|
|
|
} else {
|
|
|
|
minAvailable = "N/A"
|
|
|
|
}
|
|
|
|
|
|
|
|
if pdb.Spec.MaxUnavailable != nil {
|
|
|
|
maxUnavailable = pdb.Spec.MaxUnavailable.String()
|
|
|
|
} else {
|
|
|
|
maxUnavailable = "N/A"
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\n",
|
2016-10-21 11:57:49 +00:00
|
|
|
name,
|
2017-05-15 23:50:23 +00:00
|
|
|
minAvailable,
|
|
|
|
maxUnavailable,
|
2016-11-09 12:39:16 +00:00
|
|
|
pdb.Status.PodDisruptionsAllowed,
|
|
|
|
translateTimestamp(pdb.CreationTimestamp),
|
2016-10-21 11:57:49 +00:00
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printPodDisruptionBudgetList(pdbList *policy.PodDisruptionBudgetList, w io.Writer, options printers.PrintOptions) error {
|
2016-10-21 11:57:49 +00:00
|
|
|
for _, pdb := range pdbList.Items {
|
|
|
|
if err := printPodDisruptionBudget(&pdb, w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-03-11 05:29:37 +00:00
|
|
|
// TODO(AdoHe): try to put wide output in a single method
|
2017-02-19 22:37:24 +00:00
|
|
|
func printReplicationController(controller *api.ReplicationController, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, controller.Name, options.WithKind)
|
2016-07-22 22:01:59 +00:00
|
|
|
|
2015-07-01 20:56:31 +00:00
|
|
|
namespace := controller.Namespace
|
2014-12-19 02:15:47 +00:00
|
|
|
containers := controller.Spec.Template.Spec.Containers
|
2015-06-16 16:30:11 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-07-01 20:56:31 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-02-23 15:11:19 +00:00
|
|
|
|
|
|
|
desiredReplicas := controller.Spec.Replicas
|
|
|
|
currentReplicas := controller.Status.Replicas
|
2016-08-18 09:35:18 +00:00
|
|
|
readyReplicas := controller.Status.ReadyReplicas
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%d\t%d\t%d\t%s",
|
2015-05-20 19:51:35 +00:00
|
|
|
name,
|
2016-02-23 15:11:19 +00:00
|
|
|
desiredReplicas,
|
|
|
|
currentReplicas,
|
2016-08-18 09:35:18 +00:00
|
|
|
readyReplicas,
|
2015-06-18 06:32:03 +00:00
|
|
|
translateTimestamp(controller.CreationTimestamp),
|
2015-06-16 16:30:11 +00:00
|
|
|
); err != nil {
|
2014-12-19 02:15:47 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-03-11 05:29:37 +00:00
|
|
|
|
2016-02-14 08:14:20 +00:00
|
|
|
if options.Wide {
|
2016-03-11 05:29:37 +00:00
|
|
|
if err := layoutContainers(containers, w); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := fmt.Fprintf(w, "\t%s", labels.FormatLabels(controller.Spec.Selector)); err != nil {
|
2016-02-14 08:14:20 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(controller.Labels, options.ColumnLabels)); err != nil {
|
2015-06-16 16:30:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, controller.Labels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-06-16 16:30:11 +00:00
|
|
|
|
2014-12-19 02:15:47 +00:00
|
|
|
return nil
|
2014-10-06 01:24:19 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printReplicationControllerList(list *api.ReplicationControllerList, w io.Writer, options printers.PrintOptions) error {
|
2014-10-22 17:02:02 +00:00
|
|
|
for _, controller := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printReplicationController(&controller, w, options); err != nil {
|
2014-10-06 01:24:19 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printReplicaSet(rs *extensions.ReplicaSet, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, rs.Name, options.WithKind)
|
2016-07-22 22:01:59 +00:00
|
|
|
|
2016-02-09 05:23:56 +00:00
|
|
|
namespace := rs.Namespace
|
|
|
|
containers := rs.Spec.Template.Spec.Containers
|
|
|
|
|
|
|
|
if options.WithNamespace {
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-02-23 15:11:19 +00:00
|
|
|
|
|
|
|
desiredReplicas := rs.Spec.Replicas
|
|
|
|
currentReplicas := rs.Status.Replicas
|
2016-08-18 09:35:18 +00:00
|
|
|
readyReplicas := rs.Status.ReadyReplicas
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%d\t%d\t%d\t%s",
|
2016-02-09 05:23:56 +00:00
|
|
|
name,
|
2016-02-23 15:11:19 +00:00
|
|
|
desiredReplicas,
|
|
|
|
currentReplicas,
|
2016-08-18 09:35:18 +00:00
|
|
|
readyReplicas,
|
2016-02-09 05:23:56 +00:00
|
|
|
translateTimestamp(rs.CreationTimestamp),
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-02-14 08:14:20 +00:00
|
|
|
if options.Wide {
|
2016-03-11 05:29:37 +00:00
|
|
|
if err := layoutContainers(containers, w); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-12-03 18:57:26 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "\t%s", metav1.FormatLabelSelector(rs.Spec.Selector)); err != nil {
|
2016-02-14 08:14:20 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(rs.Labels, options.ColumnLabels)); err != nil {
|
2016-02-09 05:23:56 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, rs.Labels)); err != nil {
|
2016-02-09 05:23:56 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printReplicaSetList(list *extensions.ReplicaSetList, w io.Writer, options printers.PrintOptions) error {
|
2016-02-09 05:23:56 +00:00
|
|
|
for _, rs := range list.Items {
|
|
|
|
if err := printReplicaSet(&rs, w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printCluster(c *federation.Cluster, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, c.Name, options.WithKind)
|
2016-07-22 22:01:59 +00:00
|
|
|
|
2016-04-26 14:33:47 +00:00
|
|
|
var statuses []string
|
|
|
|
for _, condition := range c.Status.Conditions {
|
|
|
|
if condition.Status == api.ConditionTrue {
|
|
|
|
statuses = append(statuses, string(condition.Type))
|
|
|
|
} else {
|
|
|
|
statuses = append(statuses, "Not"+string(condition.Type))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(statuses) == 0 {
|
|
|
|
statuses = append(statuses, "Unknown")
|
|
|
|
}
|
|
|
|
|
2016-06-28 20:37:03 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\n",
|
2016-06-29 22:02:08 +00:00
|
|
|
name,
|
2016-04-26 14:33:47 +00:00
|
|
|
strings.Join(statuses, ","),
|
|
|
|
translateTimestamp(c.CreationTimestamp),
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2017-02-19 22:37:24 +00:00
|
|
|
func printClusterList(list *federation.ClusterList, w io.Writer, options printers.PrintOptions) error {
|
2016-04-26 14:33:47 +00:00
|
|
|
for _, rs := range list.Items {
|
|
|
|
if err := printCluster(&rs, w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printJob(job *batch.Job, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, job.Name, options.WithKind)
|
2016-07-22 22:01:59 +00:00
|
|
|
|
2015-09-26 04:45:18 +00:00
|
|
|
namespace := job.Namespace
|
2015-08-21 14:23:12 +00:00
|
|
|
containers := job.Spec.Template.Spec.Containers
|
2016-03-11 05:29:37 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-09-26 04:45:18 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-08-21 14:23:12 +00:00
|
|
|
}
|
2015-10-14 18:04:33 +00:00
|
|
|
|
2016-12-03 18:57:26 +00:00
|
|
|
selector, err := metav1.LabelSelectorAsSelector(job.Spec.Selector)
|
2016-03-11 05:29:37 +00:00
|
|
|
if err != nil {
|
|
|
|
// this shouldn't happen if LabelSelector passed validation
|
|
|
|
return err
|
|
|
|
}
|
2016-02-25 15:43:04 +00:00
|
|
|
if job.Spec.Completions != nil {
|
2016-02-28 05:59:01 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%d\t%d\t%s",
|
2016-02-25 15:43:04 +00:00
|
|
|
name,
|
|
|
|
*job.Spec.Completions,
|
|
|
|
job.Status.Succeeded,
|
2016-02-28 05:59:01 +00:00
|
|
|
translateTimestamp(job.CreationTimestamp),
|
2016-02-25 15:43:04 +00:00
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2016-02-28 05:59:01 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%d\t%s",
|
2016-02-25 15:43:04 +00:00
|
|
|
name,
|
|
|
|
"<none>",
|
|
|
|
job.Status.Succeeded,
|
2016-02-28 05:59:01 +00:00
|
|
|
translateTimestamp(job.CreationTimestamp),
|
2016-02-25 15:43:04 +00:00
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-08-21 14:23:12 +00:00
|
|
|
}
|
2016-02-14 08:14:20 +00:00
|
|
|
if options.Wide {
|
2016-03-11 05:29:37 +00:00
|
|
|
if err := layoutContainers(containers, w); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := fmt.Fprintf(w, "\t%s", selector.String()); err != nil {
|
2016-02-14 08:14:20 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(job.Labels, options.ColumnLabels)); err != nil {
|
2015-09-26 04:45:18 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, job.Labels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-09-26 04:45:18 +00:00
|
|
|
|
2015-08-21 14:23:12 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printJobList(list *batch.JobList, w io.Writer, options printers.PrintOptions) error {
|
2015-08-21 14:23:12 +00:00
|
|
|
for _, job := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printJob(&job, w, options); err != nil {
|
2015-08-21 14:23:12 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printCronJob(cronJob *batch.CronJob, w io.Writer, options printers.PrintOptions) error {
|
2016-11-01 22:46:23 +00:00
|
|
|
name := cronJob.Name
|
|
|
|
namespace := cronJob.Namespace
|
2016-05-18 08:11:35 +00:00
|
|
|
|
|
|
|
if options.WithNamespace {
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lastScheduleTime := "<none>"
|
2016-11-01 22:46:23 +00:00
|
|
|
if cronJob.Status.LastScheduleTime != nil {
|
|
|
|
lastScheduleTime = cronJob.Status.LastScheduleTime.Time.Format(time.RFC1123Z)
|
2016-05-18 08:11:35 +00:00
|
|
|
}
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\n",
|
|
|
|
name,
|
2016-11-01 22:46:23 +00:00
|
|
|
cronJob.Spec.Schedule,
|
|
|
|
printBoolPtr(cronJob.Spec.Suspend),
|
|
|
|
len(cronJob.Status.Active),
|
2016-05-18 08:11:35 +00:00
|
|
|
lastScheduleTime,
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printCronJobList(list *batch.CronJobList, w io.Writer, options printers.PrintOptions) error {
|
2016-11-01 22:46:23 +00:00
|
|
|
for _, cronJob := range list.Items {
|
|
|
|
if err := printCronJob(&cronJob, w, options); err != nil {
|
2016-05-18 08:11:35 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-06-02 23:09:51 +00:00
|
|
|
// loadBalancerStatusStringer behaves mostly like a string interface and converts the given status to a string.
|
|
|
|
// `wide` indicates whether the returned value is meant for --o=wide output. If not, it's clipped to 16 bytes.
|
|
|
|
func loadBalancerStatusStringer(s api.LoadBalancerStatus, wide bool) string {
|
2015-09-23 21:50:59 +00:00
|
|
|
ingress := s.Ingress
|
|
|
|
result := []string{}
|
|
|
|
for i := range ingress {
|
|
|
|
if ingress[i].IP != "" {
|
|
|
|
result = append(result, ingress[i].IP)
|
2016-06-02 23:09:51 +00:00
|
|
|
} else if ingress[i].Hostname != "" {
|
|
|
|
result = append(result, ingress[i].Hostname)
|
2015-09-23 21:50:59 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-02 23:09:51 +00:00
|
|
|
r := strings.Join(result, ",")
|
|
|
|
if !wide && len(r) > loadBalancerWidth {
|
|
|
|
r = r[0:(loadBalancerWidth-3)] + "..."
|
|
|
|
}
|
|
|
|
return r
|
2015-09-23 21:50:59 +00:00
|
|
|
}
|
|
|
|
|
2016-06-02 23:09:51 +00:00
|
|
|
func getServiceExternalIP(svc *api.Service, wide bool) string {
|
2015-08-08 04:08:43 +00:00
|
|
|
switch svc.Spec.Type {
|
|
|
|
case api.ServiceTypeClusterIP:
|
2015-08-12 00:18:21 +00:00
|
|
|
if len(svc.Spec.ExternalIPs) > 0 {
|
|
|
|
return strings.Join(svc.Spec.ExternalIPs, ",")
|
|
|
|
}
|
2015-08-08 04:08:43 +00:00
|
|
|
return "<none>"
|
|
|
|
case api.ServiceTypeNodePort:
|
2015-08-12 00:18:21 +00:00
|
|
|
if len(svc.Spec.ExternalIPs) > 0 {
|
|
|
|
return strings.Join(svc.Spec.ExternalIPs, ",")
|
|
|
|
}
|
2016-04-21 07:35:32 +00:00
|
|
|
return "<nodes>"
|
2015-08-08 04:08:43 +00:00
|
|
|
case api.ServiceTypeLoadBalancer:
|
2016-06-02 23:09:51 +00:00
|
|
|
lbIps := loadBalancerStatusStringer(svc.Status.LoadBalancer, wide)
|
2015-08-12 00:18:21 +00:00
|
|
|
if len(svc.Spec.ExternalIPs) > 0 {
|
2015-09-23 21:50:59 +00:00
|
|
|
result := append(strings.Split(lbIps, ","), svc.Spec.ExternalIPs...)
|
|
|
|
return strings.Join(result, ",")
|
2015-08-12 00:18:21 +00:00
|
|
|
}
|
2016-04-21 07:35:32 +00:00
|
|
|
if len(lbIps) > 0 {
|
|
|
|
return lbIps
|
|
|
|
}
|
|
|
|
return "<pending>"
|
2016-08-23 13:51:17 +00:00
|
|
|
case api.ServiceTypeExternalName:
|
|
|
|
return svc.Spec.ExternalName
|
2015-08-08 04:08:43 +00:00
|
|
|
}
|
2016-04-21 07:35:32 +00:00
|
|
|
return "<unknown>"
|
2015-08-08 04:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func makePortString(ports []api.ServicePort) string {
|
|
|
|
pieces := make([]string, len(ports))
|
|
|
|
for ix := range ports {
|
|
|
|
port := &ports[ix]
|
|
|
|
pieces[ix] = fmt.Sprintf("%d/%s", port.Port, port.Protocol)
|
2016-10-17 05:48:56 +00:00
|
|
|
if port.NodePort > 0 {
|
|
|
|
pieces[ix] = fmt.Sprintf("%d:%d/%s", port.Port, port.NodePort, port.Protocol)
|
|
|
|
}
|
2015-08-08 04:08:43 +00:00
|
|
|
}
|
|
|
|
return strings.Join(pieces, ",")
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printService(svc *api.Service, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, svc.Name, options.WithKind)
|
2016-07-22 22:01:59 +00:00
|
|
|
|
2015-07-01 20:56:31 +00:00
|
|
|
namespace := svc.Namespace
|
2015-05-20 19:51:35 +00:00
|
|
|
|
2015-08-08 04:08:43 +00:00
|
|
|
internalIP := svc.Spec.ClusterIP
|
2016-06-02 23:09:51 +00:00
|
|
|
externalIP := getServiceExternalIP(svc, options.Wide)
|
2015-05-20 19:51:35 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-07-01 20:56:31 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-02-14 08:14:20 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s",
|
2015-06-18 06:32:03 +00:00
|
|
|
name,
|
2015-08-08 04:08:43 +00:00
|
|
|
internalIP,
|
|
|
|
externalIP,
|
|
|
|
makePortString(svc.Spec.Ports),
|
2015-06-18 06:32:03 +00:00
|
|
|
translateTimestamp(svc.CreationTimestamp),
|
|
|
|
); err != nil {
|
2015-03-13 15:16:41 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-02-14 08:14:20 +00:00
|
|
|
if options.Wide {
|
|
|
|
if _, err := fmt.Fprintf(w, "\t%s", labels.FormatLabels(svc.Spec.Selector)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(svc.Labels, options.ColumnLabels)); err != nil {
|
2015-06-16 16:30:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, svc.Labels))
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
2014-10-06 01:24:19 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printServiceList(list *api.ServiceList, w io.Writer, options printers.PrintOptions) error {
|
2014-10-06 01:24:19 +00:00
|
|
|
for _, svc := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printService(&svc, w, options); err != nil {
|
2014-10-06 01:24:19 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-23 21:50:59 +00:00
|
|
|
// backendStringer behaves just like a string interface and converts the given backend to a string.
|
2015-10-09 22:49:10 +00:00
|
|
|
func backendStringer(backend *extensions.IngressBackend) string {
|
2015-09-23 21:50:59 +00:00
|
|
|
if backend == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%v:%v", backend.ServiceName, backend.ServicePort.String())
|
|
|
|
}
|
|
|
|
|
2016-06-05 02:43:51 +00:00
|
|
|
func formatHosts(rules []extensions.IngressRule) string {
|
|
|
|
list := []string{}
|
|
|
|
max := 3
|
|
|
|
more := false
|
|
|
|
for _, rule := range rules {
|
|
|
|
if len(list) == max {
|
|
|
|
more = true
|
|
|
|
}
|
|
|
|
if !more && len(rule.Host) != 0 {
|
|
|
|
list = append(list, rule.Host)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(list) == 0 {
|
|
|
|
return "*"
|
|
|
|
}
|
|
|
|
ret := strings.Join(list, ",")
|
|
|
|
if more {
|
|
|
|
return fmt.Sprintf("%s + %d more...", ret, len(rules)-max)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func formatPorts(tls []extensions.IngressTLS) string {
|
|
|
|
if len(tls) != 0 {
|
|
|
|
return "80, 443"
|
|
|
|
}
|
|
|
|
return "80"
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printIngress(ingress *extensions.Ingress, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, ingress.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-07-22 22:01:59 +00:00
|
|
|
namespace := ingress.Namespace
|
2015-09-23 21:50:59 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-09-23 21:50:59 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-28 05:59:01 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%v\t%v\t%v\t%s",
|
2015-09-23 21:50:59 +00:00
|
|
|
name,
|
2016-06-05 02:43:51 +00:00
|
|
|
formatHosts(ingress.Spec.Rules),
|
2016-06-02 23:09:51 +00:00
|
|
|
loadBalancerStatusStringer(ingress.Status.LoadBalancer, options.Wide),
|
2016-06-05 02:43:51 +00:00
|
|
|
formatPorts(ingress.Spec.TLS),
|
2016-02-28 05:59:01 +00:00
|
|
|
translateTimestamp(ingress.CreationTimestamp),
|
|
|
|
); err != nil {
|
2015-09-23 21:50:59 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(ingress.Labels, options.ColumnLabels)); err != nil {
|
2016-02-14 09:28:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-09-23 21:50:59 +00:00
|
|
|
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, ingress.Labels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-09-23 21:50:59 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printIngressList(ingressList *extensions.IngressList, w io.Writer, options printers.PrintOptions) error {
|
2015-09-23 21:50:59 +00:00
|
|
|
for _, ingress := range ingressList.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printIngress(&ingress, w, options); err != nil {
|
2015-09-23 21:50:59 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printStatefulSet(ps *apps.StatefulSet, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, ps.Name, options.WithKind)
|
2016-07-22 22:01:59 +00:00
|
|
|
|
2016-04-15 22:30:15 +00:00
|
|
|
namespace := ps.Namespace
|
|
|
|
containers := ps.Spec.Template.Spec.Containers
|
|
|
|
|
|
|
|
if options.WithNamespace {
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
desiredReplicas := ps.Spec.Replicas
|
|
|
|
currentReplicas := ps.Status.Replicas
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%d\t%d\t%s",
|
|
|
|
name,
|
|
|
|
desiredReplicas,
|
|
|
|
currentReplicas,
|
|
|
|
translateTimestamp(ps.CreationTimestamp),
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if options.Wide {
|
|
|
|
if err := layoutContainers(containers, w); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-12-03 18:57:26 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "\t%s", metav1.FormatLabelSelector(ps.Spec.Selector)); err != nil {
|
2016-04-15 22:30:15 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(ps.Labels, options.ColumnLabels)); err != nil {
|
2016-04-15 22:30:15 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, ps.Labels)); err != nil {
|
2016-04-15 22:30:15 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printStatefulSetList(statefulSetList *apps.StatefulSetList, w io.Writer, options printers.PrintOptions) error {
|
2016-10-26 20:44:07 +00:00
|
|
|
for _, ps := range statefulSetList.Items {
|
|
|
|
if err := printStatefulSet(&ps, w, options); err != nil {
|
2016-04-15 22:30:15 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printDaemonSet(ds *extensions.DaemonSet, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, ds.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-07-22 22:01:59 +00:00
|
|
|
namespace := ds.Namespace
|
2015-08-27 17:18:16 +00:00
|
|
|
|
2015-09-12 16:46:10 +00:00
|
|
|
containers := ds.Spec.Template.Spec.Containers
|
2015-08-27 17:18:16 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-08-27 17:18:16 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-02-23 15:11:19 +00:00
|
|
|
|
|
|
|
desiredScheduled := ds.Status.DesiredNumberScheduled
|
|
|
|
currentScheduled := ds.Status.CurrentNumberScheduled
|
2016-10-05 07:16:41 +00:00
|
|
|
numberReady := ds.Status.NumberReady
|
2017-03-09 21:24:07 +00:00
|
|
|
numberUpdated := ds.Status.UpdatedNumberScheduled
|
|
|
|
numberAvailable := ds.Status.NumberAvailable
|
2016-12-03 18:57:26 +00:00
|
|
|
selector, err := metav1.LabelSelectorAsSelector(ds.Spec.Selector)
|
2015-10-26 06:11:09 +00:00
|
|
|
if err != nil {
|
2015-12-01 09:24:21 +00:00
|
|
|
// this shouldn't happen if LabelSelector passed validation
|
2015-10-26 06:11:09 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-09 21:24:07 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%d\t%d\t%d\t%d\t%d\t%s\t%s",
|
2015-08-27 17:18:16 +00:00
|
|
|
name,
|
2016-02-23 15:11:19 +00:00
|
|
|
desiredScheduled,
|
|
|
|
currentScheduled,
|
2016-10-05 07:16:41 +00:00
|
|
|
numberReady,
|
2017-03-09 21:24:07 +00:00
|
|
|
numberUpdated,
|
|
|
|
numberAvailable,
|
2015-09-12 16:46:10 +00:00
|
|
|
labels.FormatLabels(ds.Spec.Template.Spec.NodeSelector),
|
2016-02-28 05:59:01 +00:00
|
|
|
translateTimestamp(ds.CreationTimestamp),
|
2015-08-27 17:18:16 +00:00
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-02-14 08:14:20 +00:00
|
|
|
if options.Wide {
|
2016-03-11 05:29:37 +00:00
|
|
|
if err := layoutContainers(containers, w); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := fmt.Fprintf(w, "\t%s", selector.String()); err != nil {
|
2016-02-14 08:14:20 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(ds.Labels, options.ColumnLabels)); err != nil {
|
2015-08-27 17:18:16 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, ds.Labels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-08-27 17:18:16 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printDaemonSetList(list *extensions.DaemonSetList, w io.Writer, options printers.PrintOptions) error {
|
2015-09-12 16:46:10 +00:00
|
|
|
for _, ds := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printDaemonSet(&ds, w, options); err != nil {
|
2015-08-27 17:18:16 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printEndpoints(endpoints *api.Endpoints, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, endpoints.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-07-22 22:01:59 +00:00
|
|
|
namespace := endpoints.Namespace
|
2015-07-01 20:56:31 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-07-01 20:56:31 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-05-20 19:51:35 +00:00
|
|
|
}
|
2015-06-18 06:32:03 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%s", name, formatEndpoints(endpoints, nil), translateTimestamp(endpoints.CreationTimestamp)); err != nil {
|
2015-06-16 16:30:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(endpoints.Labels, options.ColumnLabels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, endpoints.Labels))
|
2015-02-05 23:45:53 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printEndpointsList(list *api.EndpointsList, w io.Writer, options printers.PrintOptions) error {
|
2015-02-24 02:20:10 +00:00
|
|
|
for _, item := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printEndpoints(&item, w, options); err != nil {
|
2015-02-24 02:20:10 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printNamespace(item *api.Namespace, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, item.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-07-01 20:41:54 +00:00
|
|
|
return fmt.Errorf("namespace is not namespaced")
|
|
|
|
}
|
2015-06-18 06:32:03 +00:00
|
|
|
|
2016-06-29 22:02:08 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%s", name, item.Status.Phase, translateTimestamp(item.CreationTimestamp)); err != nil {
|
2015-06-16 16:30:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(item.Labels, options.ColumnLabels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, item.Labels))
|
2015-01-19 21:50:00 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printNamespaceList(list *api.NamespaceList, w io.Writer, options printers.PrintOptions) error {
|
2015-01-19 21:50:00 +00:00
|
|
|
for _, item := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printNamespace(&item, w, options); err != nil {
|
2015-01-19 21:50:00 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printSecret(item *api.Secret, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, item.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-07-22 22:01:59 +00:00
|
|
|
namespace := item.Namespace
|
2015-07-01 20:56:31 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-07-01 20:56:31 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-05-20 19:51:35 +00:00
|
|
|
}
|
2015-06-18 06:32:03 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%v\t%s", name, item.Type, len(item.Data), translateTimestamp(item.CreationTimestamp)); err != nil {
|
2015-06-16 16:30:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(item.Labels, options.ColumnLabels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, item.Labels))
|
2015-02-18 01:24:50 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printSecretList(list *api.SecretList, w io.Writer, options printers.PrintOptions) error {
|
2015-02-18 01:24:50 +00:00
|
|
|
for _, item := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printSecret(&item, w, options); err != nil {
|
2015-02-18 01:24:50 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printServiceAccount(item *api.ServiceAccount, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, item.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-07-22 22:01:59 +00:00
|
|
|
namespace := item.Namespace
|
2015-07-01 20:56:31 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-07-01 20:56:31 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-05-20 19:51:35 +00:00
|
|
|
}
|
2015-06-18 06:32:03 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%d\t%s", name, len(item.Secrets), translateTimestamp(item.CreationTimestamp)); err != nil {
|
2015-06-16 16:30:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(item.Labels, options.ColumnLabels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, item.Labels))
|
2015-04-27 22:53:28 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printServiceAccountList(list *api.ServiceAccountList, w io.Writer, options printers.PrintOptions) error {
|
2015-04-27 22:53:28 +00:00
|
|
|
for _, item := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printServiceAccount(&item, w, options); err != nil {
|
2015-04-27 22:53:28 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printNode(node *api.Node, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, node.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-07-01 20:41:54 +00:00
|
|
|
return fmt.Errorf("node is not namespaced")
|
|
|
|
}
|
2015-02-24 05:21:14 +00:00
|
|
|
conditionMap := make(map[api.NodeConditionType]*api.NodeCondition)
|
2015-04-03 13:43:51 +00:00
|
|
|
NodeAllConditions := []api.NodeConditionType{api.NodeReady}
|
2015-02-21 17:07:09 +00:00
|
|
|
for i := range node.Status.Conditions {
|
|
|
|
cond := node.Status.Conditions[i]
|
2015-02-24 05:21:14 +00:00
|
|
|
conditionMap[cond.Type] = &cond
|
2015-01-15 01:11:34 +00:00
|
|
|
}
|
|
|
|
var status []string
|
|
|
|
for _, validCondition := range NodeAllConditions {
|
|
|
|
if condition, ok := conditionMap[validCondition]; ok {
|
2015-03-23 18:33:55 +00:00
|
|
|
if condition.Status == api.ConditionTrue {
|
2015-02-24 05:21:14 +00:00
|
|
|
status = append(status, string(condition.Type))
|
2015-01-15 01:11:34 +00:00
|
|
|
} else {
|
2015-02-24 05:21:14 +00:00
|
|
|
status = append(status, "Not"+string(condition.Type))
|
2015-01-15 01:11:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(status) == 0 {
|
|
|
|
status = append(status, "Unknown")
|
|
|
|
}
|
2015-04-16 01:53:03 +00:00
|
|
|
if node.Spec.Unschedulable {
|
|
|
|
status = append(status, "SchedulingDisabled")
|
|
|
|
}
|
2016-10-31 13:55:37 +00:00
|
|
|
role := findNodeRole(node)
|
|
|
|
if role != "" {
|
|
|
|
status = append(status, role)
|
|
|
|
}
|
2015-06-16 16:30:11 +00:00
|
|
|
|
2016-12-02 11:53:48 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s", name, strings.Join(status, ","), translateTimestamp(node.CreationTimestamp), node.Status.NodeInfo.KubeletVersion); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-09-27 10:31:37 +00:00
|
|
|
|
|
|
|
if options.Wide {
|
2016-12-16 05:42:59 +00:00
|
|
|
osImage, kernelVersion := node.Status.NodeInfo.OSImage, node.Status.NodeInfo.KernelVersion
|
|
|
|
if osImage == "" {
|
|
|
|
osImage = "<unknown>"
|
|
|
|
}
|
|
|
|
if kernelVersion == "" {
|
|
|
|
kernelVersion = "<unknown>"
|
|
|
|
}
|
|
|
|
if _, err := fmt.Fprintf(w, "\t%s\t%s\t%s", getNodeExternalIP(node), osImage, kernelVersion); err != nil {
|
2016-09-27 10:31:37 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-02-04 07:08:44 +00:00
|
|
|
// Display caller specify column labels first.
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(node.Labels, options.ColumnLabels)); err != nil {
|
2015-06-16 16:30:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, node.Labels))
|
2014-10-06 01:24:19 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-09-27 10:31:37 +00:00
|
|
|
// Returns first external ip of the node or "<none>" if none is found.
|
|
|
|
func getNodeExternalIP(node *api.Node) string {
|
|
|
|
for _, address := range node.Status.Addresses {
|
|
|
|
if address.Type == api.NodeExternalIP {
|
|
|
|
return address.Address
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "<none>"
|
|
|
|
}
|
|
|
|
|
2016-10-31 13:55:37 +00:00
|
|
|
// findNodeRole returns the role of a given node, or "" if none found.
|
|
|
|
// The role is determined by looking in order for:
|
|
|
|
// * a kubernetes.io/role label
|
|
|
|
// * a kubeadm.alpha.kubernetes.io/role label
|
|
|
|
// If no role is found, ("", nil) is returned
|
|
|
|
func findNodeRole(node *api.Node) string {
|
2016-12-03 18:57:26 +00:00
|
|
|
if role := node.Labels[metav1.NodeLabelRole]; role != "" {
|
2016-10-31 13:55:37 +00:00
|
|
|
return role
|
|
|
|
}
|
2016-12-03 18:57:26 +00:00
|
|
|
if role := node.Labels[metav1.NodeLabelKubeadmAlphaRole]; role != "" {
|
2016-10-31 13:55:37 +00:00
|
|
|
return role
|
|
|
|
}
|
|
|
|
// No role found
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printNodeList(list *api.NodeList, w io.Writer, options printers.PrintOptions) error {
|
2015-02-21 17:07:09 +00:00
|
|
|
for _, node := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printNode(&node, w, options); err != nil {
|
2014-10-06 01:24:19 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printPersistentVolume(pv *api.PersistentVolume, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, pv.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-07-01 20:56:31 +00:00
|
|
|
return fmt.Errorf("persistentVolume is not namespaced")
|
2015-05-20 19:51:35 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 19:50:36 +00:00
|
|
|
claimRefUID := ""
|
|
|
|
if pv.Spec.ClaimRef != nil {
|
2015-05-13 00:44:29 +00:00
|
|
|
claimRefUID += pv.Spec.ClaimRef.Namespace
|
|
|
|
claimRefUID += "/"
|
2015-03-26 19:50:36 +00:00
|
|
|
claimRefUID += pv.Spec.ClaimRef.Name
|
|
|
|
}
|
|
|
|
|
2017-04-10 17:49:54 +00:00
|
|
|
modesStr := helper.GetAccessModesAsString(pv.Spec.AccessModes)
|
2016-08-24 18:00:29 +00:00
|
|
|
reclaimPolicyStr := string(pv.Spec.PersistentVolumeReclaimPolicy)
|
2015-03-26 19:50:36 +00:00
|
|
|
|
|
|
|
aQty := pv.Spec.Capacity[api.ResourceStorage]
|
2015-08-11 03:55:15 +00:00
|
|
|
aSize := aQty.String()
|
2015-03-26 19:50:36 +00:00
|
|
|
|
2017-01-06 17:41:04 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
|
2015-06-18 06:32:03 +00:00
|
|
|
name,
|
2016-08-24 18:00:29 +00:00
|
|
|
aSize, modesStr, reclaimPolicyStr,
|
2015-06-18 06:32:03 +00:00
|
|
|
pv.Status.Phase,
|
|
|
|
claimRefUID,
|
2017-04-10 17:49:54 +00:00
|
|
|
helper.GetPersistentVolumeClass(pv),
|
2015-06-18 06:32:03 +00:00
|
|
|
pv.Status.Reason,
|
|
|
|
translateTimestamp(pv.CreationTimestamp),
|
|
|
|
); err != nil {
|
2015-06-16 16:30:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(pv.Labels, options.ColumnLabels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, pv.Labels))
|
2015-03-26 19:50:36 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printPersistentVolumeList(list *api.PersistentVolumeList, w io.Writer, options printers.PrintOptions) error {
|
2015-03-26 19:50:36 +00:00
|
|
|
for _, pv := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printPersistentVolume(&pv, w, options); err != nil {
|
2015-03-26 19:50:36 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printPersistentVolumeClaim(pvc *api.PersistentVolumeClaim, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, pvc.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-07-22 22:01:59 +00:00
|
|
|
namespace := pvc.Namespace
|
2015-07-01 20:56:31 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-07-01 20:56:31 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-05-20 19:51:35 +00:00
|
|
|
}
|
|
|
|
|
2015-08-11 03:55:15 +00:00
|
|
|
phase := pvc.Status.Phase
|
|
|
|
storage := pvc.Spec.Resources.Requests[api.ResourceStorage]
|
|
|
|
capacity := ""
|
|
|
|
accessModes := ""
|
|
|
|
if pvc.Spec.VolumeName != "" {
|
2017-04-10 17:49:54 +00:00
|
|
|
accessModes = helper.GetAccessModesAsString(pvc.Status.AccessModes)
|
2015-08-11 03:55:15 +00:00
|
|
|
storage = pvc.Status.Capacity[api.ResourceStorage]
|
|
|
|
capacity = storage.String()
|
2015-07-01 20:56:31 +00:00
|
|
|
}
|
2015-06-18 06:32:03 +00:00
|
|
|
|
2017-04-10 17:49:54 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s", name, phase, pvc.Spec.VolumeName, capacity, accessModes, helper.GetPersistentVolumeClaimClass(pvc), translateTimestamp(pvc.CreationTimestamp)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(pvc.Labels, options.ColumnLabels)); err != nil {
|
2015-06-16 16:30:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, pvc.Labels))
|
2015-03-26 19:50:36 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printPersistentVolumeClaimList(list *api.PersistentVolumeClaimList, w io.Writer, options printers.PrintOptions) error {
|
2015-03-26 19:50:36 +00:00
|
|
|
for _, psd := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printPersistentVolumeClaim(&psd, w, options); err != nil {
|
2015-03-26 19:50:36 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printEvent(event *api.Event, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, event.InvolvedObject.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-07-22 22:01:59 +00:00
|
|
|
namespace := event.Namespace
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-07-01 20:56:31 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-07-01 20:41:54 +00:00
|
|
|
}
|
2015-11-10 11:34:28 +00:00
|
|
|
|
|
|
|
// While watching event, we should print absolute time.
|
|
|
|
var FirstTimestamp, LastTimestamp string
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.AbsoluteTimestamps {
|
2015-11-10 11:34:28 +00:00
|
|
|
FirstTimestamp = event.FirstTimestamp.String()
|
|
|
|
LastTimestamp = event.LastTimestamp.String()
|
|
|
|
} else {
|
|
|
|
FirstTimestamp = translateTimestamp(event.FirstTimestamp)
|
|
|
|
LastTimestamp = translateTimestamp(event.LastTimestamp)
|
|
|
|
}
|
|
|
|
|
2015-06-16 16:30:11 +00:00
|
|
|
if _, err := fmt.Fprintf(
|
2015-11-13 22:30:01 +00:00
|
|
|
w, "%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
|
2015-11-10 11:34:28 +00:00
|
|
|
LastTimestamp,
|
2016-06-15 14:48:36 +00:00
|
|
|
FirstTimestamp,
|
2015-02-11 00:49:32 +00:00
|
|
|
event.Count,
|
2016-06-29 22:02:08 +00:00
|
|
|
name,
|
2014-11-04 02:02:27 +00:00
|
|
|
event.InvolvedObject.Kind,
|
2014-12-30 01:10:38 +00:00
|
|
|
event.InvolvedObject.FieldPath,
|
2015-11-13 22:30:01 +00:00
|
|
|
event.Type,
|
2014-11-04 02:02:27 +00:00
|
|
|
event.Reason,
|
2017-01-18 10:28:25 +00:00
|
|
|
formatEventSource(event.Source),
|
2014-11-04 02:02:27 +00:00
|
|
|
event.Message,
|
2015-06-16 16:30:11 +00:00
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(event.Labels, options.ColumnLabels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, event.Labels))
|
2014-11-04 02:02:27 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-12-16 22:20:51 +00:00
|
|
|
// Sorts and prints the EventList in a human-friendly format.
|
2017-02-19 22:37:24 +00:00
|
|
|
func printEventList(list *api.EventList, w io.Writer, options printers.PrintOptions) error {
|
2016-09-15 15:56:40 +00:00
|
|
|
sort.Sort(events.SortableEvents(list.Items))
|
2014-11-04 02:02:27 +00:00
|
|
|
for i := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printEvent(&list.Items[i], w, options); err != nil {
|
2014-11-04 02:02:27 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printLimitRange(limitRange *api.LimitRange, w io.Writer, options printers.PrintOptions) error {
|
2016-06-06 23:59:19 +00:00
|
|
|
return printObjectMeta(limitRange.ObjectMeta, w, options, true)
|
|
|
|
}
|
2015-07-01 20:56:31 +00:00
|
|
|
|
2016-06-06 23:59:19 +00:00
|
|
|
// Prints the LimitRangeList in a human-friendly format.
|
2017-02-19 22:37:24 +00:00
|
|
|
func printLimitRangeList(list *api.LimitRangeList, w io.Writer, options printers.PrintOptions) error {
|
2016-06-06 23:59:19 +00:00
|
|
|
for i := range list.Items {
|
|
|
|
if err := printLimitRange(&list.Items[i], w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// printObjectMeta prints the object metadata of a given resource.
|
2017-02-19 22:37:24 +00:00
|
|
|
func printObjectMeta(meta metav1.ObjectMeta, w io.Writer, options printers.PrintOptions, namespaced bool) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, meta.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-06-06 23:59:19 +00:00
|
|
|
if namespaced && options.WithNamespace {
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", meta.Namespace); err != nil {
|
2015-07-01 20:56:31 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-05-20 19:51:35 +00:00
|
|
|
}
|
|
|
|
|
2015-06-18 06:32:03 +00:00
|
|
|
if _, err := fmt.Fprintf(
|
|
|
|
w, "%s\t%s",
|
2016-06-29 22:02:08 +00:00
|
|
|
name,
|
2016-06-06 23:59:19 +00:00
|
|
|
translateTimestamp(meta.CreationTimestamp),
|
2015-06-18 06:32:03 +00:00
|
|
|
); err != nil {
|
2015-06-16 16:30:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(meta.Labels, options.ColumnLabels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, meta.Labels))
|
2015-01-22 21:52:40 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printResourceQuota(resourceQuota *api.ResourceQuota, w io.Writer, options printers.PrintOptions) error {
|
2016-06-06 23:59:19 +00:00
|
|
|
return printObjectMeta(resourceQuota.ObjectMeta, w, options, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints the ResourceQuotaList in a human-friendly format.
|
2017-02-19 22:37:24 +00:00
|
|
|
func printResourceQuotaList(list *api.ResourceQuotaList, w io.Writer, options printers.PrintOptions) error {
|
2015-01-22 21:52:40 +00:00
|
|
|
for i := range list.Items {
|
2016-06-06 23:59:19 +00:00
|
|
|
if err := printResourceQuota(&list.Items[i], w, options); err != nil {
|
2015-01-22 21:52:40 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printRole(role *rbac.Role, w io.Writer, options printers.PrintOptions) error {
|
2016-06-06 23:59:19 +00:00
|
|
|
return printObjectMeta(role.ObjectMeta, w, options, true)
|
|
|
|
}
|
2015-07-01 20:56:31 +00:00
|
|
|
|
2016-06-06 23:59:19 +00:00
|
|
|
// Prints the Role in a human-friendly format.
|
2017-02-19 22:37:24 +00:00
|
|
|
func printRoleList(list *rbac.RoleList, w io.Writer, options printers.PrintOptions) error {
|
2016-06-06 23:59:19 +00:00
|
|
|
for i := range list.Items {
|
|
|
|
if err := printRole(&list.Items[i], w, options); err != nil {
|
2015-07-01 20:56:31 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-05-20 19:51:35 +00:00
|
|
|
}
|
2016-06-06 23:59:19 +00:00
|
|
|
return nil
|
|
|
|
}
|
2015-05-20 19:51:35 +00:00
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printRoleBinding(roleBinding *rbac.RoleBinding, w io.Writer, options printers.PrintOptions) error {
|
2016-11-08 08:19:57 +00:00
|
|
|
meta := roleBinding.ObjectMeta
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, meta.Name, options.WithKind)
|
2016-11-08 08:19:57 +00:00
|
|
|
|
|
|
|
if options.WithNamespace {
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", meta.Namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := fmt.Fprintf(
|
|
|
|
w, "%s\t%s",
|
|
|
|
name,
|
|
|
|
translateTimestamp(meta.CreationTimestamp),
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if options.Wide {
|
|
|
|
roleRef := fmt.Sprintf("%s/%s", roleBinding.RoleRef.Kind, roleBinding.RoleRef.Name)
|
|
|
|
users, groups, sas, _ := rbac.SubjectsStrings(roleBinding.Subjects)
|
|
|
|
if _, err := fmt.Fprintf(w, "\t%s\t%v\t%v\t%v",
|
|
|
|
roleRef,
|
|
|
|
strings.Join(users, ", "),
|
|
|
|
strings.Join(groups, ", "),
|
|
|
|
strings.Join(sas, ", "),
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(meta.Labels, options.ColumnLabels)); err != nil {
|
2016-11-08 08:19:57 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, meta.Labels))
|
2016-11-08 08:19:57 +00:00
|
|
|
return err
|
2016-06-06 23:59:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prints the RoleBinding in a human-friendly format.
|
2017-02-19 22:37:24 +00:00
|
|
|
func printRoleBindingList(list *rbac.RoleBindingList, w io.Writer, options printers.PrintOptions) error {
|
2016-06-06 23:59:19 +00:00
|
|
|
for i := range list.Items {
|
|
|
|
if err := printRoleBinding(&list.Items[i], w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-06-16 16:30:11 +00:00
|
|
|
}
|
2016-06-06 23:59:19 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printClusterRole(clusterRole *rbac.ClusterRole, w io.Writer, options printers.PrintOptions) error {
|
2016-11-08 08:25:33 +00:00
|
|
|
if options.WithNamespace {
|
|
|
|
return fmt.Errorf("clusterRole is not namespaced")
|
|
|
|
}
|
2016-06-06 23:59:19 +00:00
|
|
|
return printObjectMeta(clusterRole.ObjectMeta, w, options, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints the ClusterRole in a human-friendly format.
|
2017-02-19 22:37:24 +00:00
|
|
|
func printClusterRoleList(list *rbac.ClusterRoleList, w io.Writer, options printers.PrintOptions) error {
|
2016-06-06 23:59:19 +00:00
|
|
|
for i := range list.Items {
|
|
|
|
if err := printClusterRole(&list.Items[i], w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-02-04 07:08:44 +00:00
|
|
|
}
|
2016-06-06 23:59:19 +00:00
|
|
|
return nil
|
2015-01-23 17:38:30 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printClusterRoleBinding(clusterRoleBinding *rbac.ClusterRoleBinding, w io.Writer, options printers.PrintOptions) error {
|
2016-11-08 08:19:57 +00:00
|
|
|
meta := clusterRoleBinding.ObjectMeta
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, meta.Name, options.WithKind)
|
2016-11-08 08:19:57 +00:00
|
|
|
|
|
|
|
if options.WithNamespace {
|
|
|
|
return fmt.Errorf("clusterRoleBinding is not namespaced")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := fmt.Fprintf(
|
|
|
|
w, "%s\t%s",
|
|
|
|
name,
|
|
|
|
translateTimestamp(meta.CreationTimestamp),
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if options.Wide {
|
|
|
|
roleRef := clusterRoleBinding.RoleRef.Name
|
|
|
|
users, groups, sas, _ := rbac.SubjectsStrings(clusterRoleBinding.Subjects)
|
|
|
|
if _, err := fmt.Fprintf(w, "\t%s\t%v\t%v\t%v",
|
|
|
|
roleRef,
|
|
|
|
strings.Join(users, ", "),
|
|
|
|
strings.Join(groups, ", "),
|
|
|
|
strings.Join(sas, ", "),
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(meta.Labels, options.ColumnLabels)); err != nil {
|
2016-11-08 08:19:57 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, meta.Labels))
|
2016-11-08 08:19:57 +00:00
|
|
|
return err
|
2016-06-06 23:59:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prints the ClusterRoleBinding in a human-friendly format.
|
2017-02-19 22:37:24 +00:00
|
|
|
func printClusterRoleBindingList(list *rbac.ClusterRoleBindingList, w io.Writer, options printers.PrintOptions) error {
|
2015-01-23 17:38:30 +00:00
|
|
|
for i := range list.Items {
|
2016-06-06 23:59:19 +00:00
|
|
|
if err := printClusterRoleBinding(&list.Items[i], w, options); err != nil {
|
2015-01-23 17:38:30 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printCertificateSigningRequest(csr *certificates.CertificateSigningRequest, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, csr.Name, options.WithKind)
|
2016-08-05 21:46:20 +00:00
|
|
|
meta := csr.ObjectMeta
|
|
|
|
|
|
|
|
status, err := extractCSRStatus(csr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := fmt.Fprintf(
|
|
|
|
w, "%s\t%s\t%s\t%s",
|
|
|
|
name,
|
|
|
|
translateTimestamp(meta.CreationTimestamp),
|
|
|
|
csr.Spec.Username,
|
|
|
|
status,
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(meta.Labels, options.ColumnLabels)); err != nil {
|
2016-08-05 21:46:20 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err = fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, meta.Labels))
|
2016-08-05 21:46:20 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func extractCSRStatus(csr *certificates.CertificateSigningRequest) (string, error) {
|
|
|
|
var approved, denied bool
|
|
|
|
for _, c := range csr.Status.Conditions {
|
|
|
|
switch c.Type {
|
|
|
|
case certificates.CertificateApproved:
|
|
|
|
approved = true
|
|
|
|
case certificates.CertificateDenied:
|
|
|
|
denied = true
|
|
|
|
default:
|
2016-08-30 21:46:06 +00:00
|
|
|
return "", fmt.Errorf("unknown csr condition %q", c)
|
2016-08-05 21:46:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
var status string
|
|
|
|
// must be in order of presidence
|
|
|
|
if denied {
|
|
|
|
status += "Denied"
|
|
|
|
} else if approved {
|
|
|
|
status += "Approved"
|
|
|
|
} else {
|
|
|
|
status += "Pending"
|
|
|
|
}
|
|
|
|
if len(csr.Status.Certificate) > 0 {
|
|
|
|
status += ",Issued"
|
|
|
|
}
|
|
|
|
return status, nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printCertificateSigningRequestList(list *certificates.CertificateSigningRequestList, w io.Writer, options printers.PrintOptions) error {
|
2016-08-05 21:46:20 +00:00
|
|
|
for i := range list.Items {
|
|
|
|
if err := printCertificateSigningRequest(&list.Items[i], w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printComponentStatus(item *api.ComponentStatus, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, item.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-07-01 20:41:54 +00:00
|
|
|
return fmt.Errorf("componentStatus is not namespaced")
|
|
|
|
}
|
2015-04-15 19:23:02 +00:00
|
|
|
status := "Unknown"
|
|
|
|
message := ""
|
|
|
|
error := ""
|
|
|
|
for _, condition := range item.Conditions {
|
|
|
|
if condition.Type == api.ComponentHealthy {
|
|
|
|
if condition.Status == api.ConditionTrue {
|
|
|
|
status = "Healthy"
|
|
|
|
} else {
|
|
|
|
status = "Unhealthy"
|
|
|
|
}
|
|
|
|
message = condition.Message
|
|
|
|
error = condition.Error
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2015-06-16 16:30:11 +00:00
|
|
|
|
2016-06-29 22:02:08 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s", name, status, message, error); err != nil {
|
2015-06-16 16:30:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(item.Labels, options.ColumnLabels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, item.Labels))
|
2015-04-15 19:23:02 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printComponentStatusList(list *api.ComponentStatusList, w io.Writer, options printers.PrintOptions) error {
|
2015-04-15 19:23:02 +00:00
|
|
|
for _, item := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printComponentStatus(&item, w, options); err != nil {
|
2015-04-15 19:23:02 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printThirdPartyResource(rsrc *extensions.ThirdPartyResource, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, rsrc.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2015-08-15 05:10:15 +00:00
|
|
|
versions := make([]string, len(rsrc.Versions))
|
|
|
|
for ix := range rsrc.Versions {
|
|
|
|
version := &rsrc.Versions[ix]
|
2016-03-10 04:06:31 +00:00
|
|
|
versions[ix] = fmt.Sprintf("%s", version.Name)
|
2015-08-15 05:10:15 +00:00
|
|
|
}
|
|
|
|
versionsString := strings.Join(versions, ",")
|
2016-06-29 22:02:08 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\n", name, rsrc.Description, versionsString); err != nil {
|
2015-08-15 05:10:15 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printThirdPartyResourceList(list *extensions.ThirdPartyResourceList, w io.Writer, options printers.PrintOptions) error {
|
2015-08-15 05:10:15 +00:00
|
|
|
for _, item := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printThirdPartyResource(&item, w, options); err != nil {
|
2015-08-15 05:10:15 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2016-03-10 01:27:19 +00:00
|
|
|
|
|
|
|
func truncate(str string, maxLen int) string {
|
|
|
|
if len(str) > maxLen {
|
|
|
|
return str[0:maxLen] + "..."
|
|
|
|
}
|
|
|
|
return str
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printThirdPartyResourceData(rsrc *extensions.ThirdPartyResourceData, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, rsrc.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-03-10 01:27:19 +00:00
|
|
|
l := labels.FormatLabels(rsrc.Labels)
|
|
|
|
truncateCols := 50
|
|
|
|
if options.Wide {
|
|
|
|
truncateCols = 100
|
|
|
|
}
|
2016-06-29 22:02:08 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\n", name, l, truncate(string(rsrc.Data), truncateCols)); err != nil {
|
2016-03-10 01:27:19 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printThirdPartyResourceDataList(list *extensions.ThirdPartyResourceDataList, w io.Writer, options printers.PrintOptions) error {
|
2016-03-10 01:27:19 +00:00
|
|
|
for _, item := range list.Items {
|
|
|
|
if err := printThirdPartyResourceData(&item, w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2015-08-15 05:10:15 +00:00
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printDeployment(deployment *extensions.Deployment, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, deployment.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-08-31 21:43:24 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", deployment.Namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-22 18:40:37 +00:00
|
|
|
desiredReplicas := deployment.Spec.Replicas
|
|
|
|
currentReplicas := deployment.Status.Replicas
|
|
|
|
updatedReplicas := deployment.Status.UpdatedReplicas
|
|
|
|
availableReplicas := deployment.Status.AvailableReplicas
|
2015-08-31 21:43:24 +00:00
|
|
|
age := translateTimestamp(deployment.CreationTimestamp)
|
2016-12-27 04:10:05 +00:00
|
|
|
containers := deployment.Spec.Template.Spec.Containers
|
|
|
|
selector, err := metav1.LabelSelectorAsSelector(deployment.Spec.Selector)
|
|
|
|
if err != nil {
|
|
|
|
// this shouldn't happen if LabelSelector passed validation
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-06-29 22:02:08 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%d\t%d\t%d\t%d\t%s", name, desiredReplicas, currentReplicas, updatedReplicas, availableReplicas, age); err != nil {
|
2015-08-31 21:43:24 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-12-27 04:10:05 +00:00
|
|
|
if options.Wide {
|
|
|
|
if err := layoutContainers(containers, w); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := fmt.Fprintf(w, "\t%s", selector.String()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(deployment.Labels, options.ColumnLabels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err = fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, deployment.Labels))
|
2015-08-31 21:43:24 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printDeploymentList(list *extensions.DeploymentList, w io.Writer, options printers.PrintOptions) error {
|
2015-08-31 21:43:24 +00:00
|
|
|
for _, item := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printDeployment(&item, w, options); err != nil {
|
2015-08-31 21:43:24 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-11-30 20:58:58 +00:00
|
|
|
func formatHPAMetrics(specs []autoscaling.MetricSpec, statuses []autoscaling.MetricStatus) string {
|
|
|
|
if len(specs) == 0 {
|
|
|
|
return "<none>"
|
|
|
|
}
|
|
|
|
list := []string{}
|
|
|
|
max := 2
|
|
|
|
more := false
|
|
|
|
count := 0
|
|
|
|
for i, spec := range specs {
|
|
|
|
switch spec.Type {
|
|
|
|
case autoscaling.PodsMetricSourceType:
|
|
|
|
current := "<unknown>"
|
|
|
|
if len(statuses) > i && statuses[i].Pods != nil {
|
|
|
|
current = statuses[i].Pods.CurrentAverageValue.String()
|
|
|
|
}
|
|
|
|
list = append(list, fmt.Sprintf("%s / %s", current, spec.Pods.TargetAverageValue.String()))
|
|
|
|
case autoscaling.ObjectMetricSourceType:
|
|
|
|
current := "<unknown>"
|
|
|
|
if len(statuses) > i && statuses[i].Object != nil {
|
|
|
|
current = statuses[i].Object.CurrentValue.String()
|
|
|
|
}
|
|
|
|
list = append(list, fmt.Sprintf("%s / %s", current, spec.Object.TargetValue.String()))
|
|
|
|
case autoscaling.ResourceMetricSourceType:
|
|
|
|
if spec.Resource.TargetAverageValue != nil {
|
|
|
|
current := "<unknown>"
|
|
|
|
if len(statuses) > i && statuses[i].Resource != nil {
|
|
|
|
current = statuses[i].Resource.CurrentAverageValue.String()
|
|
|
|
}
|
|
|
|
list = append(list, fmt.Sprintf("%s / %s", current, spec.Resource.TargetAverageValue.String()))
|
|
|
|
} else {
|
|
|
|
current := "<unknown>"
|
|
|
|
if len(statuses) > i && statuses[i].Resource != nil && statuses[i].Resource.CurrentAverageUtilization != nil {
|
|
|
|
current = fmt.Sprintf("%d%%", *statuses[i].Resource.CurrentAverageUtilization)
|
|
|
|
}
|
|
|
|
|
|
|
|
target := "<auto>"
|
|
|
|
if spec.Resource.TargetAverageUtilization != nil {
|
|
|
|
target = fmt.Sprintf("%d%%", *spec.Resource.TargetAverageUtilization)
|
|
|
|
}
|
|
|
|
list = append(list, fmt.Sprintf("%s / %s", current, target))
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
list = append(list, "<unknown type>")
|
|
|
|
}
|
|
|
|
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
|
|
|
|
if count > max {
|
|
|
|
list = list[:max]
|
|
|
|
more = true
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := strings.Join(list, ", ")
|
|
|
|
if more {
|
|
|
|
return fmt.Sprintf("%s + %d more...", ret, count-max)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printHorizontalPodAutoscaler(hpa *autoscaling.HorizontalPodAutoscaler, w io.Writer, options printers.PrintOptions) error {
|
2015-09-02 10:20:11 +00:00
|
|
|
namespace := hpa.Namespace
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, hpa.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-05-05 10:27:24 +00:00
|
|
|
reference := fmt.Sprintf("%s/%s",
|
|
|
|
hpa.Spec.ScaleTargetRef.Kind,
|
|
|
|
hpa.Spec.ScaleTargetRef.Name)
|
2015-10-21 00:30:56 +00:00
|
|
|
minPods := "<unset>"
|
2016-11-30 20:58:58 +00:00
|
|
|
metrics := formatHPAMetrics(hpa.Spec.Metrics, hpa.Status.CurrentMetrics)
|
2015-10-21 00:30:56 +00:00
|
|
|
if hpa.Spec.MinReplicas != nil {
|
|
|
|
minPods = fmt.Sprintf("%d", *hpa.Spec.MinReplicas)
|
|
|
|
}
|
2015-09-17 12:08:39 +00:00
|
|
|
maxPods := hpa.Spec.MaxReplicas
|
2016-12-24 16:54:13 +00:00
|
|
|
currentReplicas := hpa.Status.CurrentReplicas
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-09-02 10:20:11 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-30 20:58:58 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\t%d\t%s",
|
2015-09-02 10:20:11 +00:00
|
|
|
name,
|
|
|
|
reference,
|
2016-11-30 20:58:58 +00:00
|
|
|
metrics,
|
2015-10-21 00:30:56 +00:00
|
|
|
minPods,
|
2015-09-02 10:20:11 +00:00
|
|
|
maxPods,
|
2016-12-24 16:54:13 +00:00
|
|
|
currentReplicas,
|
2015-09-02 10:20:11 +00:00
|
|
|
translateTimestamp(hpa.CreationTimestamp),
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(hpa.Labels, options.ColumnLabels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, hpa.Labels))
|
2015-09-02 10:20:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printHorizontalPodAutoscalerList(list *autoscaling.HorizontalPodAutoscalerList, w io.Writer, options printers.PrintOptions) error {
|
2015-09-02 10:20:11 +00:00
|
|
|
for i := range list.Items {
|
2015-11-10 11:34:28 +00:00
|
|
|
if err := printHorizontalPodAutoscaler(&list.Items[i], w, options); err != nil {
|
2015-09-02 10:20:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printConfigMap(configMap *api.ConfigMap, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, configMap.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-07-22 22:01:59 +00:00
|
|
|
namespace := configMap.Namespace
|
2015-12-15 15:09:42 +00:00
|
|
|
|
2016-01-20 15:39:15 +00:00
|
|
|
if options.WithNamespace {
|
2015-12-15 15:09:42 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%v\t%s", name, len(configMap.Data), translateTimestamp(configMap.CreationTimestamp)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(configMap.Labels, options.ColumnLabels)); err != nil {
|
2016-02-04 07:08:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, configMap.Labels))
|
2015-12-15 15:09:42 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printConfigMapList(list *api.ConfigMapList, w io.Writer, options printers.PrintOptions) error {
|
2015-12-15 15:09:42 +00:00
|
|
|
for i := range list.Items {
|
|
|
|
if err := printConfigMap(&list.Items[i], w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printPodSecurityPolicy(item *extensions.PodSecurityPolicy, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, item.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
|
|
|
_, err := fmt.Fprintf(w, "%s\t%t\t%v\t%s\t%s\t%s\t%s\t%t\t%v\n", name, item.Spec.Privileged,
|
2016-05-05 19:43:54 +00:00
|
|
|
item.Spec.AllowedCapabilities, item.Spec.SELinux.Rule,
|
|
|
|
item.Spec.RunAsUser.Rule, item.Spec.FSGroup.Rule, item.Spec.SupplementalGroups.Rule, item.Spec.ReadOnlyRootFilesystem, item.Spec.Volumes)
|
2015-12-14 13:31:23 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printPodSecurityPolicyList(list *extensions.PodSecurityPolicyList, w io.Writer, options printers.PrintOptions) error {
|
2015-12-14 13:31:23 +00:00
|
|
|
for _, item := range list.Items {
|
|
|
|
if err := printPodSecurityPolicy(&item, w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-03-13 14:31:16 +00:00
|
|
|
func printExtensionsNetworkPolicy(networkPolicy *extensions.NetworkPolicy, w io.Writer, options printers.PrintOptions) error {
|
2017-03-14 09:11:51 +00:00
|
|
|
name := printers.FormatResourceName(options.Kind, networkPolicy.Name, options.WithKind)
|
2016-06-29 22:02:08 +00:00
|
|
|
|
2016-07-22 22:01:59 +00:00
|
|
|
namespace := networkPolicy.Namespace
|
2016-05-18 17:16:33 +00:00
|
|
|
|
|
|
|
if options.WithNamespace {
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-12-03 18:57:26 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%v\t%s", name, metav1.FormatLabelSelector(&networkPolicy.Spec.PodSelector), translateTimestamp(networkPolicy.CreationTimestamp)); err != nil {
|
2016-05-18 17:16:33 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(networkPolicy.Labels, options.ColumnLabels)); err != nil {
|
2016-05-18 17:16:33 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, networkPolicy.Labels))
|
2016-05-18 17:16:33 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-03-13 14:31:16 +00:00
|
|
|
func printExtensionsNetworkPolicyList(list *extensions.NetworkPolicyList, w io.Writer, options printers.PrintOptions) error {
|
|
|
|
for i := range list.Items {
|
|
|
|
if err := printExtensionsNetworkPolicy(&list.Items[i], w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func printNetworkPolicy(networkPolicy *networking.NetworkPolicy, w io.Writer, options printers.PrintOptions) error {
|
|
|
|
name := printers.FormatResourceName(options.Kind, networkPolicy.Name, options.WithKind)
|
|
|
|
|
|
|
|
namespace := networkPolicy.Namespace
|
|
|
|
|
|
|
|
if options.WithNamespace {
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%v\t%s", name, metav1.FormatLabelSelector(&networkPolicy.Spec.PodSelector), translateTimestamp(networkPolicy.CreationTimestamp)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(networkPolicy.Labels, options.ColumnLabels)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, networkPolicy.Labels))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func printNetworkPolicyList(list *networking.NetworkPolicyList, w io.Writer, options printers.PrintOptions) error {
|
2016-05-18 17:16:33 +00:00
|
|
|
for i := range list.Items {
|
|
|
|
if err := printNetworkPolicy(&list.Items[i], w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printStorageClass(sc *storage.StorageClass, w io.Writer, options printers.PrintOptions) error {
|
2016-08-18 08:36:49 +00:00
|
|
|
name := sc.Name
|
2016-10-12 19:49:16 +00:00
|
|
|
|
2017-02-28 03:31:29 +00:00
|
|
|
if options.WithNamespace {
|
|
|
|
return fmt.Errorf("storageclass is not namespaced")
|
|
|
|
}
|
|
|
|
|
2016-10-12 19:49:16 +00:00
|
|
|
if storageutil.IsDefaultAnnotation(sc.ObjectMeta) {
|
|
|
|
name += " (default)"
|
|
|
|
}
|
2016-08-18 08:36:49 +00:00
|
|
|
provtype := sc.Provisioner
|
|
|
|
|
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t", name, provtype); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendLabels(sc.Labels, options.ColumnLabels)); err != nil {
|
2016-08-18 08:36:49 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-14 09:11:51 +00:00
|
|
|
if _, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, sc.Labels)); err != nil {
|
2016-08-18 08:36:49 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printStorageClassList(scList *storage.StorageClassList, w io.Writer, options printers.PrintOptions) error {
|
2016-08-18 08:36:49 +00:00
|
|
|
for _, sc := range scList.Items {
|
|
|
|
if err := printStorageClass(&sc, w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-04-21 02:11:01 +00:00
|
|
|
func printPodPreset(podPreset *settings.PodPreset, w io.Writer, options printers.PrintOptions) error {
|
|
|
|
return printObjectMeta(podPreset.ObjectMeta, w, options, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func printPodPresetList(list *settings.PodPresetList, w io.Writer, options printers.PrintOptions) error {
|
|
|
|
for i := range list.Items {
|
|
|
|
if err := printPodPreset(&list.Items[i], w, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:37:24 +00:00
|
|
|
func printStatus(status *metav1.Status, w io.Writer, options printers.PrintOptions) error {
|
2016-10-28 18:15:14 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\n", status.Status, status.Reason, status.Message); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-03-11 05:29:37 +00:00
|
|
|
// Lay out all the containers on one line if use wide output.
|
|
|
|
func layoutContainers(containers []api.Container, w io.Writer) error {
|
|
|
|
var namesBuffer bytes.Buffer
|
|
|
|
var imagesBuffer bytes.Buffer
|
|
|
|
|
|
|
|
for i, container := range containers {
|
|
|
|
namesBuffer.WriteString(container.Name)
|
|
|
|
imagesBuffer.WriteString(container.Image)
|
|
|
|
if i != len(containers)-1 {
|
|
|
|
namesBuffer.WriteString(",")
|
|
|
|
imagesBuffer.WriteString(",")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_, err := fmt.Fprintf(w, "\t%s\t%s", namesBuffer.String(), imagesBuffer.String())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-01-18 10:28:25 +00:00
|
|
|
// formatEventSource formats EventSource as a comma separated string excluding Host when empty
|
|
|
|
func formatEventSource(es api.EventSource) string {
|
|
|
|
EventSourceString := []string{es.Component}
|
|
|
|
if len(es.Host) > 0 {
|
|
|
|
EventSourceString = append(EventSourceString, es.Host)
|
|
|
|
}
|
|
|
|
return strings.Join(EventSourceString, ", ")
|
|
|
|
}
|