@@ -17,7 +17,6 @@ limitations under the License.
17
17
package printers
18
18
19
19
import (
20
- "bytes"
21
20
"fmt"
22
21
"io"
23
22
"reflect"
@@ -30,7 +29,6 @@ import (
30
29
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
31
30
"k8s.io/apimachinery/pkg/labels"
32
31
"k8s.io/apimachinery/pkg/runtime"
33
- "k8s.io/apimachinery/pkg/runtime/schema"
34
32
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
35
33
)
36
34
@@ -88,15 +86,6 @@ func (a *HumanReadablePrinter) With(fns ...func(PrintHandler)) *HumanReadablePri
88
86
return a
89
87
}
90
88
91
- // EnsurePrintHeaders sets the HumanReadablePrinter option "NoHeaders" to false
92
- // and removes the .lastType that was printed, which forces headers to be
93
- // printed in cases where multiple lists of the same resource are printed
94
- // consecutively, but are separated by non-printer related information.
95
- func (h * HumanReadablePrinter ) EnsurePrintHeaders () {
96
- h .options .NoHeaders = false
97
- h .lastType = nil
98
- }
99
-
100
89
// TableHandler adds a print handler with a given set of columns to HumanReadablePrinter instance.
101
90
// See ValidateRowPrintHandlerFunc for required method signature.
102
91
func (h * HumanReadablePrinter ) TableHandler (columnDefinitions []metav1beta1.TableColumnDefinition , printFunc interface {}) error {
@@ -163,51 +152,6 @@ func ValidateRowPrintHandlerFunc(printFunc reflect.Value) error {
163
152
return nil
164
153
}
165
154
166
- // ValidatePrintHandlerFunc validates print handler signature.
167
- // printFunc is the function that will be called to print an object.
168
- // It must be of the following type:
169
- // func printFunc(object ObjectType, w io.Writer, options PrintOptions) error
170
- // where ObjectType is the type of the object that will be printed.
171
- // DEPRECATED: will be replaced with ValidateRowPrintHandlerFunc
172
- func ValidatePrintHandlerFunc (printFunc reflect.Value ) error {
173
- if printFunc .Kind () != reflect .Func {
174
- return fmt .Errorf ("invalid print handler. %#v is not a function" , printFunc )
175
- }
176
- funcType := printFunc .Type ()
177
- if funcType .NumIn () != 3 || funcType .NumOut () != 1 {
178
- return fmt .Errorf ("invalid print handler." +
179
- "Must accept 3 parameters and return 1 value." )
180
- }
181
- if funcType .In (1 ) != reflect .TypeOf ((* io .Writer )(nil )).Elem () ||
182
- funcType .In (2 ) != reflect .TypeOf ((* PrintOptions )(nil )).Elem () ||
183
- funcType .Out (0 ) != reflect .TypeOf ((* error )(nil )).Elem () {
184
- return fmt .Errorf ("invalid print handler. The expected signature is: " +
185
- "func handler(obj %v, w io.Writer, options PrintOptions) error" , funcType .In (0 ))
186
- }
187
- return nil
188
- }
189
-
190
- func (h * HumanReadablePrinter ) HandledResources () []string {
191
- keys := make ([]string , 0 )
192
-
193
- for k := range h .handlerMap {
194
- // k.String looks like "*api.PodList" and we want just "pod"
195
- api := strings .Split (k .String (), "." )
196
- resource := api [len (api )- 1 ]
197
- if strings .HasSuffix (resource , "List" ) {
198
- continue
199
- }
200
- resource = strings .ToLower (resource )
201
- keys = append (keys , resource )
202
- }
203
- return keys
204
- }
205
-
206
- func (h * HumanReadablePrinter ) unknown (data []byte , w io.Writer ) error {
207
- _ , err := fmt .Fprintf (w , "Unknown object: %s" , string (data ))
208
- return err
209
- }
210
-
211
155
func printHeader (columnNames []string , w io.Writer ) error {
212
156
if _ , err := fmt .Fprintf (w , "%s\n " , strings .Join (columnNames , "\t " )); err != nil {
213
157
return err
@@ -283,15 +227,6 @@ func (h *HumanReadablePrinter) PrintObj(obj runtime.Object, output io.Writer) er
283
227
return fmt .Errorf ("error: unknown type %#v" , obj )
284
228
}
285
229
286
- func hasCondition (conditions []metav1beta1.TableRowCondition , t metav1beta1.RowConditionType ) bool {
287
- for _ , condition := range conditions {
288
- if condition .Type == t {
289
- return condition .Status == metav1beta1 .ConditionTrue
290
- }
291
- }
292
- return false
293
- }
294
-
295
230
// PrintTable prints a table to the provided output respecting the filtering rules for options
296
231
// for wide columns and filtered rows. It filters out rows that are Completed. You should call
297
232
// DecorateTable if you receive a table from a remote server before calling PrintTable.
@@ -565,65 +500,6 @@ func printRows(output io.Writer, rows []metav1beta1.TableRow, options PrintOptio
565
500
}
566
501
}
567
502
568
- // TODO: this method assumes the meta/v1 server API, so should be refactored out of this package
569
- func printUnstructured (unstructured runtime.Unstructured , w io.Writer , additionalFields []string , options PrintOptions ) error {
570
- metadata , err := meta .Accessor (unstructured )
571
- if err != nil {
572
- return err
573
- }
574
-
575
- if options .WithNamespace {
576
- if _ , err := fmt .Fprintf (w , "%s\t " , metadata .GetNamespace ()); err != nil {
577
- return err
578
- }
579
- }
580
-
581
- content := unstructured .UnstructuredContent ()
582
- kind := "<missing>"
583
- if objKind , ok := content ["kind" ]; ok {
584
- if str , ok := objKind .(string ); ok {
585
- kind = str
586
- }
587
- }
588
- if objAPIVersion , ok := content ["apiVersion" ]; ok {
589
- if str , ok := objAPIVersion .(string ); ok {
590
- version , err := schema .ParseGroupVersion (str )
591
- if err != nil {
592
- return err
593
- }
594
- kind = kind + "." + version .Version + "." + version .Group
595
- }
596
- }
597
-
598
- name := FormatResourceName (options .Kind , metadata .GetName (), options .WithKind )
599
-
600
- if _ , err := fmt .Fprintf (w , "%s\t %s" , name , kind ); err != nil {
601
- return err
602
- }
603
- for _ , field := range additionalFields {
604
- if value , ok := content [field ]; ok {
605
- var formattedValue string
606
- switch typedValue := value .(type ) {
607
- case []interface {}:
608
- formattedValue = fmt .Sprintf ("%d item(s)" , len (typedValue ))
609
- default :
610
- formattedValue = fmt .Sprintf ("%v" , value )
611
- }
612
- if _ , err := fmt .Fprintf (w , "\t %s" , formattedValue ); err != nil {
613
- return err
614
- }
615
- }
616
- }
617
- if _ , err := fmt .Fprint (w , AppendLabels (metadata .GetLabels (), options .ColumnLabels )); err != nil {
618
- return err
619
- }
620
- if _ , err := fmt .Fprint (w , AppendAllLabels (options .ShowLabels , metadata .GetLabels ())); err != nil {
621
- return err
622
- }
623
-
624
- return nil
625
- }
626
-
627
503
func formatLabelHeaders (columnLabels []string ) []string {
628
504
formHead := make ([]string , len (columnLabels ))
629
505
for i , l := range columnLabels {
@@ -664,42 +540,3 @@ func appendLabelCells(values []interface{}, itemLabels map[string]string, opts P
664
540
}
665
541
return values
666
542
}
667
-
668
- // FormatResourceName receives a resource kind, name, and boolean specifying
669
- // whether or not to update the current name to "kind/name"
670
- func FormatResourceName (kind schema.GroupKind , name string , withKind bool ) string {
671
- if ! withKind || kind .Empty () {
672
- return name
673
- }
674
-
675
- return strings .ToLower (kind .String ()) + "/" + name
676
- }
677
-
678
- func AppendLabels (itemLabels map [string ]string , columnLabels []string ) string {
679
- var buffer bytes.Buffer
680
-
681
- for _ , cl := range columnLabels {
682
- buffer .WriteString (fmt .Sprint ("\t " ))
683
- if il , ok := itemLabels [cl ]; ok {
684
- buffer .WriteString (fmt .Sprint (il ))
685
- } else {
686
- buffer .WriteString ("<none>" )
687
- }
688
- }
689
-
690
- return buffer .String ()
691
- }
692
-
693
- // Append all labels to a single column. We need this even when show-labels flag* is
694
- // false, since this adds newline delimiter to the end of each row.
695
- func AppendAllLabels (showLabels bool , itemLabels map [string ]string ) string {
696
- var buffer bytes.Buffer
697
-
698
- if showLabels {
699
- buffer .WriteString (fmt .Sprint ("\t " ))
700
- buffer .WriteString (labels .FormatLabels (itemLabels ))
701
- }
702
- buffer .WriteString ("\n " )
703
-
704
- return buffer .String ()
705
- }
0 commit comments