mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
Add Node table printer
This commit is contained in:
parent
dc5a8ec829
commit
4d5417ad7f
@ -61,8 +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 (
|
||||||
nodeColumns = []string{"NAME", "STATUS", "AGE", "VERSION"}
|
|
||||||
nodeWideColumns = []string{"EXTERNAL-IP", "OS-IMAGE", "KERNEL-VERSION", "CONTAINER-RUNTIME"}
|
|
||||||
eventColumns = []string{"LASTSEEN", "FIRSTSEEN", "COUNT", "NAME", "KIND", "SUBOBJECT", "TYPE", "REASON", "SOURCE", "MESSAGE"}
|
eventColumns = []string{"LASTSEEN", "FIRSTSEEN", "COUNT", "NAME", "KIND", "SUBOBJECT", "TYPE", "REASON", "SOURCE", "MESSAGE"}
|
||||||
namespaceColumns = []string{"NAME", "STATUS", "AGE"}
|
namespaceColumns = []string{"NAME", "STATUS", "AGE"}
|
||||||
secretColumns = []string{"NAME", "TYPE", "DATA", "AGE"}
|
secretColumns = []string{"NAME", "TYPE", "DATA", "AGE"}
|
||||||
@ -234,8 +232,22 @@ func AddHandlers(h printers.PrintHandler) {
|
|||||||
h.TableHandler(endpointColumnDefinitions, printEndpoints)
|
h.TableHandler(endpointColumnDefinitions, printEndpoints)
|
||||||
h.TableHandler(endpointColumnDefinitions, printEndpointsList)
|
h.TableHandler(endpointColumnDefinitions, printEndpointsList)
|
||||||
|
|
||||||
h.Handler(nodeColumns, nodeWideColumns, printNode)
|
//nodeColumns = []string{"NAME", "STATUS", "AGE", "VERSION"}
|
||||||
h.Handler(nodeColumns, nodeWideColumns, printNodeList)
|
//nodeWideColumns = []string{"EXTERNAL-IP", "OS-IMAGE", "KERNEL-VERSION", "CONTAINER-RUNTIME"}
|
||||||
|
nodeColumnDefinitions := []metav1alpha1.TableColumnDefinition{
|
||||||
|
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
|
||||||
|
{Name: "Status", Type: "string", Description: "The status of the node"},
|
||||||
|
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
|
||||||
|
{Name: "Version", Type: "string", Description: apiv1.NodeSystemInfo{}.SwaggerDoc()["kubeletVersion"]},
|
||||||
|
{Name: "External-IP", Type: "string", Priority: 1, Description: apiv1.NodeStatus{}.SwaggerDoc()["addresses"]},
|
||||||
|
{Name: "OS-Image", Type: "string", Priority: 1, Description: apiv1.NodeSystemInfo{}.SwaggerDoc()["osImage"]},
|
||||||
|
{Name: "Kernel-Version", Type: "string", Priority: 1, Description: apiv1.NodeSystemInfo{}.SwaggerDoc()["kernelVersion"]},
|
||||||
|
{Name: "Container-Runtime", Type: "string", Priority: 1, Description: apiv1.NodeSystemInfo{}.SwaggerDoc()["containerRuntimeVersion"]},
|
||||||
|
}
|
||||||
|
|
||||||
|
h.TableHandler(nodeColumnDefinitions, printNode)
|
||||||
|
h.TableHandler(nodeColumnDefinitions, printNodeList)
|
||||||
|
|
||||||
h.Handler(eventColumns, nil, printEvent)
|
h.Handler(eventColumns, nil, printEvent)
|
||||||
h.Handler(eventColumns, nil, printEventList)
|
h.Handler(eventColumns, nil, printEventList)
|
||||||
h.Handler(namespaceColumns, nil, printNamespace)
|
h.Handler(namespaceColumns, nil, printNamespace)
|
||||||
@ -1009,16 +1021,15 @@ func printServiceAccountList(list *api.ServiceAccountList, w io.Writer, options
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printNode(node *api.Node, w io.Writer, options printers.PrintOptions) error {
|
func printNode(obj *api.Node, options printers.PrintOptions) ([]metav1alpha1.TableRow, error) {
|
||||||
name := printers.FormatResourceName(options.Kind, node.Name, options.WithKind)
|
row := metav1alpha1.TableRow{
|
||||||
|
Object: runtime.RawExtension{Object: obj},
|
||||||
if options.WithNamespace {
|
|
||||||
return fmt.Errorf("node is not namespaced")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
conditionMap := make(map[api.NodeConditionType]*api.NodeCondition)
|
conditionMap := make(map[api.NodeConditionType]*api.NodeCondition)
|
||||||
NodeAllConditions := []api.NodeConditionType{api.NodeReady}
|
NodeAllConditions := []api.NodeConditionType{api.NodeReady}
|
||||||
for i := range node.Status.Conditions {
|
for i := range obj.Status.Conditions {
|
||||||
cond := node.Status.Conditions[i]
|
cond := obj.Status.Conditions[i]
|
||||||
conditionMap[cond.Type] = &cond
|
conditionMap[cond.Type] = &cond
|
||||||
}
|
}
|
||||||
var status []string
|
var status []string
|
||||||
@ -1034,16 +1045,13 @@ func printNode(node *api.Node, w io.Writer, options printers.PrintOptions) error
|
|||||||
if len(status) == 0 {
|
if len(status) == 0 {
|
||||||
status = append(status, "Unknown")
|
status = append(status, "Unknown")
|
||||||
}
|
}
|
||||||
if node.Spec.Unschedulable {
|
if obj.Spec.Unschedulable {
|
||||||
status = append(status, "SchedulingDisabled")
|
status = append(status, "SchedulingDisabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s", name, strings.Join(status, ","), translateTimestamp(node.CreationTimestamp), node.Status.NodeInfo.KubeletVersion); err != nil {
|
row.Cells = append(row.Cells, obj.Name, strings.Join(status, ","), translateTimestamp(obj.CreationTimestamp), obj.Status.NodeInfo.KubeletVersion)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if options.Wide {
|
if options.Wide {
|
||||||
osImage, kernelVersion, crVersion := node.Status.NodeInfo.OSImage, node.Status.NodeInfo.KernelVersion, node.Status.NodeInfo.ContainerRuntimeVersion
|
osImage, kernelVersion, crVersion := obj.Status.NodeInfo.OSImage, obj.Status.NodeInfo.KernelVersion, obj.Status.NodeInfo.ContainerRuntimeVersion
|
||||||
if osImage == "" {
|
if osImage == "" {
|
||||||
osImage = "<unknown>"
|
osImage = "<unknown>"
|
||||||
}
|
}
|
||||||
@ -1053,16 +1061,10 @@ func printNode(node *api.Node, w io.Writer, options printers.PrintOptions) error
|
|||||||
if crVersion == "" {
|
if crVersion == "" {
|
||||||
crVersion = "<unknown>"
|
crVersion = "<unknown>"
|
||||||
}
|
}
|
||||||
if _, err := fmt.Fprintf(w, "\t%s\t%s\t%s\t%s", getNodeExternalIP(node), osImage, kernelVersion, crVersion); err != nil {
|
row.Cells = append(row.Cells, getNodeExternalIP(obj), osImage, kernelVersion, crVersion)
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Display caller specify column labels first.
|
|
||||||
if _, err := fmt.Fprint(w, printers.AppendLabels(node.Labels, options.ColumnLabels)); err != nil {
|
return []metav1alpha1.TableRow{row}, nil
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err := fmt.Fprint(w, printers.AppendAllLabels(options.ShowLabels, node.Labels))
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns first external ip of the node or "<none>" if none is found.
|
// Returns first external ip of the node or "<none>" if none is found.
|
||||||
@ -1076,13 +1078,16 @@ func getNodeExternalIP(node *api.Node) string {
|
|||||||
return "<none>"
|
return "<none>"
|
||||||
}
|
}
|
||||||
|
|
||||||
func printNodeList(list *api.NodeList, w io.Writer, options printers.PrintOptions) error {
|
func printNodeList(list *api.NodeList, options printers.PrintOptions) ([]metav1alpha1.TableRow, error) {
|
||||||
for _, node := range list.Items {
|
rows := make([]metav1alpha1.TableRow, 0, len(list.Items))
|
||||||
if err := printNode(&node, w, options); err != nil {
|
for i := range list.Items {
|
||||||
return err
|
r, err := printNode(&list.Items[i], options)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
rows = append(rows, r...)
|
||||||
}
|
}
|
||||||
return nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPersistentVolume(pv *api.PersistentVolume, w io.Writer, options printers.PrintOptions) error {
|
func printPersistentVolume(pv *api.PersistentVolume, w io.Writer, options printers.PrintOptions) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user