Merge pull request #46646 from rickypai/rpai/add_container_runtime_version_to_node_wide_printer

Automatic merge from submit-queue (batch tested with PRs 47403, 46646, 46906, 46527, 46792)

add ContainerRuntimeVersion to `kubectl get nodes -o=wide` output

**What this PR does / why we need it**: adds container runtime version to `kubectl get nodes -o=wide` output as a way to surface more node-level information

When upgrading to a new container runtime version (docker 1.11 -> docker 1.12) or when experimenting with a different container runtime version (experimenting with rkt in a docker cluster), it's useful for cluster operators to see which nodes are running which container runtime version. `kubectl get nodes -o=wide` already provides kernel and OS version, and I believe adding container runtime version would be good.

**Release note**:
```release-note
container runtime version has been added to the output of `kubectl get nodes -o=wide` as `CONTAINER-RUNTIME`
```
This commit is contained in:
Kubernetes Submit Queue 2017-06-23 02:59:25 -07:00 committed by GitHub
commit 4a1d95ef57
2 changed files with 51 additions and 3 deletions

View File

@ -73,7 +73,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"}
@ -1122,14 +1122,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

@ -818,6 +818,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,