add ContainerRuntimeVersion to kubectl get nodes -o=wide output

This commit is contained in:
Ricky Pai 2017-05-30 13:14:04 -07:00
parent 68dd748ba1
commit 8c0c7626eb
2 changed files with 51 additions and 3 deletions

View File

@ -71,7 +71,7 @@ var (
statefulSetColumns = []string{"NAME", "DESIRED", "CURRENT", "AGE"}
endpointColumns = []string{"NAME", "ENDPOINTS", "AGE"}
nodeColumns = []string{"NAME", "STATUS", "AGE", "VERSION"}
nodeWideColumns = []string{"EXTERNAL-IP", "OS-IMAGE", "KERNEL-VERSION"}
nodeWideColumns = []string{"EXTERNAL-IP", "OS-IMAGE", "KERNEL-VERSION", "CONTAINER-RUNTIME"}
daemonSetColumns = []string{"NAME", "DESIRED", "CURRENT", "READY", "UP-TO-DATE", "AVAILABLE", "NODE-SELECTOR", "AGE"}
daemonSetWideColumns = []string{"CONTAINER(S)", "IMAGE(S)", "SELECTOR"}
eventColumns = []string{"LASTSEEN", "FIRSTSEEN", "COUNT", "NAME", "KIND", "SUBOBJECT", "TYPE", "REASON", "SOURCE", "MESSAGE"}
@ -1127,14 +1127,17 @@ func printNode(node *api.Node, w io.Writer, options printers.PrintOptions) error
}
if options.Wide {
osImage, kernelVersion := node.Status.NodeInfo.OSImage, node.Status.NodeInfo.KernelVersion
osImage, kernelVersion, crVersion := node.Status.NodeInfo.OSImage, node.Status.NodeInfo.KernelVersion, node.Status.NodeInfo.ContainerRuntimeVersion
if osImage == "" {
osImage = "<unknown>"
}
if kernelVersion == "" {
kernelVersion = "<unknown>"
}
if _, err := fmt.Fprintf(w, "\t%s\t%s\t%s", getNodeExternalIP(node), osImage, kernelVersion); err != nil {
if crVersion == "" {
crVersion = "<unknown>"
}
if _, err := fmt.Fprintf(w, "\t%s\t%s\t%s\t%s", getNodeExternalIP(node), osImage, kernelVersion, crVersion); err != nil {
return err
}
}

View File

@ -826,6 +826,51 @@ func TestPrintNodeKernelVersion(t *testing.T) {
}
}
func TestPrintNodeContainerRuntimeVersion(t *testing.T) {
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{
ColumnLabels: []string{},
Wide: true,
})
AddHandlers(printer)
table := []struct {
node api.Node
containerRuntimeVersion string
}{
{
node: api.Node{
ObjectMeta: metav1.ObjectMeta{Name: "foo1"},
Status: api.NodeStatus{
NodeInfo: api.NodeSystemInfo{ContainerRuntimeVersion: "foo://1.2.3"},
Addresses: []api.NodeAddress{{Type: api.NodeExternalIP, Address: "1.1.1.1"}},
},
},
containerRuntimeVersion: "foo://1.2.3",
},
{
node: api.Node{
ObjectMeta: metav1.ObjectMeta{Name: "foo2"},
Status: api.NodeStatus{
NodeInfo: api.NodeSystemInfo{},
Addresses: []api.NodeAddress{{Type: api.NodeExternalIP, Address: "1.1.1.1"}},
},
},
containerRuntimeVersion: "<unknown>",
},
}
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.containerRuntimeVersion) {
t.Fatalf("Expect printing node %s with kernel version %#v, got: %#v", test.node.Name, test.containerRuntimeVersion, buffer.String())
}
}
}
func TestPrintNodeName(t *testing.T) {
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{
Wide: true,