mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 05:19:39 +02:00
fix: improve the node view for detecting roles - develop (#354)
This commit is contained in:
parent
81c5f4acc3
commit
7c01f84a5c
1 changed files with 10 additions and 17 deletions
|
@ -6,36 +6,29 @@ export function getInternalNodeIpAddress(node?: Node) {
|
|||
)?.address;
|
||||
}
|
||||
|
||||
// most kube clusters set control-plane label, older clusters set master, microk8s doesn't have either but instead sets microk8s-controlplane
|
||||
const controlPlaneLabels = [
|
||||
'node-role.kubernetes.io/control-plane',
|
||||
'node-role.kubernetes.io/master',
|
||||
'node.kubernetes.io/microk8s-controlplane',
|
||||
'node.kubernetes.io/microk8s-controlplane'
|
||||
];
|
||||
|
||||
const roleLabels = ['kubernetes.io/role'];
|
||||
const roleLabels = [
|
||||
'kubernetes.io/role',
|
||||
'node.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' {
|
||||
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
|
||||
(label) => 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';
|
||||
return hasControlPlaneLabel || hasControlPlaneLabelValue
|
||||
? 'Control plane'
|
||||
: 'Worker';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue