Add namespace table printer
This commit is contained in:
@@ -61,7 +61,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 (
|
||||||
namespaceColumns = []string{"NAME", "STATUS", "AGE"}
|
|
||||||
secretColumns = []string{"NAME", "TYPE", "DATA", "AGE"}
|
secretColumns = []string{"NAME", "TYPE", "DATA", "AGE"}
|
||||||
serviceAccountColumns = []string{"NAME", "SECRETS", "AGE"}
|
serviceAccountColumns = []string{"NAME", "SECRETS", "AGE"}
|
||||||
persistentVolumeColumns = []string{"NAME", "CAPACITY", "ACCESSMODES", "RECLAIMPOLICY", "STATUS", "CLAIM", "STORAGECLASS", "REASON", "AGE"}
|
persistentVolumeColumns = []string{"NAME", "CAPACITY", "ACCESSMODES", "RECLAIMPOLICY", "STATUS", "CLAIM", "STORAGECLASS", "REASON", "AGE"}
|
||||||
@@ -261,9 +260,15 @@ func AddHandlers(h printers.PrintHandler) {
|
|||||||
}
|
}
|
||||||
h.TableHandler(eventColumnDefinitions, printEvent)
|
h.TableHandler(eventColumnDefinitions, printEvent)
|
||||||
h.TableHandler(eventColumnDefinitions, printEventList)
|
h.TableHandler(eventColumnDefinitions, printEventList)
|
||||||
|
//namespaceColumns = []string{"NAME", "STATUS", "AGE"}
|
||||||
|
namespaceColumnDefinitions := []metav1alpha1.TableColumnDefinition{
|
||||||
|
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
|
||||||
|
{Name: "Status", Type: "string", Description: "The status of the namespace"},
|
||||||
|
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
|
||||||
|
}
|
||||||
|
h.TableHandler(namespaceColumnDefinitions, printNamespace)
|
||||||
|
h.TableHandler(namespaceColumnDefinitions, printNamespaceList)
|
||||||
|
|
||||||
h.Handler(namespaceColumns, nil, printNamespace)
|
|
||||||
h.Handler(namespaceColumns, nil, printNamespaceList)
|
|
||||||
h.Handler(secretColumns, nil, printSecret)
|
h.Handler(secretColumns, nil, printSecret)
|
||||||
h.Handler(secretColumns, nil, printSecretList)
|
h.Handler(secretColumns, nil, printSecretList)
|
||||||
h.Handler(serviceAccountColumns, nil, printServiceAccount)
|
h.Handler(serviceAccountColumns, nil, printServiceAccount)
|
||||||
@@ -947,30 +952,24 @@ func printEndpointsList(list *api.EndpointsList, options printers.PrintOptions)
|
|||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printNamespace(item *api.Namespace, w io.Writer, options printers.PrintOptions) error {
|
func printNamespace(obj *api.Namespace, options printers.PrintOptions) ([]metav1alpha1.TableRow, error) {
|
||||||
name := printers.FormatResourceName(options.Kind, item.Name, options.WithKind)
|
row := metav1alpha1.TableRow{
|
||||||
|
Object: runtime.RawExtension{Object: obj},
|
||||||
if options.WithNamespace {
|
}
|
||||||
return fmt.Errorf("namespace is not namespaced")
|
row.Cells = append(row.Cells, obj.Name, obj.Status.Phase, translateTimestamp(obj.CreationTimestamp))
|
||||||
|
return []metav1alpha1.TableRow{row}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := fmt.Fprintf(w, "%s\t%s\t%s", name, item.Status.Phase, translateTimestamp(item.CreationTimestamp)); err != nil {
|
func printNamespaceList(list *api.NamespaceList, options printers.PrintOptions) ([]metav1alpha1.TableRow, error) {
|
||||||
return err
|
rows := make([]metav1alpha1.TableRow, 0, len(list.Items))
|
||||||
|
for i := range list.Items {
|
||||||
|
r, err := printNamespace(&list.Items[i], options)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, err := fmt.Fprint(w, printers.AppendLabels(item.Labels, options.ColumnLabels)); err != nil {
|
rows = append(rows, r...)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, item.Labels))
|
return rows, nil
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func printNamespaceList(list *api.NamespaceList, w io.Writer, options printers.PrintOptions) error {
|
|
||||||
for _, item := range list.Items {
|
|
||||||
if err := printNamespace(&item, w, options); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func printSecret(item *api.Secret, w io.Writer, options printers.PrintOptions) error {
|
func printSecret(item *api.Secret, w io.Writer, options printers.PrintOptions) error {
|
||||||
|
Reference in New Issue
Block a user