Skip to content

Commit

Permalink
kubectl: show node label if defined
Browse files Browse the repository at this point in the history
We are moving towards marking master nodes as tainted, and not
necessarily unschedulable.  Further now we encourage users to cordon
nodes, marking them unschedulable.

Thus the reliance on "Unschedulable" is not really a great indicator for
the master.

So, recognize the existing node 'role' markers, and surface them
where Unschedulable is (in the status).

We recognize:

 * a kubernetes.io/role label
 * a kubeadm.alpha.kubernetes.io/role label

Fix kubernetes#33533
  • Loading branch information
justinsb committed Nov 7, 2016
1 parent 15fa0df commit 98f7c39
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/kubectl/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,7 @@ func (d *NodeDescriber) Describe(namespace, name string, describerSettings Descr
func describeNode(node *api.Node, nodeNonTerminatedPodsList *api.PodList, events *api.EventList, canViewPods bool) (string, error) {
return tabbedString(func(out io.Writer) error {
fmt.Fprintf(out, "Name:\t%s\n", node.Name)
fmt.Fprintf(out, "Role:\t%s\n", findNodeRole(node))
printLabelsMultiline(out, "Labels", node.Labels)
printTaintsInAnnotationMultiline(out, "Taints", node.Annotations)
fmt.Fprintf(out, "CreationTimestamp:\t%s\n", node.CreationTimestamp.Time.Format(time.RFC1123Z))
Expand Down
20 changes: 20 additions & 0 deletions pkg/kubectl/resource_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,10 @@ func printNode(node *api.Node, w io.Writer, options PrintOptions) error {
if node.Spec.Unschedulable {
status = append(status, "SchedulingDisabled")
}
role := findNodeRole(node)
if role != "" {
status = append(status, role)
}

if _, err := fmt.Fprintf(w, "%s\t%s\t%s", name, strings.Join(status, ","), translateTimestamp(node.CreationTimestamp)); err != nil {
return err
Expand Down Expand Up @@ -1520,6 +1524,22 @@ func getNodeExternalIP(node *api.Node) string {
return "<none>"
}

// findNodeRole returns the role of a given node, or "" if none found.
// The role is determined by looking in order for:
// * a kubernetes.io/role label
// * a kubeadm.alpha.kubernetes.io/role label
// If no role is found, ("", nil) is returned
func findNodeRole(node *api.Node) string {
if role := node.Labels[unversioned.NodeLabelRole]; role != "" {
return role
}
if role := node.Labels[unversioned.NodeLabelKubeadmAlphaRole]; role != "" {
return role
}
// No role found
return ""
}

func printNodeList(list *api.NodeList, w io.Writer, options PrintOptions) error {
for _, node := range list.Items {
if err := printNode(&node, w, options); err != nil {
Expand Down
30 changes: 30 additions & 0 deletions pkg/kubectl/resource_printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,36 @@ func TestPrintNodeStatus(t *testing.T) {
},
status: "Unknown,SchedulingDisabled",
},
{
node: api.Node{
ObjectMeta: api.ObjectMeta{
Name: "foo10",
Labels: map[string]string{"kubernetes.io/role": "master"},
},
Status: api.NodeStatus{Conditions: []api.NodeCondition{{Type: api.NodeReady, Status: api.ConditionTrue}}},
},
status: "Ready,master",
},
{
node: api.Node{
ObjectMeta: api.ObjectMeta{
Name: "foo11",
Labels: map[string]string{"kubernetes.io/role": "node"},
},
Status: api.NodeStatus{Conditions: []api.NodeCondition{{Type: api.NodeReady, Status: api.ConditionTrue}}},
},
status: "Ready,node",
},
{
node: api.Node{
ObjectMeta: api.ObjectMeta{
Name: "foo12",
Labels: map[string]string{"kubeadm.alpha.kubernetes.io/role": "node"},
},
Status: api.NodeStatus{Conditions: []api.NodeCondition{{Type: api.NodeReady, Status: api.ConditionTrue}}},
},
status: "Ready,node",
},
}

for _, test := range table {
Expand Down

0 comments on commit 98f7c39

Please sign in to comment.