Update PrintOptions to more appropriate GenerateOptions in some cases

This commit is contained in:
Sean Sullivan 2019-08-23 09:25:22 -07:00
parent 52a9f18b07
commit 33bf8a8ebd
6 changed files with 98 additions and 114 deletions

View File

@ -36,9 +36,8 @@ type HumanPrintFlags struct {
// get.go-specific values
NoHeaders bool
Kind schema.GroupKind
AbsoluteTimestamps bool
WithNamespace bool
Kind schema.GroupKind
WithNamespace bool
}
// SetKind sets the Kind option
@ -127,10 +126,9 @@ func NewHumanPrintFlags() *HumanPrintFlags {
columnLabels := []string{}
return &HumanPrintFlags{
NoHeaders: false,
WithNamespace: false,
AbsoluteTimestamps: false,
ColumnLabels: &columnLabels,
NoHeaders: false,
WithNamespace: false,
ColumnLabels: &columnLabels,
Kind: schema.GroupKind{},
ShowLabels: &showLabels,

View File

@ -39,14 +39,13 @@ func (fn ResourcePrinterFunc) PrintObj(obj runtime.Object, w io.Writer) error {
// PrintOptions struct defines a struct for various print options
type PrintOptions struct {
NoHeaders bool
WithNamespace bool
WithKind bool
Wide bool
ShowLabels bool
AbsoluteTimestamps bool
Kind schema.GroupKind
ColumnLabels []string
NoHeaders bool
WithNamespace bool
WithKind bool
Wide bool
ShowLabels bool
Kind schema.GroupKind
ColumnLabels []string
SortBy string

View File

@ -543,7 +543,7 @@ var (
podFailedConditions = []metav1.TableRowCondition{{Type: metav1.RowCompleted, Status: metav1.ConditionTrue, Reason: string(api.PodFailed), Message: "The pod failed."}}
)
func printPodList(podList *api.PodList, options printers.PrintOptions) ([]metav1.TableRow, error) {
func printPodList(podList *api.PodList, options printers.GenerateOptions) ([]metav1.TableRow, error) {
rows := make([]metav1.TableRow, 0, len(podList.Items))
for i := range podList.Items {
r, err := printPod(&podList.Items[i], options)
@ -555,7 +555,7 @@ func printPodList(podList *api.PodList, options printers.PrintOptions) ([]metav1
return rows, nil
}
func printPod(pod *api.Pod, options printers.PrintOptions) ([]metav1.TableRow, error) {
func printPod(pod *api.Pod, options printers.GenerateOptions) ([]metav1.TableRow, error) {
restarts := 0
totalContainers := len(pod.Spec.Containers)
readyContainers := 0
@ -680,7 +680,7 @@ func printPod(pod *api.Pod, options printers.PrintOptions) ([]metav1.TableRow, e
return []metav1beta1.TableRow{row}, nil
}
func printPodTemplate(obj *api.PodTemplate, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printPodTemplate(obj *api.PodTemplate, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -689,7 +689,7 @@ func printPodTemplate(obj *api.PodTemplate, options printers.PrintOptions) ([]me
return []metav1beta1.TableRow{row}, nil
}
func printPodTemplateList(list *api.PodTemplateList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printPodTemplateList(list *api.PodTemplateList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printPodTemplate(&list.Items[i], options)
@ -701,7 +701,7 @@ func printPodTemplateList(list *api.PodTemplateList, options printers.PrintOptio
return rows, nil
}
func printPodDisruptionBudget(obj *policy.PodDisruptionBudget, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printPodDisruptionBudget(obj *policy.PodDisruptionBudget, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -724,7 +724,7 @@ func printPodDisruptionBudget(obj *policy.PodDisruptionBudget, options printers.
return []metav1beta1.TableRow{row}, nil
}
func printPodDisruptionBudgetList(list *policy.PodDisruptionBudgetList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printPodDisruptionBudgetList(list *policy.PodDisruptionBudgetList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printPodDisruptionBudget(&list.Items[i], options)
@ -737,7 +737,7 @@ func printPodDisruptionBudgetList(list *policy.PodDisruptionBudgetList, options
}
// TODO(AdoHe): try to put wide output in a single method
func printReplicationController(obj *api.ReplicationController, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printReplicationController(obj *api.ReplicationController, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -754,7 +754,7 @@ func printReplicationController(obj *api.ReplicationController, options printers
return []metav1beta1.TableRow{row}, nil
}
func printReplicationControllerList(list *api.ReplicationControllerList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printReplicationControllerList(list *api.ReplicationControllerList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printReplicationController(&list.Items[i], options)
@ -766,7 +766,7 @@ func printReplicationControllerList(list *api.ReplicationControllerList, options
return rows, nil
}
func printReplicaSet(obj *apps.ReplicaSet, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printReplicaSet(obj *apps.ReplicaSet, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -783,7 +783,7 @@ func printReplicaSet(obj *apps.ReplicaSet, options printers.PrintOptions) ([]met
return []metav1beta1.TableRow{row}, nil
}
func printReplicaSetList(list *apps.ReplicaSetList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printReplicaSetList(list *apps.ReplicaSetList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printReplicaSet(&list.Items[i], options)
@ -795,7 +795,7 @@ func printReplicaSetList(list *apps.ReplicaSetList, options printers.PrintOption
return rows, nil
}
func printJob(obj *batch.Job, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printJob(obj *batch.Job, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -831,7 +831,7 @@ func printJob(obj *batch.Job, options printers.PrintOptions) ([]metav1beta1.Tabl
return []metav1beta1.TableRow{row}, nil
}
func printJobList(list *batch.JobList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printJobList(list *batch.JobList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printJob(&list.Items[i], options)
@ -843,7 +843,7 @@ func printJobList(list *batch.JobList, options printers.PrintOptions) ([]metav1b
return rows, nil
}
func printCronJob(obj *batch.CronJob, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printCronJob(obj *batch.CronJob, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -861,7 +861,7 @@ func printCronJob(obj *batch.CronJob, options printers.PrintOptions) ([]metav1be
return []metav1beta1.TableRow{row}, nil
}
func printCronJobList(list *batch.CronJobList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printCronJobList(list *batch.CronJobList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printCronJob(&list.Items[i], options)
@ -937,7 +937,7 @@ func makePortString(ports []api.ServicePort) string {
return strings.Join(pieces, ",")
}
func printService(obj *api.Service, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printService(obj *api.Service, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -960,7 +960,7 @@ func printService(obj *api.Service, options printers.PrintOptions) ([]metav1beta
return []metav1beta1.TableRow{row}, nil
}
func printServiceList(list *api.ServiceList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printServiceList(list *api.ServiceList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printService(&list.Items[i], options)
@ -1001,7 +1001,7 @@ func formatPorts(tls []networking.IngressTLS) string {
return "80"
}
func printIngress(obj *networking.Ingress, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printIngress(obj *networking.Ingress, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1013,7 +1013,7 @@ func printIngress(obj *networking.Ingress, options printers.PrintOptions) ([]met
return []metav1beta1.TableRow{row}, nil
}
func printIngressList(list *networking.IngressList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printIngressList(list *networking.IngressList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printIngress(&list.Items[i], options)
@ -1025,7 +1025,7 @@ func printIngressList(list *networking.IngressList, options printers.PrintOption
return rows, nil
}
func printStatefulSet(obj *apps.StatefulSet, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printStatefulSet(obj *apps.StatefulSet, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1040,7 +1040,7 @@ func printStatefulSet(obj *apps.StatefulSet, options printers.PrintOptions) ([]m
return []metav1beta1.TableRow{row}, nil
}
func printStatefulSetList(list *apps.StatefulSetList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printStatefulSetList(list *apps.StatefulSetList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printStatefulSet(&list.Items[i], options)
@ -1052,7 +1052,7 @@ func printStatefulSetList(list *apps.StatefulSetList, options printers.PrintOpti
return rows, nil
}
func printDaemonSet(obj *apps.DaemonSet, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printDaemonSet(obj *apps.DaemonSet, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1071,7 +1071,7 @@ func printDaemonSet(obj *apps.DaemonSet, options printers.PrintOptions) ([]metav
return []metav1beta1.TableRow{row}, nil
}
func printDaemonSetList(list *apps.DaemonSetList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printDaemonSetList(list *apps.DaemonSetList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printDaemonSet(&list.Items[i], options)
@ -1083,7 +1083,7 @@ func printDaemonSetList(list *apps.DaemonSetList, options printers.PrintOptions)
return rows, nil
}
func printEndpoints(obj *api.Endpoints, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printEndpoints(obj *api.Endpoints, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1091,7 +1091,7 @@ func printEndpoints(obj *api.Endpoints, options printers.PrintOptions) ([]metav1
return []metav1beta1.TableRow{row}, nil
}
func printEndpointsList(list *api.EndpointsList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printEndpointsList(list *api.EndpointsList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printEndpoints(&list.Items[i], options)
@ -1103,7 +1103,7 @@ func printEndpointsList(list *api.EndpointsList, options printers.PrintOptions)
return rows, nil
}
func printNamespace(obj *api.Namespace, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printNamespace(obj *api.Namespace, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1111,7 +1111,7 @@ func printNamespace(obj *api.Namespace, options printers.PrintOptions) ([]metav1
return []metav1beta1.TableRow{row}, nil
}
func printNamespaceList(list *api.NamespaceList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printNamespaceList(list *api.NamespaceList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printNamespace(&list.Items[i], options)
@ -1123,7 +1123,7 @@ func printNamespaceList(list *api.NamespaceList, options printers.PrintOptions)
return rows, nil
}
func printSecret(obj *api.Secret, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printSecret(obj *api.Secret, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1131,7 +1131,7 @@ func printSecret(obj *api.Secret, options printers.PrintOptions) ([]metav1beta1.
return []metav1beta1.TableRow{row}, nil
}
func printSecretList(list *api.SecretList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printSecretList(list *api.SecretList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printSecret(&list.Items[i], options)
@ -1143,7 +1143,7 @@ func printSecretList(list *api.SecretList, options printers.PrintOptions) ([]met
return rows, nil
}
func printServiceAccount(obj *api.ServiceAccount, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printServiceAccount(obj *api.ServiceAccount, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1151,7 +1151,7 @@ func printServiceAccount(obj *api.ServiceAccount, options printers.PrintOptions)
return []metav1beta1.TableRow{row}, nil
}
func printServiceAccountList(list *api.ServiceAccountList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printServiceAccountList(list *api.ServiceAccountList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printServiceAccount(&list.Items[i], options)
@ -1163,7 +1163,7 @@ func printServiceAccountList(list *api.ServiceAccountList, options printers.Prin
return rows, nil
}
func printNode(obj *api.Node, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printNode(obj *api.Node, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1256,7 +1256,7 @@ func findNodeRoles(node *api.Node) []string {
return roles.List()
}
func printNodeList(list *api.NodeList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printNodeList(list *api.NodeList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printNode(&list.Items[i], options)
@ -1268,7 +1268,7 @@ func printNodeList(list *api.NodeList, options printers.PrintOptions) ([]metav1b
return rows, nil
}
func printPersistentVolume(obj *api.PersistentVolume, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printPersistentVolume(obj *api.PersistentVolume, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1301,7 +1301,7 @@ func printPersistentVolume(obj *api.PersistentVolume, options printers.PrintOpti
return []metav1beta1.TableRow{row}, nil
}
func printPersistentVolumeList(list *api.PersistentVolumeList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printPersistentVolumeList(list *api.PersistentVolumeList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printPersistentVolume(&list.Items[i], options)
@ -1313,7 +1313,7 @@ func printPersistentVolumeList(list *api.PersistentVolumeList, options printers.
return rows, nil
}
func printPersistentVolumeClaim(obj *api.PersistentVolumeClaim, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printPersistentVolumeClaim(obj *api.PersistentVolumeClaim, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1342,7 +1342,7 @@ func printPersistentVolumeClaim(obj *api.PersistentVolumeClaim, options printers
return []metav1beta1.TableRow{row}, nil
}
func printPersistentVolumeClaimList(list *api.PersistentVolumeClaimList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printPersistentVolumeClaimList(list *api.PersistentVolumeClaimList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printPersistentVolumeClaim(&list.Items[i], options)
@ -1354,19 +1354,14 @@ func printPersistentVolumeClaimList(list *api.PersistentVolumeClaimList, options
return rows, nil
}
func printEvent(obj *api.Event, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printEvent(obj *api.Event, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
// While watching event, we should print absolute time.
var firstTimestamp, lastTimestamp string
if options.AbsoluteTimestamps {
firstTimestamp = obj.FirstTimestamp.String()
lastTimestamp = obj.LastTimestamp.String()
} else {
firstTimestamp = translateTimestampSince(obj.FirstTimestamp)
lastTimestamp = translateTimestampSince(obj.LastTimestamp)
}
firstTimestamp := translateTimestampSince(obj.FirstTimestamp)
lastTimestamp := translateTimestampSince(obj.LastTimestamp)
var target string
if len(obj.InvolvedObject.Name) > 0 {
target = fmt.Sprintf("%s/%s", strings.ToLower(obj.InvolvedObject.Kind), obj.InvolvedObject.Name)
@ -1400,7 +1395,7 @@ func printEvent(obj *api.Event, options printers.PrintOptions) ([]metav1beta1.Ta
}
// Sorts and prints the EventList in a human-friendly format.
func printEventList(list *api.EventList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printEventList(list *api.EventList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printEvent(&list.Items[i], options)
@ -1412,7 +1407,7 @@ func printEventList(list *api.EventList, options printers.PrintOptions) ([]metav
return rows, nil
}
func printRoleBinding(obj *rbac.RoleBinding, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printRoleBinding(obj *rbac.RoleBinding, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1427,7 +1422,7 @@ func printRoleBinding(obj *rbac.RoleBinding, options printers.PrintOptions) ([]m
}
// Prints the RoleBinding in a human-friendly format.
func printRoleBindingList(list *rbac.RoleBindingList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printRoleBindingList(list *rbac.RoleBindingList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printRoleBinding(&list.Items[i], options)
@ -1439,7 +1434,7 @@ func printRoleBindingList(list *rbac.RoleBindingList, options printers.PrintOpti
return rows, nil
}
func printClusterRoleBinding(obj *rbac.ClusterRoleBinding, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printClusterRoleBinding(obj *rbac.ClusterRoleBinding, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1454,7 +1449,7 @@ func printClusterRoleBinding(obj *rbac.ClusterRoleBinding, options printers.Prin
}
// Prints the ClusterRoleBinding in a human-friendly format.
func printClusterRoleBindingList(list *rbac.ClusterRoleBindingList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printClusterRoleBindingList(list *rbac.ClusterRoleBindingList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printClusterRoleBinding(&list.Items[i], options)
@ -1466,7 +1461,7 @@ func printClusterRoleBindingList(list *rbac.ClusterRoleBindingList, options prin
return rows, nil
}
func printCertificateSigningRequest(obj *certificates.CertificateSigningRequest, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printCertificateSigningRequest(obj *certificates.CertificateSigningRequest, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1505,7 +1500,7 @@ func extractCSRStatus(csr *certificates.CertificateSigningRequest) (string, erro
return status, nil
}
func printCertificateSigningRequestList(list *certificates.CertificateSigningRequestList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printCertificateSigningRequestList(list *certificates.CertificateSigningRequestList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printCertificateSigningRequest(&list.Items[i], options)
@ -1517,7 +1512,7 @@ func printCertificateSigningRequestList(list *certificates.CertificateSigningReq
return rows, nil
}
func printComponentStatus(obj *api.ComponentStatus, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printComponentStatus(obj *api.ComponentStatus, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1540,7 +1535,7 @@ func printComponentStatus(obj *api.ComponentStatus, options printers.PrintOption
return []metav1beta1.TableRow{row}, nil
}
func printComponentStatusList(list *api.ComponentStatusList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printComponentStatusList(list *api.ComponentStatusList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printComponentStatus(&list.Items[i], options)
@ -1552,7 +1547,7 @@ func printComponentStatusList(list *api.ComponentStatusList, options printers.Pr
return rows, nil
}
func printDeployment(obj *apps.Deployment, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printDeployment(obj *apps.Deployment, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1575,7 +1570,7 @@ func printDeployment(obj *apps.Deployment, options printers.PrintOptions) ([]met
return []metav1beta1.TableRow{row}, nil
}
func printDeploymentList(list *apps.DeploymentList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printDeploymentList(list *apps.DeploymentList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printDeployment(&list.Items[i], options)
@ -1661,7 +1656,7 @@ func formatHPAMetrics(specs []autoscaling.MetricSpec, statuses []autoscaling.Met
return ret
}
func printHorizontalPodAutoscaler(obj *autoscaling.HorizontalPodAutoscaler, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printHorizontalPodAutoscaler(obj *autoscaling.HorizontalPodAutoscaler, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1680,7 +1675,7 @@ func printHorizontalPodAutoscaler(obj *autoscaling.HorizontalPodAutoscaler, opti
return []metav1beta1.TableRow{row}, nil
}
func printHorizontalPodAutoscalerList(list *autoscaling.HorizontalPodAutoscalerList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printHorizontalPodAutoscalerList(list *autoscaling.HorizontalPodAutoscalerList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printHorizontalPodAutoscaler(&list.Items[i], options)
@ -1692,7 +1687,7 @@ func printHorizontalPodAutoscalerList(list *autoscaling.HorizontalPodAutoscalerL
return rows, nil
}
func printConfigMap(obj *api.ConfigMap, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printConfigMap(obj *api.ConfigMap, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1700,7 +1695,7 @@ func printConfigMap(obj *api.ConfigMap, options printers.PrintOptions) ([]metav1
return []metav1beta1.TableRow{row}, nil
}
func printConfigMapList(list *api.ConfigMapList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printConfigMapList(list *api.ConfigMapList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printConfigMap(&list.Items[i], options)
@ -1712,7 +1707,7 @@ func printConfigMapList(list *api.ConfigMapList, options printers.PrintOptions)
return rows, nil
}
func printPodSecurityPolicy(obj *policy.PodSecurityPolicy, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printPodSecurityPolicy(obj *policy.PodSecurityPolicy, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1733,7 +1728,7 @@ func printPodSecurityPolicy(obj *policy.PodSecurityPolicy, options printers.Prin
return []metav1beta1.TableRow{row}, nil
}
func printPodSecurityPolicyList(list *policy.PodSecurityPolicyList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printPodSecurityPolicyList(list *policy.PodSecurityPolicyList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printPodSecurityPolicy(&list.Items[i], options)
@ -1745,7 +1740,7 @@ func printPodSecurityPolicyList(list *policy.PodSecurityPolicyList, options prin
return rows, nil
}
func printNetworkPolicy(obj *networking.NetworkPolicy, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printNetworkPolicy(obj *networking.NetworkPolicy, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1753,7 +1748,7 @@ func printNetworkPolicy(obj *networking.NetworkPolicy, options printers.PrintOpt
return []metav1beta1.TableRow{row}, nil
}
func printNetworkPolicyList(list *networking.NetworkPolicyList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printNetworkPolicyList(list *networking.NetworkPolicyList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printNetworkPolicy(&list.Items[i], options)
@ -1765,7 +1760,7 @@ func printNetworkPolicyList(list *networking.NetworkPolicyList, options printers
return rows, nil
}
func printStorageClass(obj *storage.StorageClass, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printStorageClass(obj *storage.StorageClass, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1780,7 +1775,7 @@ func printStorageClass(obj *storage.StorageClass, options printers.PrintOptions)
return []metav1beta1.TableRow{row}, nil
}
func printStorageClassList(list *storage.StorageClassList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printStorageClassList(list *storage.StorageClassList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printStorageClass(&list.Items[i], options)
@ -1792,7 +1787,7 @@ func printStorageClassList(list *storage.StorageClassList, options printers.Prin
return rows, nil
}
func printLease(obj *coordination.Lease, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printLease(obj *coordination.Lease, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1805,7 +1800,7 @@ func printLease(obj *coordination.Lease, options printers.PrintOptions) ([]metav
return []metav1beta1.TableRow{row}, nil
}
func printLeaseList(list *coordination.LeaseList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printLeaseList(list *coordination.LeaseList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printLease(&list.Items[i], options)
@ -1817,7 +1812,7 @@ func printLeaseList(list *coordination.LeaseList, options printers.PrintOptions)
return rows, nil
}
func printStatus(obj *metav1.Status, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printStatus(obj *metav1.Status, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1851,7 +1846,7 @@ func formatEventSource(es api.EventSource) string {
return strings.Join(EventSourceString, ", ")
}
func printControllerRevision(obj *apps.ControllerRevision, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printControllerRevision(obj *apps.ControllerRevision, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1873,7 +1868,7 @@ func printControllerRevision(obj *apps.ControllerRevision, options printers.Prin
return []metav1beta1.TableRow{row}, nil
}
func printControllerRevisionList(list *apps.ControllerRevisionList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printControllerRevisionList(list *apps.ControllerRevisionList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printControllerRevision(&list.Items[i], options)
@ -1895,7 +1890,7 @@ func formatResourceName(kind schema.GroupKind, name string, withKind bool) strin
return strings.ToLower(kind.String()) + "/" + name
}
func printResourceQuota(resourceQuota *api.ResourceQuota, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printResourceQuota(resourceQuota *api.ResourceQuota, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: resourceQuota},
}
@ -1927,7 +1922,7 @@ func printResourceQuota(resourceQuota *api.ResourceQuota, options printers.Print
return []metav1beta1.TableRow{row}, nil
}
func printResourceQuotaList(list *api.ResourceQuotaList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printResourceQuotaList(list *api.ResourceQuotaList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printResourceQuota(&list.Items[i], options)
@ -1939,7 +1934,7 @@ func printResourceQuotaList(list *api.ResourceQuotaList, options printers.PrintO
return rows, nil
}
func printPriorityClass(obj *scheduling.PriorityClass, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printPriorityClass(obj *scheduling.PriorityClass, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1952,7 +1947,7 @@ func printPriorityClass(obj *scheduling.PriorityClass, options printers.PrintOpt
return []metav1beta1.TableRow{row}, nil
}
func printPriorityClassList(list *scheduling.PriorityClassList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printPriorityClassList(list *scheduling.PriorityClassList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printPriorityClass(&list.Items[i], options)
@ -1964,7 +1959,7 @@ func printPriorityClassList(list *scheduling.PriorityClassList, options printers
return rows, nil
}
func printRuntimeClass(obj *nodeapi.RuntimeClass, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printRuntimeClass(obj *nodeapi.RuntimeClass, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -1976,7 +1971,7 @@ func printRuntimeClass(obj *nodeapi.RuntimeClass, options printers.PrintOptions)
return []metav1beta1.TableRow{row}, nil
}
func printRuntimeClassList(list *nodeapi.RuntimeClassList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printRuntimeClassList(list *nodeapi.RuntimeClassList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printRuntimeClass(&list.Items[i], options)
@ -1989,7 +1984,7 @@ func printRuntimeClassList(list *nodeapi.RuntimeClassList, options printers.Prin
return rows, nil
}
func printVolumeAttachment(obj *storage.VolumeAttachment, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printVolumeAttachment(obj *storage.VolumeAttachment, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: obj},
}
@ -2004,7 +1999,7 @@ func printVolumeAttachment(obj *storage.VolumeAttachment, options printers.Print
return []metav1beta1.TableRow{row}, nil
}
func printVolumeAttachmentList(list *storage.VolumeAttachmentList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func printVolumeAttachmentList(list *storage.VolumeAttachmentList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(list.Items))
for i := range list.Items {
r, err := printVolumeAttachment(&list.Items[i], options)

View File

@ -286,16 +286,11 @@ func TestFormatResourceName(t *testing.T) {
}
}
func PrintCustomType(obj *TestPrintType, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
data := obj.Data
kind := options.Kind
if options.WithKind {
data = kind.String() + "/" + data
}
return []metav1beta1.TableRow{{Cells: []interface{}{data}}}, nil
func PrintCustomType(obj *TestPrintType, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
return []metav1beta1.TableRow{{Cells: []interface{}{obj.Data}}}, nil
}
func ErrorPrintHandler(obj *TestPrintType, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
func ErrorPrintHandler(obj *TestPrintType, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) {
return nil, fmt.Errorf("ErrorPrintHandler error")
}
@ -1634,7 +1629,7 @@ func TestPrintPod(t *testing.T) {
}
for i, test := range tests {
rows, err := printPod(&test.pod, printers.PrintOptions{})
rows, err := printPod(&test.pod, printers.GenerateOptions{})
if err != nil {
t.Fatal(err)
}
@ -1758,7 +1753,7 @@ func TestPrintPodwide(t *testing.T) {
}
for i, test := range tests {
rows, err := printPod(&test.pod, printers.PrintOptions{Wide: true})
rows, err := printPod(&test.pod, printers.GenerateOptions{Wide: true})
if err != nil {
t.Fatal(err)
}
@ -1808,7 +1803,7 @@ func TestPrintPodList(t *testing.T) {
}
for _, test := range tests {
rows, err := printPodList(&test.pods, printers.PrintOptions{})
rows, err := printPodList(&test.pods, printers.GenerateOptions{})
if err != nil {
t.Fatal(err)

View File

@ -84,8 +84,7 @@ func (h *HumanReadableGenerator) GenerateTable(obj runtime.Object, options Gener
return nil, fmt.Errorf("no table handler registered for this type %v", t)
}
printOptions := PrintOptions{NoHeaders: options.NoHeaders, Wide: options.Wide}
args := []reflect.Value{reflect.ValueOf(obj), reflect.ValueOf(printOptions)}
args := []reflect.Value{reflect.ValueOf(obj), reflect.ValueOf(options)}
results := handler.printFunc.Call(args)
if !results[1].IsNil() {
return nil, results[1].Interface().(error)
@ -151,7 +150,7 @@ func (h *HumanReadableGenerator) TableHandler(columnDefinitions []metav1beta1.Ta
// ValidateRowPrintHandlerFunc validates print handler signature.
// printFunc is the function that will be called to print an object.
// It must be of the following type:
// func printFunc(object ObjectType, options PrintOptions) ([]metav1beta1.TableRow, error)
// func printFunc(object ObjectType, options GenerateOptions) ([]metav1beta1.TableRow, error)
// where ObjectType is the type of the object that will be printed, and the first
// return value is an array of rows, with each row containing a number of cells that
// match the number of columns defined for that printer function.
@ -164,11 +163,11 @@ func ValidateRowPrintHandlerFunc(printFunc reflect.Value) error {
return fmt.Errorf("invalid print handler." +
"Must accept 2 parameters and return 2 value.")
}
if funcType.In(1) != reflect.TypeOf((*PrintOptions)(nil)).Elem() ||
if funcType.In(1) != reflect.TypeOf((*GenerateOptions)(nil)).Elem() ||
funcType.Out(0) != reflect.TypeOf((*[]metav1beta1.TableRow)(nil)).Elem() ||
funcType.Out(1) != reflect.TypeOf((*error)(nil)).Elem() {
return fmt.Errorf("invalid print handler. The expected signature is: "+
"func handler(obj %v, options PrintOptions) ([]metav1beta1.TableRow, error)", funcType.In(0))
"func handler(obj %v, options GenerateOptions) ([]metav1beta1.TableRow, error)", funcType.In(0))
}
return nil
}

View File

@ -73,9 +73,7 @@ type HumanReadablePrinter struct {
}
// NewTablePrinter creates a printer suitable for calling PrintObj().
// TODO(seans3): Change return type to ResourcePrinter interface once we no longer need
// to constuct the "handlerMap".
func NewTablePrinter(options PrintOptions) *HumanReadablePrinter {
func NewTablePrinter(options PrintOptions) ResourcePrinter {
printer := &HumanReadablePrinter{
options: options,
}