mirror of https://github.com/k3s-io/k3s
fixes golint errors in pkg/printers/storage
fixes golint errors in pkg/printers fixes golint errors for pkg/printers/internalversion implements recommended changesk3s-v1.15.3
parent
8f5a62af48
commit
d97b7f20f8
|
@ -199,9 +199,6 @@ pkg/kubemark
|
|||
pkg/master
|
||||
pkg/master/controller/crdregistration
|
||||
pkg/master/tunneler
|
||||
pkg/printers
|
||||
pkg/printers/internalversion
|
||||
pkg/printers/storage
|
||||
pkg/proxy
|
||||
pkg/proxy/apis/config
|
||||
pkg/proxy/apis/config/v1alpha1
|
||||
|
|
|
@ -37,6 +37,7 @@ func (fn ResourcePrinterFunc) PrintObj(obj runtime.Object, w io.Writer) error {
|
|||
return fn(obj, w)
|
||||
}
|
||||
|
||||
// PrintOptions struct defines a struct for various print options
|
||||
type PrintOptions struct {
|
||||
// supported Format types can be found in pkg/printers/printers.go
|
||||
OutputFormatType string
|
||||
|
|
|
@ -16,9 +16,9 @@ limitations under the License.
|
|||
|
||||
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 (
|
||||
// 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/authentication/install"
|
||||
_ "k8s.io/kubernetes/pkg/apis/authorization/install"
|
||||
|
|
|
@ -706,7 +706,7 @@ func printPod(pod *api.Pod, options printers.PrintOptions) ([]metav1beta1.TableR
|
|||
for _, condition := range pod.Status.Conditions {
|
||||
if condition.Type == conditionType {
|
||||
if condition.Status == api.ConditionTrue {
|
||||
trueConditions += 1
|
||||
trueConditions++
|
||||
}
|
||||
break
|
||||
}
|
||||
|
@ -2072,6 +2072,7 @@ func printBool(value bool) string {
|
|||
return "False"
|
||||
}
|
||||
|
||||
// SortableResourceNames - An array of sortable resource names
|
||||
type SortableResourceNames []api.ResourceName
|
||||
|
||||
func (list SortableResourceNames) Len() int {
|
||||
|
|
|
@ -2866,8 +2866,8 @@ func TestPrintPodShowLabels(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPrintService(t *testing.T) {
|
||||
single_ExternalIP := []string{"80.11.12.10"}
|
||||
mul_ExternalIP := []string{"80.11.12.10", "80.11.12.11"}
|
||||
singleExternalIP := []string{"80.11.12.10"}
|
||||
mulExternalIP := []string{"80.11.12.10", "80.11.12.11"}
|
||||
tests := []struct {
|
||||
service api.Service
|
||||
expect string
|
||||
|
@ -2937,7 +2937,7 @@ func TestPrintService(t *testing.T) {
|
|||
},
|
||||
},
|
||||
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",
|
||||
|
@ -2955,7 +2955,7 @@ func TestPrintService(t *testing.T) {
|
|||
},
|
||||
},
|
||||
ClusterIP: "10.9.8.7",
|
||||
ExternalIPs: single_ExternalIP,
|
||||
ExternalIPs: singleExternalIP,
|
||||
},
|
||||
Status: api.ServiceStatus{
|
||||
LoadBalancer: api.LoadBalancerStatus{
|
||||
|
@ -2983,7 +2983,7 @@ func TestPrintService(t *testing.T) {
|
|||
},
|
||||
},
|
||||
ClusterIP: "10.9.8.7",
|
||||
ExternalIPs: mul_ExternalIP,
|
||||
ExternalIPs: mulExternalIP,
|
||||
},
|
||||
Status: api.ServiceStatus{
|
||||
LoadBalancer: api.LoadBalancerStatus{
|
||||
|
|
|
@ -25,10 +25,12 @@ import (
|
|||
"k8s.io/kubernetes/pkg/printers"
|
||||
)
|
||||
|
||||
// TableConvertor struct - converts objects to metav1beta1.Table using printers.TableGenerator
|
||||
type TableConvertor struct {
|
||||
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) {
|
||||
noHeaders := false
|
||||
if tableOptions != nil {
|
||||
|
|
|
@ -27,10 +27,12 @@ import (
|
|||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
)
|
||||
|
||||
// TableGenerator - an interface for generating metav1beta1.Table provided a runtime.Object
|
||||
type TableGenerator interface {
|
||||
GenerateTable(obj runtime.Object, options PrintOptions) (*metav1beta1.Table, error)
|
||||
}
|
||||
|
||||
// PrintHandler - interface to handle printing provided an array of metav1beta1.TableColumnDefinition
|
||||
type PrintHandler interface {
|
||||
TableHandler(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 {
|
||||
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
|
||||
|
|
|
@ -31,7 +31,6 @@ import (
|
|||
)
|
||||
|
||||
var _ ResourcePrinter = &HumanReadablePrinter{}
|
||||
|
||||
var withNamespacePrefixColumns = []string{"NAMESPACE"} // TODO(erictune): print cluster name too.
|
||||
|
||||
// NewTablePrinter creates a printer suitable for calling PrintObj().
|
||||
|
@ -45,6 +44,13 @@ func NewTablePrinter(options PrintOptions) *HumanReadablePrinter {
|
|||
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.
|
||||
func (h *HumanReadablePrinter) PrintObj(obj runtime.Object, output io.Writer) error {
|
||||
w, found := output.(*tabwriter.Writer)
|
||||
|
@ -299,13 +305,6 @@ func printRowsForHandlerEntry(output io.Writer, handler *handlerEntry, obj runti
|
|||
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.
|
||||
func printRows(output io.Writer, rows []metav1beta1.TableRow, options PrintOptions) {
|
||||
for _, row := range rows {
|
||||
|
|
|
@ -109,7 +109,7 @@ func timeoutPath(resource, namespace, name string) string {
|
|||
}
|
||||
|
||||
// Bodies for requests used in subsequent tests.
|
||||
var aPod string = `
|
||||
var aPod = `
|
||||
{
|
||||
"kind": "Pod",
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
|
@ -127,7 +127,7 @@ var aPod string = `
|
|||
}
|
||||
}
|
||||
`
|
||||
var aRC string = `
|
||||
var aRC = `
|
||||
{
|
||||
"kind": "ReplicationController",
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
|
@ -160,7 +160,7 @@ var aRC string = `
|
|||
}
|
||||
}
|
||||
`
|
||||
var aService string = `
|
||||
var aService = `
|
||||
{
|
||||
"kind": "Service",
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
|
@ -184,7 +184,7 @@ var aService string = `
|
|||
}
|
||||
}
|
||||
`
|
||||
var aNode string = `
|
||||
var aNode = `
|
||||
{
|
||||
"kind": "Node",
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
|
@ -215,7 +215,7 @@ func aEvent(namespace string) string {
|
|||
`
|
||||
}
|
||||
|
||||
var aBinding string = `
|
||||
var aBinding = `
|
||||
{
|
||||
"kind": "Binding",
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
|
@ -238,7 +238,7 @@ var emptyEndpoints = `
|
|||
}
|
||||
`
|
||||
|
||||
var aEndpoints string = `
|
||||
var aEndpoints = `
|
||||
{
|
||||
"kind": "Endpoints",
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
|
@ -263,7 +263,7 @@ var aEndpoints string = `
|
|||
}
|
||||
`
|
||||
|
||||
var deleteNow string = `
|
||||
var deleteNow = `
|
||||
{
|
||||
"kind": "DeleteOptions",
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
|
|
Loading…
Reference in New Issue