Merge pull request #76771 from baasbank/fix-lint-errors-pkg/printer

Fix lint errors pkg/printer
This commit is contained in:
Kubernetes Prow Robot 2019-05-01 10:50:58 -07:00 committed by GitHub
commit 0207363445
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 29 deletions

View File

@ -199,9 +199,6 @@ pkg/kubemark
pkg/master pkg/master
pkg/master/controller/crdregistration pkg/master/controller/crdregistration
pkg/master/tunneler pkg/master/tunneler
pkg/printers
pkg/printers/internalversion
pkg/printers/storage
pkg/proxy pkg/proxy
pkg/proxy/apis/config pkg/proxy/apis/config
pkg/proxy/apis/config/v1alpha1 pkg/proxy/apis/config/v1alpha1

View File

@ -37,6 +37,7 @@ func (fn ResourcePrinterFunc) PrintObj(obj runtime.Object, w io.Writer) error {
return fn(obj, w) return fn(obj, w)
} }
// PrintOptions struct defines a struct for various print options
type PrintOptions struct { type PrintOptions struct {
// supported Format types can be found in pkg/printers/printers.go // supported Format types can be found in pkg/printers/printers.go
OutputFormatType string OutputFormatType string

View File

@ -16,9 +16,9 @@ limitations under the License.
package internalversion package internalversion
// These imports are the API groups the client will support.
// TODO: Remove these manual install once we don't need legacy scheme in get comman
import ( import (
// These imports are the API groups the client will support.
// TODO: Remove these manual install once we don't need legacy scheme in get comman
_ "k8s.io/kubernetes/pkg/apis/apps/install" _ "k8s.io/kubernetes/pkg/apis/apps/install"
_ "k8s.io/kubernetes/pkg/apis/authentication/install" _ "k8s.io/kubernetes/pkg/apis/authentication/install"
_ "k8s.io/kubernetes/pkg/apis/authorization/install" _ "k8s.io/kubernetes/pkg/apis/authorization/install"

View File

@ -706,7 +706,7 @@ func printPod(pod *api.Pod, options printers.PrintOptions) ([]metav1beta1.TableR
for _, condition := range pod.Status.Conditions { for _, condition := range pod.Status.Conditions {
if condition.Type == conditionType { if condition.Type == conditionType {
if condition.Status == api.ConditionTrue { if condition.Status == api.ConditionTrue {
trueConditions += 1 trueConditions++
} }
break break
} }
@ -2072,6 +2072,7 @@ func printBool(value bool) string {
return "False" return "False"
} }
// SortableResourceNames - An array of sortable resource names
type SortableResourceNames []api.ResourceName type SortableResourceNames []api.ResourceName
func (list SortableResourceNames) Len() int { func (list SortableResourceNames) Len() int {

View File

@ -2866,8 +2866,8 @@ func TestPrintPodShowLabels(t *testing.T) {
} }
func TestPrintService(t *testing.T) { func TestPrintService(t *testing.T) {
single_ExternalIP := []string{"80.11.12.10"} singleExternalIP := []string{"80.11.12.10"}
mul_ExternalIP := []string{"80.11.12.10", "80.11.12.11"} mulExternalIP := []string{"80.11.12.10", "80.11.12.11"}
tests := []struct { tests := []struct {
service api.Service service api.Service
expect string expect string
@ -2937,7 +2937,7 @@ func TestPrintService(t *testing.T) {
}, },
}, },
ClusterIP: "10.9.8.7", ClusterIP: "10.9.8.7",
ExternalIPs: single_ExternalIP, ExternalIPs: singleExternalIP,
}, },
}, },
"test4\tLoadBalancer\t10.9.8.7\t80.11.12.10\t8888/tcp\t<unknown>\n", "test4\tLoadBalancer\t10.9.8.7\t80.11.12.10\t8888/tcp\t<unknown>\n",
@ -2955,7 +2955,7 @@ func TestPrintService(t *testing.T) {
}, },
}, },
ClusterIP: "10.9.8.7", ClusterIP: "10.9.8.7",
ExternalIPs: single_ExternalIP, ExternalIPs: singleExternalIP,
}, },
Status: api.ServiceStatus{ Status: api.ServiceStatus{
LoadBalancer: api.LoadBalancerStatus{ LoadBalancer: api.LoadBalancerStatus{
@ -2983,7 +2983,7 @@ func TestPrintService(t *testing.T) {
}, },
}, },
ClusterIP: "10.9.8.7", ClusterIP: "10.9.8.7",
ExternalIPs: mul_ExternalIP, ExternalIPs: mulExternalIP,
}, },
Status: api.ServiceStatus{ Status: api.ServiceStatus{
LoadBalancer: api.LoadBalancerStatus{ LoadBalancer: api.LoadBalancerStatus{

View File

@ -25,10 +25,12 @@ import (
"k8s.io/kubernetes/pkg/printers" "k8s.io/kubernetes/pkg/printers"
) )
// TableConvertor struct - converts objects to metav1beta1.Table using printers.TableGenerator
type TableConvertor struct { type TableConvertor struct {
printers.TableGenerator printers.TableGenerator
} }
// ConvertToTable method - converts objects to metav1beta1.Table objects using TableGenerator
func (c TableConvertor) ConvertToTable(ctx context.Context, obj runtime.Object, tableOptions runtime.Object) (*metav1beta1.Table, error) { func (c TableConvertor) ConvertToTable(ctx context.Context, obj runtime.Object, tableOptions runtime.Object) (*metav1beta1.Table, error) {
noHeaders := false noHeaders := false
if tableOptions != nil { if tableOptions != nil {

View File

@ -27,10 +27,12 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime"
) )
// TableGenerator - an interface for generating metav1beta1.Table provided a runtime.Object
type TableGenerator interface { type TableGenerator interface {
GenerateTable(obj runtime.Object, options PrintOptions) (*metav1beta1.Table, error) GenerateTable(obj runtime.Object, options PrintOptions) (*metav1beta1.Table, error)
} }
// PrintHandler - interface to handle printing provided an array of metav1beta1.TableColumnDefinition
type PrintHandler interface { type PrintHandler interface {
TableHandler(columns []metav1beta1.TableColumnDefinition, printFunc interface{}) error TableHandler(columns []metav1beta1.TableColumnDefinition, printFunc interface{}) error
DefaultTableHandler(columns []metav1beta1.TableColumnDefinition, printFunc interface{}) error DefaultTableHandler(columns []metav1beta1.TableColumnDefinition, printFunc interface{}) error
@ -64,11 +66,12 @@ func NewTableGenerator() *HumanReadablePrinter {
} }
} }
func (a *HumanReadablePrinter) With(fns ...func(PrintHandler)) *HumanReadablePrinter { // With method - accepts a list of builder functions that modify HumanReadablePrinter
func (h *HumanReadablePrinter) With(fns ...func(PrintHandler)) *HumanReadablePrinter {
for _, fn := range fns { for _, fn := range fns {
fn(a) fn(h)
} }
return a return h
} }
// GenerateTable returns a table for the provided object, using the printer registered for that type. It returns // GenerateTable returns a table for the provided object, using the printer registered for that type. It returns

View File

@ -31,7 +31,6 @@ import (
) )
var _ ResourcePrinter = &HumanReadablePrinter{} var _ ResourcePrinter = &HumanReadablePrinter{}
var withNamespacePrefixColumns = []string{"NAMESPACE"} // TODO(erictune): print cluster name too. var withNamespacePrefixColumns = []string{"NAMESPACE"} // TODO(erictune): print cluster name too.
// NewTablePrinter creates a printer suitable for calling PrintObj(). // NewTablePrinter creates a printer suitable for calling PrintObj().
@ -45,6 +44,13 @@ func NewTablePrinter(options PrintOptions) *HumanReadablePrinter {
return printer return printer
} }
func printHeader(columnNames []string, w io.Writer) error {
if _, err := fmt.Fprintf(w, "%s\n", strings.Join(columnNames, "\t")); err != nil {
return err
}
return nil
}
// PrintObj prints the obj in a human-friendly format according to the type of the obj. // PrintObj prints the obj in a human-friendly format according to the type of the obj.
func (h *HumanReadablePrinter) PrintObj(obj runtime.Object, output io.Writer) error { func (h *HumanReadablePrinter) PrintObj(obj runtime.Object, output io.Writer) error {
w, found := output.(*tabwriter.Writer) w, found := output.(*tabwriter.Writer)
@ -299,13 +305,6 @@ func printRowsForHandlerEntry(output io.Writer, handler *handlerEntry, obj runti
return results[1].Interface().(error) return results[1].Interface().(error)
} }
func printHeader(columnNames []string, w io.Writer) error {
if _, err := fmt.Fprintf(w, "%s\n", strings.Join(columnNames, "\t")); err != nil {
return err
}
return nil
}
// printRows writes the provided rows to output. // printRows writes the provided rows to output.
func printRows(output io.Writer, rows []metav1beta1.TableRow, options PrintOptions) { func printRows(output io.Writer, rows []metav1beta1.TableRow, options PrintOptions) {
for _, row := range rows { for _, row := range rows {

View File

@ -109,7 +109,7 @@ func timeoutPath(resource, namespace, name string) string {
} }
// Bodies for requests used in subsequent tests. // Bodies for requests used in subsequent tests.
var aPod string = ` var aPod = `
{ {
"kind": "Pod", "kind": "Pod",
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `", "apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
@ -127,7 +127,7 @@ var aPod string = `
} }
} }
` `
var aRC string = ` var aRC = `
{ {
"kind": "ReplicationController", "kind": "ReplicationController",
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `", "apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
@ -160,7 +160,7 @@ var aRC string = `
} }
} }
` `
var aService string = ` var aService = `
{ {
"kind": "Service", "kind": "Service",
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `", "apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
@ -184,7 +184,7 @@ var aService string = `
} }
} }
` `
var aNode string = ` var aNode = `
{ {
"kind": "Node", "kind": "Node",
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `", "apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
@ -215,7 +215,7 @@ func aEvent(namespace string) string {
` `
} }
var aBinding string = ` var aBinding = `
{ {
"kind": "Binding", "kind": "Binding",
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `", "apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
@ -238,7 +238,7 @@ var emptyEndpoints = `
} }
` `
var aEndpoints string = ` var aEndpoints = `
{ {
"kind": "Endpoints", "kind": "Endpoints",
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `", "apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
@ -263,7 +263,7 @@ var aEndpoints string = `
} }
` `
var deleteNow string = ` var deleteNow = `
{ {
"kind": "DeleteOptions", "kind": "DeleteOptions",
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `", "apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",