Commit a551dff5 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #35901 from justinsb/kubectl_show_labels

Automatic merge from submit-queue kubectl: show node label if defined 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 #33533
parents c98fc701 98f7c391
......@@ -1803,6 +1803,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))
......
......@@ -1526,6 +1526,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
......@@ -1555,6 +1559,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 {
......
......@@ -679,6 +679,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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment