mirror of https://github.com/k3s-io/k3s
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 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 #33533pull/6/head
parent
15fa0df93e
commit
98f7c3919e
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue