mirror of https://github.com/k3s-io/k3s
Add ingress table printer
parent
9bd1529a98
commit
d114045577
|
@ -60,7 +60,6 @@ const loadBalancerWidth = 16
|
||||||
// NOTE: When adding a new resource type here, please update the list
|
// NOTE: When adding a new resource type here, please update the list
|
||||||
// pkg/kubectl/cmd/get.go to reflect the new resource type.
|
// pkg/kubectl/cmd/get.go to reflect the new resource type.
|
||||||
var (
|
var (
|
||||||
ingressColumns = []string{"NAME", "HOSTS", "ADDRESS", "PORTS", "AGE"}
|
|
||||||
statefulSetColumns = []string{"NAME", "DESIRED", "CURRENT", "AGE"}
|
statefulSetColumns = []string{"NAME", "DESIRED", "CURRENT", "AGE"}
|
||||||
endpointColumns = []string{"NAME", "ENDPOINTS", "AGE"}
|
endpointColumns = []string{"NAME", "ENDPOINTS", "AGE"}
|
||||||
nodeColumns = []string{"NAME", "STATUS", "AGE", "VERSION"}
|
nodeColumns = []string{"NAME", "STATUS", "AGE", "VERSION"}
|
||||||
|
@ -207,8 +206,16 @@ func AddHandlers(h printers.PrintHandler) {
|
||||||
h.TableHandler(serviceColumnDefinitions, printService)
|
h.TableHandler(serviceColumnDefinitions, printService)
|
||||||
h.TableHandler(serviceColumnDefinitions, printServiceList)
|
h.TableHandler(serviceColumnDefinitions, printServiceList)
|
||||||
|
|
||||||
h.Handler(ingressColumns, nil, printIngress)
|
ingressColumnDefinitions := []metav1alpha1.TableColumnDefinition{
|
||||||
h.Handler(ingressColumns, nil, printIngressList)
|
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
|
||||||
|
{Name: "Hosts", Type: "string", Description: "Hosts that incoming requests are matched against before the ingress rule"},
|
||||||
|
{Name: "Address", Type: "string", Description: "Address is a list containing ingress points for the load-balancer"},
|
||||||
|
{Name: "Ports", Type: "string", Description: "Ports of TLS configurations that open"},
|
||||||
|
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
|
||||||
|
}
|
||||||
|
h.TableHandler(ingressColumnDefinitions, printIngress)
|
||||||
|
h.TableHandler(ingressColumnDefinitions, printIngressList)
|
||||||
|
|
||||||
h.Handler(statefulSetColumns, nil, printStatefulSet)
|
h.Handler(statefulSetColumns, nil, printStatefulSet)
|
||||||
h.Handler(statefulSetColumns, nil, printStatefulSetList)
|
h.Handler(statefulSetColumns, nil, printStatefulSetList)
|
||||||
h.Handler(endpointColumns, nil, printEndpoints)
|
h.Handler(endpointColumns, nil, printEndpoints)
|
||||||
|
@ -800,43 +807,28 @@ func formatPorts(tls []extensions.IngressTLS) string {
|
||||||
return "80"
|
return "80"
|
||||||
}
|
}
|
||||||
|
|
||||||
func printIngress(ingress *extensions.Ingress, w io.Writer, options printers.PrintOptions) error {
|
func printIngress(obj *extensions.Ingress, options printers.PrintOptions) ([]metav1alpha1.TableRow, error) {
|
||||||
name := printers.FormatResourceName(options.Kind, ingress.Name, options.WithKind)
|
row := metav1alpha1.TableRow{
|
||||||
|
Object: runtime.RawExtension{Object: obj},
|
||||||
namespace := ingress.Namespace
|
|
||||||
|
|
||||||
if options.WithNamespace {
|
|
||||||
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
hosts := formatHosts(obj.Spec.Rules)
|
||||||
if _, err := fmt.Fprintf(w, "%s\t%v\t%v\t%v\t%s",
|
address := loadBalancerStatusStringer(obj.Status.LoadBalancer, options.Wide)
|
||||||
name,
|
ports := formatPorts(obj.Spec.TLS)
|
||||||
formatHosts(ingress.Spec.Rules),
|
createTime := translateTimestamp(obj.CreationTimestamp)
|
||||||
loadBalancerStatusStringer(ingress.Status.LoadBalancer, options.Wide),
|
row.Cells = append(row.Cells, obj.Name, hosts, address, ports, createTime)
|
||||||
formatPorts(ingress.Spec.TLS),
|
return []metav1alpha1.TableRow{row}, nil
|
||||||
translateTimestamp(ingress.CreationTimestamp),
|
|
||||||
); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := fmt.Fprint(w, printers.AppendLabels(ingress.Labels, options.ColumnLabels)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, ingress.Labels)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func printIngressList(ingressList *extensions.IngressList, w io.Writer, options printers.PrintOptions) error {
|
func printIngressList(list *extensions.IngressList, options printers.PrintOptions) ([]metav1alpha1.TableRow, error) {
|
||||||
for _, ingress := range ingressList.Items {
|
rows := make([]metav1alpha1.TableRow, 0, len(list.Items))
|
||||||
if err := printIngress(&ingress, w, options); err != nil {
|
for i := range list.Items {
|
||||||
return err
|
r, err := printIngress(&list.Items[i], options)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
rows = append(rows, r...)
|
||||||
}
|
}
|
||||||
return nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printStatefulSet(ps *apps.StatefulSet, w io.Writer, options printers.PrintOptions) error {
|
func printStatefulSet(ps *apps.StatefulSet, w io.Writer, options printers.PrintOptions) error {
|
||||||
|
|
|
@ -1094,10 +1094,14 @@ func TestPrintHunmanReadableIngressWithColumnLabels(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
buff := bytes.Buffer{}
|
buff := bytes.NewBuffer([]byte{})
|
||||||
printIngress(&ingress, &buff, printers.PrintOptions{
|
table, err := printers.NewTablePrinter().With(AddHandlers).PrintTable(&ingress, printers.PrintOptions{ColumnLabels: []string{"app_name"}})
|
||||||
ColumnLabels: []string{"app_name"},
|
if err != nil {
|
||||||
})
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := printers.PrintTable(table, buff, printers.PrintOptions{NoHeaders: true}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
output := string(buff.Bytes())
|
output := string(buff.Bytes())
|
||||||
appName := ingress.ObjectMeta.Labels["app_name"]
|
appName := ingress.ObjectMeta.Labels["app_name"]
|
||||||
if !strings.Contains(output, appName) {
|
if !strings.Contains(output, appName) {
|
||||||
|
|
Loading…
Reference in New Issue