Skip to content

Commit ee177db

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#38866 from xingzhou/kube-25579
Automatic merge from submit-queue (batch tested with PRs 37845, 39439, 39514, 39457, 38866) Add software versions to "kubectl get nodes -o wide" output. Added "OS-IMAGE" and "KERNEL-VERSION" two columns to "kubectl get nodes -o wide" output. This will help to provide more information for user to locate or debug issues. See discussion in ticket kubernetes#25579
2 parents 3c56041 + 5edac7c commit ee177db

File tree

2 files changed

+97
-2
lines changed

2 files changed

+97
-2
lines changed

pkg/kubectl/resource_printer.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ var (
494494
statefulSetColumns = []string{"NAME", "DESIRED", "CURRENT", "AGE"}
495495
endpointColumns = []string{"NAME", "ENDPOINTS", "AGE"}
496496
nodeColumns = []string{"NAME", "STATUS", "AGE", "VERSION"}
497-
nodeWideColumns = []string{"EXTERNAL-IP"}
497+
nodeWideColumns = []string{"EXTERNAL-IP", "OS-IMAGE", "KERNEL-VERSION"}
498498
daemonSetColumns = []string{"NAME", "DESIRED", "CURRENT", "READY", "NODE-SELECTOR", "AGE"}
499499
daemonSetWideColumns = []string{"CONTAINER(S)", "IMAGE(S)", "SELECTOR"}
500500
eventColumns = []string{"LASTSEEN", "FIRSTSEEN", "COUNT", "NAME", "KIND", "SUBOBJECT", "TYPE", "REASON", "SOURCE", "MESSAGE"}
@@ -1550,7 +1550,14 @@ func printNode(node *api.Node, w io.Writer, options PrintOptions) error {
15501550
}
15511551

15521552
if options.Wide {
1553-
if _, err := fmt.Fprintf(w, "\t%s", getNodeExternalIP(node)); err != nil {
1553+
osImage, kernelVersion := node.Status.NodeInfo.OSImage, node.Status.NodeInfo.KernelVersion
1554+
if osImage == "" {
1555+
osImage = "<unknown>"
1556+
}
1557+
if kernelVersion == "" {
1558+
kernelVersion = "<unknown>"
1559+
}
1560+
if _, err := fmt.Fprintf(w, "\t%s\t%s\t%s", getNodeExternalIP(node), osImage, kernelVersion); err != nil {
15541561
return err
15551562
}
15561563
}

pkg/kubectl/resource_printer_test.go

+88
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,94 @@ func TestPrintNodeStatus(t *testing.T) {
727727
}
728728
}
729729

730+
func TestPrintNodeOSImage(t *testing.T) {
731+
printer := NewHumanReadablePrinter(PrintOptions{
732+
ColumnLabels: []string{},
733+
Wide: true,
734+
})
735+
736+
table := []struct {
737+
node api.Node
738+
osImage string
739+
}{
740+
{
741+
node: api.Node{
742+
ObjectMeta: api.ObjectMeta{Name: "foo1"},
743+
Status: api.NodeStatus{
744+
NodeInfo: api.NodeSystemInfo{OSImage: "fake-os-image"},
745+
Addresses: []api.NodeAddress{{Type: api.NodeExternalIP, Address: "1.1.1.1"}},
746+
},
747+
},
748+
osImage: "fake-os-image",
749+
},
750+
{
751+
node: api.Node{
752+
ObjectMeta: api.ObjectMeta{Name: "foo2"},
753+
Status: api.NodeStatus{
754+
NodeInfo: api.NodeSystemInfo{KernelVersion: "fake-kernel-version"},
755+
Addresses: []api.NodeAddress{{Type: api.NodeExternalIP, Address: "1.1.1.1"}},
756+
},
757+
},
758+
osImage: "<unknown>",
759+
},
760+
}
761+
762+
for _, test := range table {
763+
buffer := &bytes.Buffer{}
764+
err := printer.PrintObj(&test.node, buffer)
765+
if err != nil {
766+
t.Fatalf("An error occurred printing Node: %#v", err)
767+
}
768+
if !contains(strings.Fields(buffer.String()), test.osImage) {
769+
t.Fatalf("Expect printing node %s with os image %#v, got: %#v", test.node.Name, test.osImage, buffer.String())
770+
}
771+
}
772+
}
773+
774+
func TestPrintNodeKernelVersion(t *testing.T) {
775+
printer := NewHumanReadablePrinter(PrintOptions{
776+
ColumnLabels: []string{},
777+
Wide: true,
778+
})
779+
780+
table := []struct {
781+
node api.Node
782+
kernelVersion string
783+
}{
784+
{
785+
node: api.Node{
786+
ObjectMeta: api.ObjectMeta{Name: "foo1"},
787+
Status: api.NodeStatus{
788+
NodeInfo: api.NodeSystemInfo{KernelVersion: "fake-kernel-version"},
789+
Addresses: []api.NodeAddress{{Type: api.NodeExternalIP, Address: "1.1.1.1"}},
790+
},
791+
},
792+
kernelVersion: "fake-kernel-version",
793+
},
794+
{
795+
node: api.Node{
796+
ObjectMeta: api.ObjectMeta{Name: "foo2"},
797+
Status: api.NodeStatus{
798+
NodeInfo: api.NodeSystemInfo{OSImage: "fake-os-image"},
799+
Addresses: []api.NodeAddress{{Type: api.NodeExternalIP, Address: "1.1.1.1"}},
800+
},
801+
},
802+
kernelVersion: "<unknown>",
803+
},
804+
}
805+
806+
for _, test := range table {
807+
buffer := &bytes.Buffer{}
808+
err := printer.PrintObj(&test.node, buffer)
809+
if err != nil {
810+
t.Fatalf("An error occurred printing Node: %#v", err)
811+
}
812+
if !contains(strings.Fields(buffer.String()), test.kernelVersion) {
813+
t.Fatalf("Expect printing node %s with kernel version %#v, got: %#v", test.node.Name, test.kernelVersion, buffer.String())
814+
}
815+
}
816+
}
817+
730818
func TestPrintNodeExternalIP(t *testing.T) {
731819
printer := NewHumanReadablePrinter(PrintOptions{
732820
Wide: true,

0 commit comments

Comments
 (0)