mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Update Node.getRoleLabels() to work with kube 1.16's defaults (#4771)
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
4ec36a154d
commit
dd4aa30b8d
2 files changed
+156
-7
No files matched your search
@@ -140,6 +140,12 @@ function* getTrueConditionTypes(conditions: IterableIterator<NodeCondition> | It
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This regex is used in the `getRoleLabels()` method bellow, but placed here
|
||||
* as factoring out regexes is best practice.
|
||||
*/
|
||||
const nodeRoleLabelKeyMatcher = /^.*node-role.kubernetes.io\/+(?<role>.+)$/;
|
||||
|
||||
export class Node extends KubeObject {
|
||||
static kind = "Node";
|
||||
static namespaced = false;
|
||||
@@ -165,17 +171,29 @@ export class Node extends KubeObject {
|
||||
return this.spec.taints || [];
|
||||
}
|
||||
|
||||
getRoleLabels() {
|
||||
if (!this.metadata?.labels || typeof this.metadata.labels !== "object") {
|
||||
getRoleLabels(): string {
|
||||
const { labels } = this.metadata;
|
||||
|
||||
if (!labels || typeof labels !== "object") {
|
||||
return "";
|
||||
}
|
||||
|
||||
const roleLabels = Object.keys(this.metadata.labels)
|
||||
.filter(key => key.includes("node-role.kubernetes.io"))
|
||||
.map(key => key.match(/([^/]+$)/)[0]); // all after last slash
|
||||
const roleLabels: string[] = [];
|
||||
|
||||
if (this.metadata.labels["kubernetes.io/role"] != undefined) {
|
||||
roleLabels.push(this.metadata.labels["kubernetes.io/role"]);
|
||||
for (const labelKey of Object.keys(labels)) {
|
||||
const match = nodeRoleLabelKeyMatcher.exec(labelKey);
|
||||
|
||||
if (match) {
|
||||
roleLabels.push(match.groups.role);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof labels["kubernetes.io/role"] === "string") {
|
||||
roleLabels.push(labels["kubernetes.io/role"]);
|
||||
}
|
||||
|
||||
if (typeof labels["node.kubernetes.io/role"] === "string") {
|
||||
roleLabels.push(labels["node.kubernetes.io/role"]);
|
||||
}
|
||||
|
||||
return roleLabels.join(", ");
|
||||
|
||||
Reference in new issue
Block a user