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 taint
nodes, marking them unschedulable.

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

Instead, 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
 * a taint with Key 'dedicated'

Fix kubernetes#33533
  • Loading branch information
justinsb committed Oct 31, 2016
1 parent 8ca348a commit fbd0cbe
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pkg/kubectl/resource_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,9 @@ func printNode(node *api.Node, w io.Writer, options PrintOptions) error {
if node.Spec.Unschedulable {
status = append(status, "SchedulingDisabled")
}
if role := findNodeRole(node); 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 @@ -1505,6 +1508,34 @@ 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
// * a taint with Key 'dedicated'
// If no role is found, ("") is returned
func findNodeRole(node *api.Node) string {
if role := node.Labels["kubernetes.io/role"]; role != "" {
return role
}
if role := node.Labels["kubeadm.alpha.kubernetes.io/role"]; role != "" {
return role
}

taints, err := api.GetTaintsFromNodeAnnotations(node.Annotations)
if err != nil {
glog.Warningf("error parsing node taints for node %q: %v", node.Name, err)
} else {
for _, taint := range taints {
if taint.Key == "dedicated" {
return taint.Value
}
}
}
// 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
60 changes: 60 additions & 0 deletions pkg/kubectl/resource_printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,66 @@ 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",
},
{
node: api.Node{
ObjectMeta: api.ObjectMeta{
Name: "foo13",
Annotations: map[string]string{"scheduler.alpha.kubernetes.io/taints": "[{\"key\":\"dedicated\",\"value\":\"master\",\"effect\":\"NoSchedule\"}]"},
},
Status: api.NodeStatus{Conditions: []api.NodeCondition{{Type: api.NodeReady, Status: api.ConditionTrue}}},
},
status: "Ready,master",
},
{
node: api.Node{
ObjectMeta: api.ObjectMeta{
Name: "foo14",
Annotations: map[string]string{"scheduler.alpha.kubernetes.io/taints": "[{\"key\":\"somethingelse\",\"value\":\"master\",\"effect\":\"NoSchedule\"}]"},
},
Status: api.NodeStatus{Conditions: []api.NodeCondition{{Type: api.NodeReady, Status: api.ConditionTrue}}},
},
status: "Ready",
},
{
node: api.Node{
ObjectMeta: api.ObjectMeta{
Name: "foo15",
Annotations: map[string]string{"scheduler.alpha.kubernetes.io/taints": "unparseable"},
},
Status: api.NodeStatus{Conditions: []api.NodeCondition{{Type: api.NodeReady, Status: api.ConditionTrue}}},
},
status: "Ready",
},
}

for _, test := range table {
Expand Down

0 comments on commit fbd0cbe

Please sign in to comment.