diff --git a/pkg/kubectl/resource_printer.go b/pkg/kubectl/resource_printer.go index 70558a1b091..51165689fd3 100644 --- a/pkg/kubectl/resource_printer.go +++ b/pkg/kubectl/resource_printer.go @@ -494,7 +494,7 @@ var ( statefulSetColumns = []string{"NAME", "DESIRED", "CURRENT", "AGE"} endpointColumns = []string{"NAME", "ENDPOINTS", "AGE"} nodeColumns = []string{"NAME", "STATUS", "AGE", "VERSION"} - nodeWideColumns = []string{"EXTERNAL-IP"} + nodeWideColumns = []string{"EXTERNAL-IP", "OS-IMAGE", "KERNEL-VERSION"} daemonSetColumns = []string{"NAME", "DESIRED", "CURRENT", "READY", "NODE-SELECTOR", "AGE"} daemonSetWideColumns = []string{"CONTAINER(S)", "IMAGE(S)", "SELECTOR"} 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 { } if options.Wide { - if _, err := fmt.Fprintf(w, "\t%s", getNodeExternalIP(node)); err != nil { + osImage, kernelVersion := node.Status.NodeInfo.OSImage, node.Status.NodeInfo.KernelVersion + if osImage == "" { + osImage = "" + } + if kernelVersion == "" { + kernelVersion = "" + } + if _, err := fmt.Fprintf(w, "\t%s\t%s\t%s", getNodeExternalIP(node), osImage, kernelVersion); err != nil { return err } } diff --git a/pkg/kubectl/resource_printer_test.go b/pkg/kubectl/resource_printer_test.go index f65fac66852..888954e9d84 100644 --- a/pkg/kubectl/resource_printer_test.go +++ b/pkg/kubectl/resource_printer_test.go @@ -727,6 +727,94 @@ func TestPrintNodeStatus(t *testing.T) { } } +func TestPrintNodeOSImage(t *testing.T) { + printer := NewHumanReadablePrinter(PrintOptions{ + ColumnLabels: []string{}, + Wide: true, + }) + + table := []struct { + node api.Node + osImage string + }{ + { + node: api.Node{ + ObjectMeta: api.ObjectMeta{Name: "foo1"}, + Status: api.NodeStatus{ + NodeInfo: api.NodeSystemInfo{OSImage: "fake-os-image"}, + Addresses: []api.NodeAddress{{Type: api.NodeExternalIP, Address: "1.1.1.1"}}, + }, + }, + osImage: "fake-os-image", + }, + { + node: api.Node{ + ObjectMeta: api.ObjectMeta{Name: "foo2"}, + Status: api.NodeStatus{ + NodeInfo: api.NodeSystemInfo{KernelVersion: "fake-kernel-version"}, + Addresses: []api.NodeAddress{{Type: api.NodeExternalIP, Address: "1.1.1.1"}}, + }, + }, + osImage: "", + }, + } + + for _, test := range table { + buffer := &bytes.Buffer{} + err := printer.PrintObj(&test.node, buffer) + if err != nil { + t.Fatalf("An error occurred printing Node: %#v", err) + } + if !contains(strings.Fields(buffer.String()), test.osImage) { + t.Fatalf("Expect printing node %s with os image %#v, got: %#v", test.node.Name, test.osImage, buffer.String()) + } + } +} + +func TestPrintNodeKernelVersion(t *testing.T) { + printer := NewHumanReadablePrinter(PrintOptions{ + ColumnLabels: []string{}, + Wide: true, + }) + + table := []struct { + node api.Node + kernelVersion string + }{ + { + node: api.Node{ + ObjectMeta: api.ObjectMeta{Name: "foo1"}, + Status: api.NodeStatus{ + NodeInfo: api.NodeSystemInfo{KernelVersion: "fake-kernel-version"}, + Addresses: []api.NodeAddress{{Type: api.NodeExternalIP, Address: "1.1.1.1"}}, + }, + }, + kernelVersion: "fake-kernel-version", + }, + { + node: api.Node{ + ObjectMeta: api.ObjectMeta{Name: "foo2"}, + Status: api.NodeStatus{ + NodeInfo: api.NodeSystemInfo{OSImage: "fake-os-image"}, + Addresses: []api.NodeAddress{{Type: api.NodeExternalIP, Address: "1.1.1.1"}}, + }, + }, + kernelVersion: "", + }, + } + + for _, test := range table { + buffer := &bytes.Buffer{} + err := printer.PrintObj(&test.node, buffer) + if err != nil { + t.Fatalf("An error occurred printing Node: %#v", err) + } + if !contains(strings.Fields(buffer.String()), test.kernelVersion) { + t.Fatalf("Expect printing node %s with kernel version %#v, got: %#v", test.node.Name, test.kernelVersion, buffer.String()) + } + } +} + func TestPrintNodeExternalIP(t *testing.T) { printer := NewHumanReadablePrinter(PrintOptions{ Wide: true,