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-07-25 02:50:52 +00:00
appsv1beta1 "k8s.io/api/apps/v1beta1"
2017-06-24 22:31:36 +00:00
batchv1 "k8s.io/api/batch/v1"
batchv2alpha1 "k8s.io/api/batch/v2alpha1"
2017-06-22 18:24:23 +00:00
apiv1 "k8s.io/api/core/v1"
2017-06-24 22:31:36 +00:00
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
2017-06-25 19:43:05 +00:00
"k8s.io/apimachinery/pkg/api/meta"
2017-01-11 14:09:48 +00:00
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2017-05-26 23:00:01 +00:00
metav1alpha1 "k8s.io/apimachinery/pkg/apis/meta/v1alpha1"
2017-01-11 14:09:48 +00:00
"k8s.io/apimachinery/pkg/labels"
2017-05-26 23:00:01 +00:00
"k8s.io/apimachinery/pkg/runtime"
2017-01-11 14:09:48 +00:00
"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"
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-05-30 23:10:56 +00:00
"k8s.io/kubernetes/pkg/controller"
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-06-24 22:31:36 +00:00
persistentVolumeColumns = [ ] string { "NAME" , "CAPACITY" , "ACCESSMODES" , "RECLAIMPOLICY" , "STATUS" , "CLAIM" , "STORAGECLASS" , "REASON" , "AGE" }
persistentVolumeClaimColumns = [ ] string { "NAME" , "STATUS" , "VOLUME" , "CAPACITY" , "ACCESSMODES" , "STORAGECLASS" , "AGE" }
componentStatusColumns = [ ] string { "NAME" , "STATUS" , "MESSAGE" , "ERROR" }
thirdPartyResourceColumns = [ ] string { "NAME" , "DESCRIPTION" , "VERSION(S)" }
roleBindingColumns = [ ] string { "NAME" , "AGE" }
roleBindingWideColumns = [ ] string { "ROLE" , "USERS" , "GROUPS" , "SERVICEACCOUNTS" }
clusterRoleBindingColumns = [ ] string { "NAME" , "AGE" }
clusterRoleBindingWideColumns = [ ] string { "ROLE" , "USERS" , "GROUPS" , "SERVICEACCOUNTS" }
storageClassColumns = [ ] string { "NAME" , "PROVISIONER" }
statusColumns = [ ] string { "STATUS" , "REASON" , "MESSAGE" }
2016-09-20 08:56:25 +00:00
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" }
2017-05-30 23:10:56 +00:00
controllerRevisionColumns = [ ] string { "NAME" , "CONTROLLER" , "REVISION" , "AGE" }
2016-09-20 08:56:25 +00:00
)
2014-10-06 01:24:19 +00:00
2017-05-26 23:00:01 +00:00
// AddHandlers adds print handlers for default Kubernetes types dealing with internal versions.
// TODO: handle errors from Handler
func AddHandlers ( h printers . PrintHandler ) {
podColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Ready" , Type : "string" , Description : "The aggregate readiness state of this pod for accepting traffic." } ,
{ Name : "Status" , Type : "string" , Description : "The aggregate status of the containers in this pod." } ,
{ Name : "Restarts" , Type : "integer" , Description : "The number of times the containers in this pod have been restarted." } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
{ Name : "IP" , Type : "string" , Priority : 1 , Description : apiv1 . PodStatus { } . SwaggerDoc ( ) [ "podIP" ] } ,
{ Name : "Node" , Type : "string" , Priority : 1 , Description : apiv1 . PodSpec { } . SwaggerDoc ( ) [ "nodeName" ] } ,
2016-07-13 16:00:33 +00:00
}
2017-05-26 23:00:01 +00:00
h . TableHandler ( podColumnDefinitions , printPodList )
h . TableHandler ( podColumnDefinitions , printPod )
2016-07-13 16:00:33 +00:00
2017-06-24 22:31:36 +00:00
podTemplateColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Containers" , Type : "string" , Description : "Names of each container in the template." } ,
{ Name : "Images" , Type : "string" , Description : "Images referenced by each container in the template." } ,
{ Name : "Pod Labels" , Type : "string" , Description : "The labels for the pod template." } ,
}
h . TableHandler ( podTemplateColumnDefinitions , printPodTemplate )
h . TableHandler ( podTemplateColumnDefinitions , printPodTemplateList )
podDisruptionBudgetColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Min Available" , Type : "string" , Description : "The minimum number of pods that must be available." } ,
{ Name : "Max Unavailable" , Type : "string" , Description : "The maximum number of pods that may be unavailable." } ,
{ Name : "Allowed Disruptions" , Type : "integer" , Description : "Calculated number of pods that may be disrupted at this time." } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
}
h . TableHandler ( podDisruptionBudgetColumnDefinitions , printPodDisruptionBudget )
h . TableHandler ( podDisruptionBudgetColumnDefinitions , printPodDisruptionBudgetList )
replicationControllerColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Desired" , Type : "integer" , Description : apiv1 . ReplicationControllerSpec { } . SwaggerDoc ( ) [ "replicas" ] } ,
{ Name : "Current" , Type : "integer" , Description : apiv1 . ReplicationControllerStatus { } . SwaggerDoc ( ) [ "replicas" ] } ,
{ Name : "Ready" , Type : "integer" , Description : apiv1 . ReplicationControllerStatus { } . SwaggerDoc ( ) [ "readyReplicas" ] } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
{ Name : "Containers" , Type : "string" , Priority : 1 , Description : "Names of each container in the template." } ,
{ Name : "Images" , Type : "string" , Priority : 1 , Description : "Images referenced by each container in the template." } ,
{ Name : "Selector" , Type : "string" , Priority : 1 , Description : apiv1 . ReplicationControllerSpec { } . SwaggerDoc ( ) [ "selector" ] } ,
}
h . TableHandler ( replicationControllerColumnDefinitions , printReplicationController )
h . TableHandler ( replicationControllerColumnDefinitions , printReplicationControllerList )
replicaSetColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Desired" , Type : "integer" , Description : extensionsv1beta1 . ReplicaSetSpec { } . SwaggerDoc ( ) [ "replicas" ] } ,
{ Name : "Current" , Type : "integer" , Description : extensionsv1beta1 . ReplicaSetStatus { } . SwaggerDoc ( ) [ "replicas" ] } ,
{ Name : "Ready" , Type : "integer" , Description : extensionsv1beta1 . ReplicaSetStatus { } . SwaggerDoc ( ) [ "readyReplicas" ] } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
{ Name : "Containers" , Type : "string" , Priority : 1 , Description : "Names of each container in the template." } ,
{ Name : "Images" , Type : "string" , Priority : 1 , Description : "Images referenced by each container in the template." } ,
{ Name : "Selector" , Type : "string" , Priority : 1 , Description : extensionsv1beta1 . ReplicaSetSpec { } . SwaggerDoc ( ) [ "selector" ] } ,
}
h . TableHandler ( replicaSetColumnDefinitions , printReplicaSet )
h . TableHandler ( replicaSetColumnDefinitions , printReplicaSetList )
2017-06-25 17:01:14 +00:00
daemonSetColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Desired" , Type : "integer" , Description : extensionsv1beta1 . DaemonSetStatus { } . SwaggerDoc ( ) [ "desiredNumberScheduled" ] } ,
{ Name : "Current" , Type : "integer" , Description : extensionsv1beta1 . DaemonSetStatus { } . SwaggerDoc ( ) [ "currentNumberScheduled" ] } ,
{ Name : "Ready" , Type : "integer" , Description : extensionsv1beta1 . DaemonSetStatus { } . SwaggerDoc ( ) [ "numberReady" ] } ,
{ Name : "Up-to-date" , Type : "integer" , Description : extensionsv1beta1 . DaemonSetStatus { } . SwaggerDoc ( ) [ "updatedNumberScheduled" ] } ,
{ Name : "Available" , Type : "integer" , Description : extensionsv1beta1 . DaemonSetStatus { } . SwaggerDoc ( ) [ "numberAvailable" ] } ,
{ Name : "Node Selector" , Type : "string" , Description : apiv1 . PodSpec { } . SwaggerDoc ( ) [ "nodeSelector" ] } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
{ Name : "Containers" , Type : "string" , Priority : 1 , Description : "Names of each container in the template." } ,
{ Name : "Images" , Type : "string" , Priority : 1 , Description : "Images referenced by each container in the template." } ,
{ Name : "Selector" , Type : "string" , Priority : 1 , Description : extensionsv1beta1 . DaemonSetSpec { } . SwaggerDoc ( ) [ "selector" ] } ,
}
h . TableHandler ( daemonSetColumnDefinitions , printDaemonSet )
h . TableHandler ( daemonSetColumnDefinitions , printDaemonSetList )
2017-06-24 22:31:36 +00:00
jobColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Desired" , Type : "integer" , Description : batchv1 . JobSpec { } . SwaggerDoc ( ) [ "completions" ] } ,
{ Name : "Successful" , Type : "integer" , Description : batchv1 . JobStatus { } . SwaggerDoc ( ) [ "succeeded" ] } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
{ Name : "Containers" , Type : "string" , Priority : 1 , Description : "Names of each container in the template." } ,
{ Name : "Images" , Type : "string" , Priority : 1 , Description : "Images referenced by each container in the template." } ,
{ Name : "Selector" , Type : "string" , Priority : 1 , Description : batchv1 . JobSpec { } . SwaggerDoc ( ) [ "selector" ] } ,
}
h . TableHandler ( jobColumnDefinitions , printJob )
h . TableHandler ( jobColumnDefinitions , printJobList )
cronJobColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Schedule" , Type : "string" , Description : batchv2alpha1 . CronJobSpec { } . SwaggerDoc ( ) [ "schedule" ] } ,
{ Name : "Suspend" , Type : "boolean" , Description : batchv2alpha1 . CronJobSpec { } . SwaggerDoc ( ) [ "suspend" ] } ,
{ Name : "Active" , Type : "integer" , Description : batchv2alpha1 . CronJobStatus { } . SwaggerDoc ( ) [ "active" ] } ,
{ Name : "Last Schedule" , Type : "string" , Description : batchv2alpha1 . CronJobStatus { } . SwaggerDoc ( ) [ "lastScheduleTime" ] } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
{ Name : "Containers" , Type : "string" , Priority : 1 , Description : "Names of each container in the template." } ,
{ Name : "Images" , Type : "string" , Priority : 1 , Description : "Images referenced by each container in the template." } ,
{ Name : "Selector" , Type : "string" , Priority : 1 , Description : batchv1 . JobSpec { } . SwaggerDoc ( ) [ "selector" ] } ,
}
h . TableHandler ( cronJobColumnDefinitions , printCronJob )
h . TableHandler ( cronJobColumnDefinitions , printCronJobList )
2017-07-21 07:42:30 +00:00
serviceColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Type" , Type : "string" , Description : apiv1 . ServiceSpec { } . SwaggerDoc ( ) [ "type" ] } ,
{ Name : "Cluster-IP" , Type : "string" , Description : apiv1 . ServiceSpec { } . SwaggerDoc ( ) [ "clusterIP" ] } ,
{ Name : "External-IP" , Type : "string" , Description : apiv1 . ServiceSpec { } . SwaggerDoc ( ) [ "externalIPs" ] } ,
{ Name : "Port(s)" , Type : "string" , Description : apiv1 . ServiceSpec { } . SwaggerDoc ( ) [ "ports" ] } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
{ Name : "Selector" , Type : "string" , Priority : 1 , Description : apiv1 . ServiceSpec { } . SwaggerDoc ( ) [ "selector" ] } ,
}
h . TableHandler ( serviceColumnDefinitions , printService )
h . TableHandler ( serviceColumnDefinitions , printServiceList )
2017-07-25 02:05:10 +00:00
ingressColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Hosts" , Type : "string" , Description : "Hosts that incoming requests are matched against before the ingress rule" } ,
{ Name : "Address" , Type : "string" , Description : "Address is a list containing ingress points for the load-balancer" } ,
{ Name : "Ports" , Type : "string" , Description : "Ports of TLS configurations that open" } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
}
h . TableHandler ( ingressColumnDefinitions , printIngress )
h . TableHandler ( ingressColumnDefinitions , printIngressList )
2017-07-25 02:50:52 +00:00
statefulSetColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Desired" , Type : "string" , Description : appsv1beta1 . StatefulSetSpec { } . SwaggerDoc ( ) [ "replicas" ] } ,
{ Name : "Current" , Type : "string" , Description : appsv1beta1 . StatefulSetStatus { } . SwaggerDoc ( ) [ "replicas" ] } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
{ Name : "Containers" , Type : "string" , Priority : 1 , Description : "Names of each container in the template." } ,
{ Name : "Images" , Type : "string" , Priority : 1 , Description : "Images referenced by each container in the template." } ,
}
h . TableHandler ( statefulSetColumnDefinitions , printStatefulSet )
h . TableHandler ( statefulSetColumnDefinitions , printStatefulSetList )
2017-07-25 03:04:37 +00:00
endpointColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Endpoints" , Type : "string" , Description : apiv1 . Endpoints { } . SwaggerDoc ( ) [ "subsets" ] } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
}
h . TableHandler ( endpointColumnDefinitions , printEndpoints )
h . TableHandler ( endpointColumnDefinitions , printEndpointsList )
2017-07-25 04:20:50 +00:00
nodeColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Status" , Type : "string" , Description : "The status of the node" } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
{ Name : "Version" , Type : "string" , Description : apiv1 . NodeSystemInfo { } . SwaggerDoc ( ) [ "kubeletVersion" ] } ,
{ Name : "External-IP" , Type : "string" , Priority : 1 , Description : apiv1 . NodeStatus { } . SwaggerDoc ( ) [ "addresses" ] } ,
{ Name : "OS-Image" , Type : "string" , Priority : 1 , Description : apiv1 . NodeSystemInfo { } . SwaggerDoc ( ) [ "osImage" ] } ,
{ Name : "Kernel-Version" , Type : "string" , Priority : 1 , Description : apiv1 . NodeSystemInfo { } . SwaggerDoc ( ) [ "kernelVersion" ] } ,
{ Name : "Container-Runtime" , Type : "string" , Priority : 1 , Description : apiv1 . NodeSystemInfo { } . SwaggerDoc ( ) [ "containerRuntimeVersion" ] } ,
}
h . TableHandler ( nodeColumnDefinitions , printNode )
h . TableHandler ( nodeColumnDefinitions , printNodeList )
2017-07-27 07:37:18 +00:00
eventColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Lastseen" , Type : "string" , Description : apiv1 . Event { } . SwaggerDoc ( ) [ "lastTimestamp" ] } ,
{ Name : "Firtseen" , Type : "string" , Description : apiv1 . Event { } . SwaggerDoc ( ) [ "firstTimestamp" ] } ,
{ Name : "Count" , Type : "string" , Description : apiv1 . Event { } . SwaggerDoc ( ) [ "count" ] } ,
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Kind" , Type : "string" , Description : apiv1 . Event { } . InvolvedObject . SwaggerDoc ( ) [ "kind" ] } ,
{ Name : "Subobject" , Type : "string" , Description : apiv1 . Event { } . InvolvedObject . SwaggerDoc ( ) [ "fieldPath" ] } ,
{ Name : "Type" , Type : "string" , Description : apiv1 . Event { } . SwaggerDoc ( ) [ "type" ] } ,
{ Name : "Reason" , Type : "string" , Description : apiv1 . Event { } . SwaggerDoc ( ) [ "reason" ] } ,
{ Name : "Source" , Type : "string" , Description : apiv1 . Event { } . SwaggerDoc ( ) [ "source" ] } ,
{ Name : "Message" , Type : "string" , Description : apiv1 . Event { } . SwaggerDoc ( ) [ "message" ] } ,
}
h . TableHandler ( eventColumnDefinitions , printEvent )
h . TableHandler ( eventColumnDefinitions , printEventList )
2017-07-27 08:10:57 +00:00
2017-07-27 08:04:33 +00:00
namespaceColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Status" , Type : "string" , Description : "The status of the namespace" } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
}
h . TableHandler ( namespaceColumnDefinitions , printNamespace )
h . TableHandler ( namespaceColumnDefinitions , printNamespaceList )
2017-07-27 07:37:18 +00:00
2017-07-27 08:10:57 +00:00
secretColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Type" , Type : "string" , Description : apiv1 . Secret { } . SwaggerDoc ( ) [ "type" ] } ,
{ Name : "Data" , Type : "string" , Description : apiv1 . Secret { } . SwaggerDoc ( ) [ "data" ] } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
}
2017-07-27 08:14:27 +00:00
h . TableHandler ( secretColumnDefinitions , printSecret )
2017-07-27 08:10:57 +00:00
h . TableHandler ( secretColumnDefinitions , printSecretList )
2017-07-27 08:14:27 +00:00
serviceAccountColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Secrets" , Type : "string" , Description : apiv1 . ServiceAccount { } . SwaggerDoc ( ) [ "secrets" ] } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
}
h . TableHandler ( serviceAccountColumnDefinitions , printServiceAccount )
h . TableHandler ( serviceAccountColumnDefinitions , printServiceAccountList )
2017-01-04 16:32:14 +00:00
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 ( 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 ( roleBindingColumns , roleBindingWideColumns , printRoleBinding )
h . Handler ( roleBindingColumns , roleBindingWideColumns , printRoleBindingList )
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 )
h . Handler ( statusColumns , nil , printStatus )
2017-05-30 23:10:56 +00:00
h . Handler ( controllerRevisionColumns , nil , printControllerRevision )
h . Handler ( controllerRevisionColumns , nil , printControllerRevisionList )
2017-06-25 19:43:05 +00:00
AddDefaultHandlers ( h )
}
// AddDefaultHandlers adds handlers that can work with most Kubernetes objects.
func AddDefaultHandlers ( h printers . PrintHandler ) {
// types without defined columns
objectMetaColumnDefinitions := [ ] metav1alpha1 . TableColumnDefinition {
{ Name : "Name" , Type : "string" , Format : "name" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "name" ] } ,
{ Name : "Age" , Type : "string" , Description : metav1 . ObjectMeta { } . SwaggerDoc ( ) [ "creationTimestamp" ] } ,
}
h . DefaultTableHandler ( objectMetaColumnDefinitions , printObjectMeta )
}
func printObjectMeta ( obj runtime . Object , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
if meta . IsListType ( obj ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , 16 )
err := meta . EachListItem ( obj , func ( obj runtime . Object ) error {
nestedRows , err := printObjectMeta ( obj , options )
if err != nil {
return err
}
rows = append ( rows , nestedRows ... )
return nil
} )
if err != nil {
return nil , err
}
return rows , nil
}
rows := make ( [ ] metav1alpha1 . TableRow , 0 , 1 )
m , err := meta . Accessor ( obj )
if err != nil {
return nil , err
}
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
}
row . Cells = append ( row . Cells , m . GetName ( ) , translateTimestamp ( m . GetCreationTimestamp ( ) ) )
rows = append ( rows , row )
return rows , nil
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-05-26 23:00:01 +00:00
var (
podSuccessConditions = [ ] metav1alpha1 . TableRowCondition { { Type : metav1alpha1 . RowCompleted , Status : metav1alpha1 . ConditionTrue , Reason : string ( api . PodSucceeded ) , Message : "The pod has completed successfully." } }
podFailedConditions = [ ] metav1alpha1 . TableRowCondition { { Type : metav1alpha1 . RowCompleted , Status : metav1alpha1 . ConditionTrue , Reason : string ( api . PodFailed ) , Message : "The pod failed." } }
)
2015-05-20 19:51:35 +00:00
2017-05-26 23:00:01 +00:00
func printPodList ( podList * api . PodList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( podList . Items ) )
for i := range podList . Items {
r , err := printPod ( & podList . Items [ i ] , options )
if err != nil {
return nil , err
}
rows = append ( rows , r ... )
}
return rows , nil
}
func printPod ( pod * api . Pod , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
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
2017-05-26 23:00:01 +00:00
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : pod } ,
}
switch pod . Status . Phase {
case api . PodSucceeded :
row . Conditions = podSuccessConditions
case api . PodFailed :
row . Conditions = podFailedConditions
}
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
2017-05-26 23:00:01 +00:00
row . Cells = append ( row . Cells , pod . Name , fmt . Sprintf ( "%d/%d" , readyContainers , totalContainers ) , reason , restarts , translateTimestamp ( pod . CreationTimestamp ) )
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>"
}
2017-05-26 23:00:01 +00:00
row . Cells = append ( row . Cells , podIP , nodeName )
2016-02-04 07:08:44 +00:00
}
2017-05-26 23:00:01 +00:00
return [ ] metav1alpha1 . TableRow { row } , nil
2014-10-06 01:24:19 +00:00
}
2017-06-24 22:31:36 +00:00
func printPodTemplate ( obj * api . PodTemplate , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
2016-02-04 07:08:44 +00:00
}
2017-06-24 22:31:36 +00:00
names , images := layoutContainerCells ( obj . Template . Spec . Containers )
row . Cells = append ( row . Cells , obj . Name , names , images , labels . FormatLabels ( obj . Template . Labels ) )
return [ ] metav1alpha1 . TableRow { row } , nil
2015-03-04 00:54:17 +00:00
}
2017-06-24 22:31:36 +00:00
func printPodTemplateList ( list * api . PodTemplateList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
for i := range list . Items {
r , err := printPodTemplate ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2015-03-04 00:54:17 +00:00
}
2017-06-24 22:31:36 +00:00
rows = append ( rows , r ... )
2015-03-04 00:54:17 +00:00
}
2017-06-24 22:31:36 +00:00
return rows , nil
2015-03-04 00:54:17 +00:00
}
2017-06-24 22:31:36 +00:00
func printPodDisruptionBudget ( obj * policy . PodDisruptionBudget , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
2016-10-21 11:57:49 +00:00
}
2017-05-15 23:50:23 +00:00
var minAvailable string
var maxUnavailable string
2017-06-24 22:31:36 +00:00
if obj . Spec . MinAvailable != nil {
minAvailable = obj . Spec . MinAvailable . String ( )
2017-05-15 23:50:23 +00:00
} else {
minAvailable = "N/A"
}
2017-06-24 22:31:36 +00:00
if obj . Spec . MaxUnavailable != nil {
maxUnavailable = obj . Spec . MaxUnavailable . String ( )
2017-05-15 23:50:23 +00:00
} else {
maxUnavailable = "N/A"
}
2017-06-24 22:31:36 +00:00
row . Cells = append ( row . Cells , obj . Name , minAvailable , maxUnavailable , obj . Status . PodDisruptionsAllowed , translateTimestamp ( obj . CreationTimestamp ) )
return [ ] metav1alpha1 . TableRow { row } , nil
2016-10-21 11:57:49 +00:00
}
2017-06-24 22:31:36 +00:00
func printPodDisruptionBudgetList ( list * policy . PodDisruptionBudgetList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
for i := range list . Items {
r , err := printPodDisruptionBudget ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2016-10-21 11:57:49 +00:00
}
2017-06-24 22:31:36 +00:00
rows = append ( rows , r ... )
2016-10-21 11:57:49 +00:00
}
2017-06-24 22:31:36 +00:00
return rows , nil
2016-10-21 11:57:49 +00:00
}
2016-03-11 05:29:37 +00:00
// TODO(AdoHe): try to put wide output in a single method
2017-06-24 22:31:36 +00:00
func printReplicationController ( obj * api . ReplicationController , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
2015-07-01 20:56:31 +00:00
}
2016-02-23 15:11:19 +00:00
2017-06-24 22:31:36 +00:00
desiredReplicas := obj . Spec . Replicas
currentReplicas := obj . Status . Replicas
readyReplicas := obj . Status . ReadyReplicas
2016-03-11 05:29:37 +00:00
2017-06-24 22:31:36 +00:00
row . Cells = append ( row . Cells , obj . Name , desiredReplicas , currentReplicas , readyReplicas , translateTimestamp ( obj . CreationTimestamp ) )
2016-02-14 08:14:20 +00:00
if options . Wide {
2017-06-24 22:31:36 +00:00
names , images := layoutContainerCells ( obj . Spec . Template . Spec . Containers )
row . Cells = append ( row . Cells , names , images , labels . FormatLabels ( obj . Spec . Selector ) )
2016-02-04 07:08:44 +00:00
}
2017-06-24 22:31:36 +00:00
return [ ] metav1alpha1 . TableRow { row } , nil
2014-10-06 01:24:19 +00:00
}
2017-06-24 22:31:36 +00:00
func printReplicationControllerList ( list * api . ReplicationControllerList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
for i := range list . Items {
r , err := printReplicationController ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2014-10-06 01:24:19 +00:00
}
2017-06-24 22:31:36 +00:00
rows = append ( rows , r ... )
2014-10-06 01:24:19 +00:00
}
2017-06-24 22:31:36 +00:00
return rows , nil
2014-10-06 01:24:19 +00:00
}
2017-06-24 22:31:36 +00:00
func printReplicaSet ( obj * extensions . ReplicaSet , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
2016-02-09 05:23:56 +00:00
}
2016-02-23 15:11:19 +00:00
2017-06-24 22:31:36 +00:00
desiredReplicas := obj . Spec . Replicas
currentReplicas := obj . Status . Replicas
readyReplicas := obj . Status . ReadyReplicas
row . Cells = append ( row . Cells , obj . Name , desiredReplicas , currentReplicas , readyReplicas , translateTimestamp ( obj . CreationTimestamp ) )
2016-02-14 08:14:20 +00:00
if options . Wide {
2017-06-24 22:31:36 +00:00
names , images := layoutContainerCells ( obj . Spec . Template . Spec . Containers )
row . Cells = append ( row . Cells , names , images , metav1 . FormatLabelSelector ( obj . Spec . Selector ) )
2016-02-09 05:23:56 +00:00
}
2017-06-24 22:31:36 +00:00
return [ ] metav1alpha1 . TableRow { row } , nil
2016-02-09 05:23:56 +00:00
}
2017-06-24 22:31:36 +00:00
func printReplicaSetList ( list * extensions . ReplicaSetList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
for i := range list . Items {
r , err := printReplicaSet ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2016-02-09 05:23:56 +00:00
}
2017-06-24 22:31:36 +00:00
rows = append ( rows , r ... )
2016-02-09 05:23:56 +00:00
}
2017-06-24 22:31:36 +00:00
return rows , nil
2016-02-09 05:23:56 +00:00
}
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-06-24 22:31:36 +00:00
func printJob ( obj * batch . Job , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
2015-08-21 14:23:12 +00:00
}
2015-10-14 18:04:33 +00:00
2017-06-24 22:31:36 +00:00
var completions string
if obj . Spec . Completions != nil {
completions = strconv . Itoa ( int ( * obj . Spec . Completions ) )
2016-02-25 15:43:04 +00:00
} else {
2017-06-24 22:31:36 +00:00
completions = "<none>"
2015-08-21 14:23:12 +00:00
}
2017-06-24 22:31:36 +00:00
row . Cells = append ( row . Cells , obj . Name , completions , obj . Status . Succeeded , translateTimestamp ( obj . CreationTimestamp ) )
2016-02-14 08:14:20 +00:00
if options . Wide {
2017-06-24 22:31:36 +00:00
names , images := layoutContainerCells ( obj . Spec . Template . Spec . Containers )
row . Cells = append ( row . Cells , names , images , metav1 . FormatLabelSelector ( obj . Spec . Selector ) )
2016-02-04 07:08:44 +00:00
}
2017-06-24 22:31:36 +00:00
return [ ] metav1alpha1 . TableRow { row } , nil
2015-08-21 14:23:12 +00:00
}
2017-06-24 22:31:36 +00:00
func printJobList ( list * batch . JobList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
for i := range list . Items {
r , err := printJob ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2015-08-21 14:23:12 +00:00
}
2017-06-24 22:31:36 +00:00
rows = append ( rows , r ... )
2015-08-21 14:23:12 +00:00
}
2017-06-24 22:31:36 +00:00
return rows , nil
2015-08-21 14:23:12 +00:00
}
2017-06-24 22:31:36 +00:00
func printCronJob ( obj * batch . CronJob , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
2016-05-18 08:11:35 +00:00
}
lastScheduleTime := "<none>"
2017-06-24 22:31:36 +00:00
if obj . Status . LastScheduleTime != nil {
lastScheduleTime = obj . Status . LastScheduleTime . Time . Format ( time . RFC1123Z )
2016-05-18 08:11:35 +00:00
}
2017-06-24 22:31:36 +00:00
row . Cells = append ( row . Cells , obj . Name , obj . Spec . Schedule , printBoolPtr ( obj . Spec . Suspend ) , len ( obj . Status . Active ) , lastScheduleTime )
if options . Wide {
names , images := layoutContainerCells ( obj . Spec . JobTemplate . Spec . Template . Spec . Containers )
row . Cells = append ( row . Cells , names , images , metav1 . FormatLabelSelector ( obj . Spec . JobTemplate . Spec . Selector ) )
}
return [ ] metav1alpha1 . TableRow { row } , nil
2016-05-18 08:11:35 +00:00
}
2017-06-24 22:31:36 +00:00
func printCronJobList ( list * batch . CronJobList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
for i := range list . Items {
r , err := printCronJob ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2016-05-18 08:11:35 +00:00
}
2017-06-24 22:31:36 +00:00
rows = append ( rows , r ... )
2016-05-18 08:11:35 +00:00
}
2017-06-24 22:31:36 +00:00
return rows , nil
2016-05-18 08:11:35 +00:00
}
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 , "," )
}
2017-06-18 04:19:57 +00:00
return "<none>"
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 {
2017-06-23 16:10:33 +00:00
results := [ ] string { }
if len ( lbIps ) > 0 {
results = append ( results , strings . Split ( lbIps , "," ) ... )
}
results = append ( results , svc . Spec . ExternalIPs ... )
return strings . Join ( results , "," )
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-07-21 07:42:30 +00:00
func printService ( obj * api . Service , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
}
svcType := obj . Spec . Type
internalIP := obj . Spec . ClusterIP
2017-06-08 11:55:23 +00:00
if len ( internalIP ) == 0 {
internalIP = "<none>"
}
2017-07-21 07:42:30 +00:00
externalIP := getServiceExternalIP ( obj , options . Wide )
svcPorts := makePortString ( obj . Spec . Ports )
2017-06-08 11:55:23 +00:00
if len ( svcPorts ) == 0 {
svcPorts = "<none>"
}
2015-05-20 19:51:35 +00:00
2017-07-21 07:42:30 +00:00
row . Cells = append ( row . Cells , obj . Name , string ( svcType ) , internalIP , externalIP , svcPorts , translateTimestamp ( obj . CreationTimestamp ) )
2016-02-14 08:14:20 +00:00
if options . Wide {
2017-07-21 07:42:30 +00:00
row . Cells = append ( row . Cells , labels . FormatLabels ( obj . Spec . Selector ) )
2015-06-16 16:30:11 +00:00
}
2017-07-21 07:42:30 +00:00
return [ ] metav1alpha1 . TableRow { row } , nil
2014-10-06 01:24:19 +00:00
}
2017-07-21 07:42:30 +00:00
func printServiceList ( list * api . ServiceList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
for i := range list . Items {
r , err := printService ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2014-10-06 01:24:19 +00:00
}
2017-07-21 07:42:30 +00:00
rows = append ( rows , r ... )
2014-10-06 01:24:19 +00:00
}
2017-07-21 07:42:30 +00:00
return rows , nil
2014-10-06 01:24:19 +00:00
}
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-07-25 02:05:10 +00:00
func printIngress ( obj * extensions . Ingress , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
2016-02-04 07:08:44 +00:00
}
2017-07-25 02:05:10 +00:00
hosts := formatHosts ( obj . Spec . Rules )
address := loadBalancerStatusStringer ( obj . Status . LoadBalancer , options . Wide )
ports := formatPorts ( obj . Spec . TLS )
createTime := translateTimestamp ( obj . CreationTimestamp )
row . Cells = append ( row . Cells , obj . Name , hosts , address , ports , createTime )
return [ ] metav1alpha1 . TableRow { row } , nil
2015-09-23 21:50:59 +00:00
}
2017-07-25 02:05:10 +00:00
func printIngressList ( list * extensions . IngressList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
for i := range list . Items {
r , err := printIngress ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2015-09-23 21:50:59 +00:00
}
2017-07-25 02:05:10 +00:00
rows = append ( rows , r ... )
2015-09-23 21:50:59 +00:00
}
2017-07-25 02:05:10 +00:00
return rows , nil
2015-09-23 21:50:59 +00:00
}
2017-07-25 02:50:52 +00:00
func printStatefulSet ( obj * apps . StatefulSet , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
2016-04-15 22:30:15 +00:00
}
2017-07-25 02:50:52 +00:00
desiredReplicas := obj . Spec . Replicas
currentReplicas := obj . Status . Replicas
createTime := translateTimestamp ( obj . CreationTimestamp )
row . Cells = append ( row . Cells , obj . Name , desiredReplicas , currentReplicas , createTime )
2016-04-15 22:30:15 +00:00
if options . Wide {
2017-07-25 02:50:52 +00:00
names , images := layoutContainerCells ( obj . Spec . Template . Spec . Containers )
row . Cells = append ( row . Cells , names , images )
2016-04-15 22:30:15 +00:00
}
2017-07-25 02:50:52 +00:00
return [ ] metav1alpha1 . TableRow { row } , nil
2016-04-15 22:30:15 +00:00
}
2017-07-25 02:50:52 +00:00
func printStatefulSetList ( list * apps . StatefulSetList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
for i := range list . Items {
r , err := printStatefulSet ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2016-04-15 22:30:15 +00:00
}
2017-07-25 02:50:52 +00:00
rows = append ( rows , r ... )
2016-04-15 22:30:15 +00:00
}
2017-07-25 02:50:52 +00:00
return rows , nil
2016-04-15 22:30:15 +00:00
}
2017-06-25 17:01:14 +00:00
func printDaemonSet ( obj * extensions . DaemonSet , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
2015-08-27 17:18:16 +00:00
}
2016-02-23 15:11:19 +00:00
2017-06-25 17:01:14 +00:00
desiredScheduled := obj . Status . DesiredNumberScheduled
currentScheduled := obj . Status . CurrentNumberScheduled
numberReady := obj . Status . NumberReady
numberUpdated := obj . Status . UpdatedNumberScheduled
numberAvailable := obj . Status . NumberAvailable
row . Cells = append ( row . Cells , obj . Name , desiredScheduled , currentScheduled , numberReady , numberUpdated , numberAvailable , labels . FormatLabels ( obj . Spec . Template . Spec . NodeSelector ) , translateTimestamp ( obj . CreationTimestamp ) )
2016-02-14 08:14:20 +00:00
if options . Wide {
2017-06-25 17:01:14 +00:00
names , images := layoutContainerCells ( obj . Spec . Template . Spec . Containers )
row . Cells = append ( row . Cells , names , images , metav1 . FormatLabelSelector ( obj . Spec . Selector ) )
2016-02-04 07:08:44 +00:00
}
2017-06-25 17:01:14 +00:00
return [ ] metav1alpha1 . TableRow { row } , nil
2015-08-27 17:18:16 +00:00
}
2017-06-25 17:01:14 +00:00
func printDaemonSetList ( list * extensions . DaemonSetList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
for i := range list . Items {
r , err := printDaemonSet ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2015-08-27 17:18:16 +00:00
}
2017-06-25 17:01:14 +00:00
rows = append ( rows , r ... )
2015-08-27 17:18:16 +00:00
}
2017-06-25 17:01:14 +00:00
return rows , nil
2015-08-27 17:18:16 +00:00
}
2017-07-25 03:04:37 +00:00
func printEndpoints ( obj * api . Endpoints , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
2016-02-04 07:08:44 +00:00
}
2017-07-25 03:04:37 +00:00
row . Cells = append ( row . Cells , obj . Name , formatEndpoints ( obj , nil ) , translateTimestamp ( obj . CreationTimestamp ) )
return [ ] metav1alpha1 . TableRow { row } , nil
2015-02-05 23:45:53 +00:00
}
2017-07-25 03:04:37 +00:00
func printEndpointsList ( list * api . EndpointsList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
for i := range list . Items {
r , err := printEndpoints ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2015-02-24 02:20:10 +00:00
}
2017-07-25 03:04:37 +00:00
rows = append ( rows , r ... )
2015-02-24 02:20:10 +00:00
}
2017-07-25 03:04:37 +00:00
return rows , nil
2015-02-24 02:20:10 +00:00
}
2017-07-27 08:04:33 +00:00
func printNamespace ( obj * api . Namespace , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
2016-02-04 07:08:44 +00:00
}
2017-07-27 08:04:33 +00:00
row . Cells = append ( row . Cells , obj . Name , obj . Status . Phase , translateTimestamp ( obj . CreationTimestamp ) )
return [ ] metav1alpha1 . TableRow { row } , nil
2015-01-19 21:50:00 +00:00
}
2017-07-27 08:04:33 +00:00
func printNamespaceList ( list * api . NamespaceList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
for i := range list . Items {
r , err := printNamespace ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2015-01-19 21:50:00 +00:00
}
2017-07-27 08:04:33 +00:00
rows = append ( rows , r ... )
2015-01-19 21:50:00 +00:00
}
2017-07-27 08:04:33 +00:00
return rows , nil
2015-01-19 21:50:00 +00:00
}
2017-07-27 08:14:27 +00:00
func printSecret ( obj * api . Secret , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
2017-07-27 08:10:57 +00:00
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
2016-02-04 07:08:44 +00:00
}
2017-07-27 08:14:27 +00:00
row . Cells = append ( row . Cells , obj . Name , obj . Type , len ( obj . Data ) , translateTimestamp ( obj . CreationTimestamp ) )
2017-07-27 08:10:57 +00:00
return [ ] metav1alpha1 . TableRow { row } , nil
2015-02-18 01:24:50 +00:00
}
2017-07-27 08:14:27 +00:00
func printSecretList ( list * api . SecretList , w io . Writer , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
2017-07-27 08:10:57 +00:00
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
for i := range list . Items {
r , err := printSecret ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2015-02-18 01:24:50 +00:00
}
2017-07-27 08:10:57 +00:00
rows = append ( rows , r ... )
2015-02-18 01:24:50 +00:00
}
2017-07-27 08:10:57 +00:00
return rows , nil
2015-02-18 01:24:50 +00:00
}
2017-07-27 08:14:27 +00:00
func printServiceAccount ( obj * api . ServiceAccount , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
2016-02-04 07:08:44 +00:00
}
2017-07-27 08:14:27 +00:00
row . Cells = append ( row . Cells , obj . Name , len ( obj . Secrets ) , translateTimestamp ( obj . CreationTimestamp ) )
return [ ] metav1alpha1 . TableRow { row } , nil
2015-04-27 22:53:28 +00:00
}
2017-07-27 08:14:27 +00:00
func printServiceAccountList ( list * api . ServiceAccountList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
for i := range list . Items {
r , err := printServiceAccount ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2015-04-27 22:53:28 +00:00
}
2017-07-27 08:14:27 +00:00
rows = append ( rows , r ... )
2015-04-27 22:53:28 +00:00
}
2017-07-27 08:14:27 +00:00
return rows , nil
2015-04-27 22:53:28 +00:00
}
2017-07-25 04:20:50 +00:00
func printNode ( obj * api . Node , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
2015-07-01 20:41:54 +00:00
}
2017-07-25 04:20:50 +00:00
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 }
2017-07-25 04:20:50 +00:00
for i := range obj . Status . Conditions {
cond := obj . 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" )
}
2017-07-25 04:20:50 +00:00
if obj . Spec . Unschedulable {
2015-04-16 01:53:03 +00:00
status = append ( status , "SchedulingDisabled" )
}
2015-06-16 16:30:11 +00:00
2017-07-25 04:20:50 +00:00
row . Cells = append ( row . Cells , obj . Name , strings . Join ( status , "," ) , translateTimestamp ( obj . CreationTimestamp ) , obj . Status . NodeInfo . KubeletVersion )
2016-09-27 10:31:37 +00:00
if options . Wide {
2017-07-25 04:20:50 +00:00
osImage , kernelVersion , crVersion := obj . Status . NodeInfo . OSImage , obj . Status . NodeInfo . KernelVersion , obj . Status . NodeInfo . ContainerRuntimeVersion
2016-12-16 05:42:59 +00:00
if osImage == "" {
osImage = "<unknown>"
}
if kernelVersion == "" {
kernelVersion = "<unknown>"
}
2017-05-30 20:14:04 +00:00
if crVersion == "" {
crVersion = "<unknown>"
}
2017-07-25 04:20:50 +00:00
row . Cells = append ( row . Cells , getNodeExternalIP ( obj ) , osImage , kernelVersion , crVersion )
2015-06-16 16:30:11 +00:00
}
2017-07-25 04:20:50 +00:00
return [ ] metav1alpha1 . TableRow { row } , nil
2014-10-06 01:24:19 +00:00
}
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>"
}
2017-07-25 04:20:50 +00:00
func printNodeList ( list * api . NodeList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
for i := range list . Items {
r , err := printNode ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2014-10-06 01:24:19 +00:00
}
2017-07-25 04:20:50 +00:00
rows = append ( rows , r ... )
2014-10-06 01:24:19 +00:00
}
2017-07-25 04:20:50 +00:00
return rows , nil
2014-10-06 01:24:19 +00:00
}
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-07-27 07:37:18 +00:00
func printEvent ( obj * api . Event , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
row := metav1alpha1 . TableRow {
Object : runtime . RawExtension { Object : obj } ,
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 {
2017-07-27 07:37:18 +00:00
FirstTimestamp = obj . FirstTimestamp . String ( )
LastTimestamp = obj . LastTimestamp . String ( )
2015-11-10 11:34:28 +00:00
} else {
2017-07-27 07:37:18 +00:00
FirstTimestamp = translateTimestamp ( obj . FirstTimestamp )
LastTimestamp = translateTimestamp ( obj . LastTimestamp )
2015-11-10 11:34:28 +00:00
}
2017-07-27 07:37:18 +00:00
row . Cells = append ( row . Cells , LastTimestamp , FirstTimestamp ,
obj . Count , obj . Name , obj . InvolvedObject . Kind ,
obj . InvolvedObject . FieldPath , obj . Type , obj . Reason ,
formatEventSource ( obj . Source ) , obj . Message )
2015-11-10 11:34:28 +00:00
2017-07-27 07:37:18 +00:00
return [ ] metav1alpha1 . TableRow { row } , nil
2014-11-04 02:02:27 +00:00
}
2014-12-16 22:20:51 +00:00
// Sorts and prints the EventList in a human-friendly format.
2017-07-27 07:37:18 +00:00
func printEventList ( list * api . EventList , options printers . PrintOptions ) ( [ ] metav1alpha1 . TableRow , error ) {
2016-09-15 15:56:40 +00:00
sort . Sort ( events . SortableEvents ( list . Items ) )
2017-07-27 07:37:18 +00:00
rows := make ( [ ] metav1alpha1 . TableRow , 0 , len ( list . Items ) )
2014-11-04 02:02:27 +00:00
for i := range list . Items {
2017-07-27 07:37:18 +00:00
r , err := printEvent ( & list . Items [ i ] , options )
if err != nil {
return nil , err
2014-11-04 02:02:27 +00:00
}
2017-07-27 07:37:18 +00:00
rows = append ( rows , r ... )
2014-11-04 02:02:27 +00:00
}
2017-07-27 07:37:18 +00:00
return rows , nil
2014-11-04 02:02:27 +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 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 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-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
}
2017-07-25 02:50:52 +00:00
// Lay out all the containers on one line if use wide output.
2017-06-24 22:31:36 +00:00
// DEPRECATED: convert to TableHandler and use layoutContainerCells
2016-03-11 05:29:37 +00:00
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-06-24 22:31:36 +00:00
// Lay out all the containers on one line if use wide output.
func layoutContainerCells ( containers [ ] api . Container ) ( names string , images string ) {
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 ( "," )
}
}
return namesBuffer . String ( ) , imagesBuffer . String ( )
}
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 , ", " )
}
2017-05-30 23:10:56 +00:00
func printControllerRevision ( history * apps . ControllerRevision , w io . Writer , options printers . PrintOptions ) error {
name := printers . FormatResourceName ( options . Kind , history . Name , options . WithKind )
if options . WithNamespace {
if _ , err := fmt . Fprintf ( w , "%s\t" , history . Namespace ) ; err != nil {
return err
}
}
controllerRef := controller . GetControllerOf ( history )
controllerName := "<none>"
if controllerRef != nil {
withKind := true
controllerName = printers . FormatResourceName ( controllerRef . Kind , controllerRef . Name , withKind )
}
revision := history . Revision
age := translateTimestamp ( history . CreationTimestamp )
if _ , err := fmt . Fprintf ( w , "%s\t%s\t%d\t%s" , name , controllerName , revision , age ) ; err != nil {
return err
}
if _ , err := fmt . Fprint ( w , printers . AppendLabels ( history . Labels , options . ColumnLabels ) ) ; err != nil {
return err
}
_ , err := fmt . Fprint ( w , printers . AppendAllLabels ( options . ShowLabels , history . Labels ) )
return err
}
func printControllerRevisionList ( list * apps . ControllerRevisionList , w io . Writer , options printers . PrintOptions ) error {
for _ , item := range list . Items {
if err := printControllerRevision ( & item , w , options ) ; err != nil {
return err
}
}
return nil
}