mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
include node internal ip as additional information for kubectl
This commit is contained in:
parent
dce1b88128
commit
a6b567e8b2
@ -220,6 +220,7 @@ func AddHandlers(h printers.PrintHandler) {
|
|||||||
{Name: "Roles", Type: "string", Description: "The roles of the node"},
|
{Name: "Roles", Type: "string", Description: "The roles of the node"},
|
||||||
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
|
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
|
||||||
{Name: "Version", Type: "string", Description: apiv1.NodeSystemInfo{}.SwaggerDoc()["kubeletVersion"]},
|
{Name: "Version", Type: "string", Description: apiv1.NodeSystemInfo{}.SwaggerDoc()["kubeletVersion"]},
|
||||||
|
{Name: "Internal-IP", Type: "string", Priority: 1, Description: apiv1.NodeStatus{}.SwaggerDoc()["addresses"]},
|
||||||
{Name: "External-IP", Type: "string", Priority: 1, Description: apiv1.NodeStatus{}.SwaggerDoc()["addresses"]},
|
{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: "OS-Image", Type: "string", Priority: 1, Description: apiv1.NodeSystemInfo{}.SwaggerDoc()["osImage"]},
|
||||||
{Name: "Kernel-Version", Type: "string", Priority: 1, Description: apiv1.NodeSystemInfo{}.SwaggerDoc()["kernelVersion"]},
|
{Name: "Kernel-Version", Type: "string", Priority: 1, Description: apiv1.NodeSystemInfo{}.SwaggerDoc()["kernelVersion"]},
|
||||||
@ -1138,7 +1139,7 @@ func printNode(obj *api.Node, options printers.PrintOptions) ([]metav1beta1.Tabl
|
|||||||
if crVersion == "" {
|
if crVersion == "" {
|
||||||
crVersion = "<unknown>"
|
crVersion = "<unknown>"
|
||||||
}
|
}
|
||||||
row.Cells = append(row.Cells, getNodeExternalIP(obj), osImage, kernelVersion, crVersion)
|
row.Cells = append(row.Cells, getNodeInternalIP(obj), getNodeExternalIP(obj), osImage, kernelVersion, crVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
return []metav1beta1.TableRow{row}, nil
|
return []metav1beta1.TableRow{row}, nil
|
||||||
@ -1155,6 +1156,17 @@ func getNodeExternalIP(node *api.Node) string {
|
|||||||
return "<none>"
|
return "<none>"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the internal IP of the node or "<none>" if none is found.
|
||||||
|
func getNodeInternalIP(node *api.Node) string {
|
||||||
|
for _, address := range node.Status.Addresses {
|
||||||
|
if address.Type == api.NodeInternalIP {
|
||||||
|
return address.Address
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "<none>"
|
||||||
|
}
|
||||||
|
|
||||||
// findNodeRoles returns the roles of a given node.
|
// findNodeRoles returns the roles of a given node.
|
||||||
// The roles are determined by looking for:
|
// The roles are determined by looking for:
|
||||||
// * a node-role.kubernetes.io/<role>="" label
|
// * a node-role.kubernetes.io/<role>="" label
|
||||||
|
@ -1118,6 +1118,54 @@ func TestPrintNodeExternalIP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrintNodeInternalIP(t *testing.T) {
|
||||||
|
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{
|
||||||
|
Wide: true,
|
||||||
|
})
|
||||||
|
AddHandlers(printer)
|
||||||
|
table := []struct {
|
||||||
|
node api.Node
|
||||||
|
internalIP string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
node: api.Node{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "foo1"},
|
||||||
|
Status: api.NodeStatus{Addresses: []api.NodeAddress{{Type: api.NodeInternalIP, Address: "1.1.1.1"}}},
|
||||||
|
},
|
||||||
|
internalIP: "1.1.1.1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
node: api.Node{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "foo2"},
|
||||||
|
Status: api.NodeStatus{Addresses: []api.NodeAddress{{Type: api.NodeExternalIP, Address: "1.1.1.1"}}},
|
||||||
|
},
|
||||||
|
internalIP: "<none>",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
node: api.Node{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "foo3"},
|
||||||
|
Status: api.NodeStatus{Addresses: []api.NodeAddress{
|
||||||
|
{Type: api.NodeInternalIP, Address: "2.2.2.2"},
|
||||||
|
{Type: api.NodeExternalIP, Address: "3.3.3.3"},
|
||||||
|
{Type: api.NodeInternalIP, Address: "4.4.4.4"},
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
internalIP: "2.2.2.2",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
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.internalIP) {
|
||||||
|
t.Fatalf("Expect printing node %s with internal ip %#v, got: %#v", test.node.Name, test.internalIP, buffer.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func contains(fields []string, field string) bool {
|
func contains(fields []string, field string) bool {
|
||||||
for _, v := range fields {
|
for _, v := range fields {
|
||||||
if v == field {
|
if v == field {
|
||||||
|
Loading…
Reference in New Issue
Block a user