From 2463648161d3f562c2ca47b6478e09c6e89d61fc Mon Sep 17 00:00:00 2001 From: Ali <83188384+testA113@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:16:41 +1200 Subject: [PATCH] fix(node): check more node role labels [EE-6968] (#11658) Co-authored-by: testa113 --- .../NodesDatatable/columns/status.tsx | 6 ++-- .../cluster/HomeView/NodesDatatable/utils.ts | 29 ++++++++++++++++--- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/react/kubernetes/cluster/HomeView/NodesDatatable/columns/status.tsx b/app/react/kubernetes/cluster/HomeView/NodesDatatable/columns/status.tsx index 258c3fdb0..e0285a476 100644 --- a/app/react/kubernetes/cluster/HomeView/NodesDatatable/columns/status.tsx +++ b/app/react/kubernetes/cluster/HomeView/NodesDatatable/columns/status.tsx @@ -23,14 +23,12 @@ function StatusCell({ } return ( -
+
{status} {node.spec?.unschedulable && ( - - SchedulingDisabled - + SchedulingDisabled )}
); diff --git a/app/react/kubernetes/cluster/HomeView/NodesDatatable/utils.ts b/app/react/kubernetes/cluster/HomeView/NodesDatatable/utils.ts index 965310703..a5d4b0b4d 100644 --- a/app/react/kubernetes/cluster/HomeView/NodesDatatable/utils.ts +++ b/app/react/kubernetes/cluster/HomeView/NodesDatatable/utils.ts @@ -7,14 +7,35 @@ export function getInternalNodeIpAddress(node?: Node) { } // most kube clusters set control-plane label, older clusters set master, microk8s doesn't have either but instead sets microk8s-controlplane -const masterLabels = [ +const controlPlaneLabels = [ 'node-role.kubernetes.io/control-plane', 'node-role.kubernetes.io/master', 'node.kubernetes.io/microk8s-controlplane', ]; +const roleLabels = ['kubernetes.io/role']; + +/** + * Returns the role of the node based on the labels. + * @param node The node to get the role of. + * It uses similar logic to https://github.com/kubernetes/kubectl/blob/04bb64c802171066ed0d886c437590c0b7ff1ed3/pkg/describe/describe.go#L5523C1-L5541C2 , + * but only returns 'Control plane' or 'Worker'. It also has an additional check for microk8s. + */ export function getRole(node: Node): 'Control plane' | 'Worker' { - return masterLabels.some((label) => node.metadata?.labels?.[label]) - ? 'Control plane' - : 'Worker'; + const hasControlPlaneLabel = controlPlaneLabels.some( + (label) => + // the label can be set to an empty string, so we need to check for undefined + // e.g. node-role.kubernetes.io/control-plane: "" + node.metadata?.labels?.[label] !== undefined + ); + const hasControlPlaneLabelValue = roleLabels.some( + (label) => + node.metadata?.labels?.[label] === 'control-plane' || + node.metadata?.labels?.[label] === 'master' + ); + + if (hasControlPlaneLabel || hasControlPlaneLabelValue) { + return 'Control plane'; + } + return 'Worker'; }