mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-19 16:49:35 +00:00
Add secret table printer
This commit is contained in:
parent
9543d81bf6
commit
703af6964c
@ -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 (
|
||||||
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"}
|
||||||
persistentVolumeClaimColumns = []string{"NAME", "STATUS", "VOLUME", "CAPACITY", "ACCESSMODES", "STORAGECLASS", "AGE"}
|
persistentVolumeClaimColumns = []string{"NAME", "STATUS", "VOLUME", "CAPACITY", "ACCESSMODES", "STORAGECLASS", "AGE"}
|
||||||
@ -230,8 +229,6 @@ func AddHandlers(h printers.PrintHandler) {
|
|||||||
h.TableHandler(endpointColumnDefinitions, printEndpoints)
|
h.TableHandler(endpointColumnDefinitions, printEndpoints)
|
||||||
h.TableHandler(endpointColumnDefinitions, printEndpointsList)
|
h.TableHandler(endpointColumnDefinitions, printEndpointsList)
|
||||||
|
|
||||||
//nodeColumns = []string{"NAME", "STATUS", "AGE", "VERSION"}
|
|
||||||
//nodeWideColumns = []string{"EXTERNAL-IP", "OS-IMAGE", "KERNEL-VERSION", "CONTAINER-RUNTIME"}
|
|
||||||
nodeColumnDefinitions := []metav1alpha1.TableColumnDefinition{
|
nodeColumnDefinitions := []metav1alpha1.TableColumnDefinition{
|
||||||
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
|
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
|
||||||
{Name: "Status", Type: "string", Description: "The status of the node"},
|
{Name: "Status", Type: "string", Description: "The status of the node"},
|
||||||
@ -260,7 +257,7 @@ 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{
|
namespaceColumnDefinitions := []metav1alpha1.TableColumnDefinition{
|
||||||
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
|
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
|
||||||
{Name: "Status", Type: "string", Description: "The status of the namespace"},
|
{Name: "Status", Type: "string", Description: "The status of the namespace"},
|
||||||
@ -269,8 +266,14 @@ func AddHandlers(h printers.PrintHandler) {
|
|||||||
h.TableHandler(namespaceColumnDefinitions, printNamespace)
|
h.TableHandler(namespaceColumnDefinitions, printNamespace)
|
||||||
h.TableHandler(namespaceColumnDefinitions, printNamespaceList)
|
h.TableHandler(namespaceColumnDefinitions, printNamespaceList)
|
||||||
|
|
||||||
h.Handler(secretColumns, nil, printSecret)
|
secretColumnDefinitions := []metav1alpha1.TableColumnDefinition{
|
||||||
h.Handler(secretColumns, nil, printSecretList)
|
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
|
||||||
|
{Name: "Type", Type: "string", Description: apiv1.Secret{}.SwaggerDoc()["type"]},
|
||||||
|
{Name: "Data", Type: "string", Description: apiv1.Secret{}.SwaggerDoc()["data"]},
|
||||||
|
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
|
||||||
|
}
|
||||||
|
h.TableHandler(secretColumnDefinitions, printSecret)
|
||||||
|
h.TableHandler(secretColumnDefinitions, printSecretList)
|
||||||
h.Handler(serviceAccountColumns, nil, printServiceAccount)
|
h.Handler(serviceAccountColumns, nil, printServiceAccount)
|
||||||
h.Handler(serviceAccountColumns, nil, printServiceAccountList)
|
h.Handler(serviceAccountColumns, nil, printServiceAccountList)
|
||||||
h.Handler(persistentVolumeClaimColumns, nil, printPersistentVolumeClaim)
|
h.Handler(persistentVolumeClaimColumns, nil, printPersistentVolumeClaim)
|
||||||
@ -972,34 +975,24 @@ func printNamespaceList(list *api.NamespaceList, options printers.PrintOptions)
|
|||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printSecret(item *api.Secret, w io.Writer, options printers.PrintOptions) error {
|
func printSecret(obj *api.Secret,options printers.PrintOptions) ([]metav1alpha1.TableRow, error) {
|
||||||
name := printers.FormatResourceName(options.Kind, item.Name, options.WithKind)
|
row := metav1alpha1.TableRow{
|
||||||
|
Object: runtime.RawExtension{Object: obj},
|
||||||
namespace := item.Namespace
|
|
||||||
|
|
||||||
if options.WithNamespace {
|
|
||||||
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
row.Cells = append(row.Cells, obj.Name, obj.Type, len(obj.Data),translateTimestamp(obj.CreationTimestamp))
|
||||||
if _, err := fmt.Fprintf(w, "%s\t%s\t%v\t%s", name, item.Type, len(item.Data), translateTimestamp(item.CreationTimestamp)); err != nil {
|
return []metav1alpha1.TableRow{row}, nil
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := fmt.Fprint(w, printers.AppendLabels(item.Labels, options.ColumnLabels)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, item.Labels))
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func printSecretList(list *api.SecretList, w io.Writer, options printers.PrintOptions) error {
|
func printSecretList(list *api.SecretList, w io.Writer, options printers.PrintOptions) ([]metav1alpha1.TableRow, error) {
|
||||||
for _, item := range list.Items {
|
rows := make([]metav1alpha1.TableRow, 0, len(list.Items))
|
||||||
if err := printSecret(&item, w, options); err != nil {
|
for i := range list.Items {
|
||||||
return err
|
r, err := printSecret(&list.Items[i], options)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
rows = append(rows, r...)
|
||||||
}
|
}
|
||||||
|
return rows, nil
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func printServiceAccount(item *api.ServiceAccount, w io.Writer, options printers.PrintOptions) error {
|
func printServiceAccount(item *api.ServiceAccount, w io.Writer, options printers.PrintOptions) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user