mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Add persistentVolumeClaim table printer
This commit is contained in:
parent
11b531b739
commit
c1ff87996a
@ -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 (
|
||||||
persistentVolumeClaimColumns = []string{"NAME", "STATUS", "VOLUME", "CAPACITY", "ACCESSMODES", "STORAGECLASS", "AGE"}
|
|
||||||
componentStatusColumns = []string{"NAME", "STATUS", "MESSAGE", "ERROR"}
|
componentStatusColumns = []string{"NAME", "STATUS", "MESSAGE", "ERROR"}
|
||||||
thirdPartyResourceColumns = []string{"NAME", "DESCRIPTION", "VERSION(S)"}
|
thirdPartyResourceColumns = []string{"NAME", "DESCRIPTION", "VERSION(S)"}
|
||||||
roleBindingColumns = []string{"NAME", "AGE"}
|
roleBindingColumns = []string{"NAME", "AGE"}
|
||||||
@ -295,8 +294,16 @@ func AddHandlers(h printers.PrintHandler) {
|
|||||||
h.TableHandler(persistentVolumeColumnDefinitions, printPersistentVolume)
|
h.TableHandler(persistentVolumeColumnDefinitions, printPersistentVolume)
|
||||||
h.TableHandler(persistentVolumeColumnDefinitions, printPersistentVolumeList)
|
h.TableHandler(persistentVolumeColumnDefinitions, printPersistentVolumeList)
|
||||||
|
|
||||||
h.Handler(persistentVolumeClaimColumns, nil, printPersistentVolumeClaim)
|
persistentVolumeClaimColumnDefinitions := []metav1alpha1.TableColumnDefinition{
|
||||||
h.Handler(persistentVolumeClaimColumns, nil, printPersistentVolumeClaimList)
|
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
|
||||||
|
{Name: "Status", Type: "string", Description: apiv1.PersistentVolumeClaimStatus{}.SwaggerDoc()["phase"]},
|
||||||
|
{Name: "Capacity", Type: "string", Description: apiv1.PersistentVolumeClaimStatus{}.SwaggerDoc()["capacity"]},
|
||||||
|
{Name: "AccessModes", Type: "string", Description: apiv1.PersistentVolumeClaimStatus{}.SwaggerDoc()["accessModes"]},
|
||||||
|
{Name: "StorageClass", Type: "string", Description: "StorageClass of the pvc"},
|
||||||
|
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
|
||||||
|
}
|
||||||
|
h.TableHandler(persistentVolumeClaimColumnDefinitions, printPersistentVolumeClaim)
|
||||||
|
h.TableHandler(persistentVolumeClaimColumnDefinitions, printPersistentVolumeClaimList)
|
||||||
|
|
||||||
h.Handler(componentStatusColumns, nil, printComponentStatus)
|
h.Handler(componentStatusColumns, nil, printComponentStatus)
|
||||||
h.Handler(componentStatusColumns, nil, printComponentStatusList)
|
h.Handler(componentStatusColumns, nil, printComponentStatusList)
|
||||||
@ -1139,44 +1146,35 @@ func printPersistentVolumeList(list *api.PersistentVolumeList, options printers.
|
|||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPersistentVolumeClaim(pvc *api.PersistentVolumeClaim, w io.Writer, options printers.PrintOptions) error {
|
func printPersistentVolumeClaim(obj *api.PersistentVolumeClaim, options printers.PrintOptions) ([]metav1alpha1.TableRow, error) {
|
||||||
name := printers.FormatResourceName(options.Kind, pvc.Name, options.WithKind)
|
row := metav1alpha1.TableRow{
|
||||||
|
Object: runtime.RawExtension{Object: obj},
|
||||||
namespace := pvc.Namespace
|
|
||||||
|
|
||||||
if options.WithNamespace {
|
|
||||||
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
phase := pvc.Status.Phase
|
phase := obj.Status.Phase
|
||||||
storage := pvc.Spec.Resources.Requests[api.ResourceStorage]
|
storage := obj.Spec.Resources.Requests[api.ResourceStorage]
|
||||||
capacity := ""
|
capacity := ""
|
||||||
accessModes := ""
|
accessModes := ""
|
||||||
if pvc.Spec.VolumeName != "" {
|
if obj.Spec.VolumeName != "" {
|
||||||
accessModes = helper.GetAccessModesAsString(pvc.Status.AccessModes)
|
accessModes = helper.GetAccessModesAsString(obj.Status.AccessModes)
|
||||||
storage = pvc.Status.Capacity[api.ResourceStorage]
|
storage = obj.Status.Capacity[api.ResourceStorage]
|
||||||
capacity = storage.String()
|
capacity = storage.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s", name, phase, pvc.Spec.VolumeName, capacity, accessModes, helper.GetPersistentVolumeClaimClass(pvc), translateTimestamp(pvc.CreationTimestamp)); err != nil {
|
row.Cells = append(row.Cells, obj.Name, phase, obj.Spec.VolumeName, capacity, accessModes, helper.GetPersistentVolumeClaimClass(obj), translateTimestamp(obj.CreationTimestamp))
|
||||||
return err
|
return []metav1alpha1.TableRow{row}, nil
|
||||||
}
|
|
||||||
if _, err := fmt.Fprint(w, printers.AppendLabels(pvc.Labels, options.ColumnLabels)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, pvc.Labels))
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPersistentVolumeClaimList(list *api.PersistentVolumeClaimList, w io.Writer, options printers.PrintOptions) error {
|
func printPersistentVolumeClaimList(list *api.PersistentVolumeClaimList, options printers.PrintOptions) ([]metav1alpha1.TableRow, error) {
|
||||||
for _, psd := range list.Items {
|
rows := make([]metav1alpha1.TableRow, 0, len(list.Items))
|
||||||
if err := printPersistentVolumeClaim(&psd, w, options); err != nil {
|
for i := range list.Items {
|
||||||
return err
|
r, err := printPersistentVolumeClaim(&list.Items[i], options)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
rows = append(rows, r...)
|
||||||
}
|
}
|
||||||
return nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printEvent(obj *api.Event, options printers.PrintOptions) ([]metav1alpha1.TableRow, error) {
|
func printEvent(obj *api.Event, options printers.PrintOptions) ([]metav1alpha1.TableRow, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user