...

Source file src/k8s.io/kubernetes/pkg/printers/storage/storage.go

Documentation: k8s.io/kubernetes/pkg/printers/storage

     1  /*
     2  Copyright 2017 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package storage
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  
    23  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    24  	"k8s.io/apimachinery/pkg/runtime"
    25  	"k8s.io/kubernetes/pkg/printers"
    26  )
    27  
    28  // TableConvertor struct - converts objects to metav1.Table using printers.TableGenerator
    29  type TableConvertor struct {
    30  	printers.TableGenerator
    31  }
    32  
    33  // ConvertToTable method - converts objects to metav1.Table objects using TableGenerator
    34  func (c TableConvertor) ConvertToTable(ctx context.Context, obj runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
    35  	noHeaders := false
    36  	if tableOptions != nil {
    37  		switch t := tableOptions.(type) {
    38  		case *metav1.TableOptions:
    39  			if t != nil {
    40  				noHeaders = t.NoHeaders
    41  			}
    42  		default:
    43  			return nil, fmt.Errorf("unrecognized type %T for table options, can't display tabular output", tableOptions)
    44  		}
    45  	}
    46  	return c.TableGenerator.GenerateTable(obj, printers.GenerateOptions{Wide: true, NoHeaders: noHeaders})
    47  }
    48  

View as plain text