mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Cherry Pick bug fixes from v5.5.0-beta.2 (#5429)
This commit is contained in:
parent
a61a455fad
commit
d09816aacf
@ -8,7 +8,61 @@ import { Node } from "../endpoints";
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
describe("Nodes tests", () => {
|
||||
describe("Node tests", () => {
|
||||
describe("isMasterNode()", () => {
|
||||
it("given a master node labelled before kubernetes 1.20, should return true", () => {
|
||||
const node = new Node({
|
||||
apiVersion: "foo",
|
||||
kind: "Node",
|
||||
metadata: {
|
||||
name: "bar",
|
||||
resourceVersion: "1",
|
||||
uid: "bat",
|
||||
labels: {
|
||||
"node-role.kubernetes.io/master": "NoSchedule",
|
||||
},
|
||||
selfLink: "/api/v1/nodes/bar",
|
||||
},
|
||||
});
|
||||
|
||||
expect(node.isMasterNode()).toBe(true);
|
||||
});
|
||||
|
||||
it("given a master node labelled after kubernetes 1.20, should return true", () => {
|
||||
const node = new Node({
|
||||
apiVersion: "foo",
|
||||
kind: "Node",
|
||||
metadata: {
|
||||
name: "bar",
|
||||
resourceVersion: "1",
|
||||
uid: "bat",
|
||||
labels: {
|
||||
"node-role.kubernetes.io/control-plane": "NoSchedule",
|
||||
},
|
||||
selfLink: "/api/v1/nodes/bar",
|
||||
},
|
||||
});
|
||||
|
||||
expect(node.isMasterNode()).toBe(true);
|
||||
});
|
||||
|
||||
it("given a non master node, should return false", () => {
|
||||
const node = new Node({
|
||||
apiVersion: "foo",
|
||||
kind: "Node",
|
||||
metadata: {
|
||||
name: "bar",
|
||||
resourceVersion: "1",
|
||||
uid: "bat",
|
||||
labels: {},
|
||||
selfLink: "/api/v1/nodes/bar",
|
||||
},
|
||||
});
|
||||
|
||||
expect(node.isMasterNode()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getRoleLabels()", () => {
|
||||
it("should return empty string if labels is not present", () => {
|
||||
const node = new Node({
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import type { BaseKubeObjectCondition, KubeObjectScope } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { cpuUnitsToNumber, unitsToBytes } from "../../../renderer/utils";
|
||||
import { cpuUnitsToNumber, unitsToBytes, isObject } from "../../../renderer/utils";
|
||||
import type { MetricData } from "./metrics.api";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
@ -69,6 +69,17 @@ export interface NodeCondition extends BaseKubeObjectCondition {
|
||||
lastHeartbeatTime?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* These role label prefixs are the ones that are for master nodes
|
||||
*
|
||||
* The `master` label has been deprecated in Kubernetes 1.20, and will be removed in 1.25 so we
|
||||
* have to also use the newer `control-plane` label
|
||||
*/
|
||||
const masterNodeLabels = [
|
||||
"master",
|
||||
"control-plane",
|
||||
];
|
||||
|
||||
/**
|
||||
* This regex is used in the `getRoleLabels()` method bellow, but placed here
|
||||
* as factoring out regexes is best practice.
|
||||
@ -189,15 +200,19 @@ export class Node extends KubeObject<NodeStatus, NodeSpec, KubeObjectScope.Clust
|
||||
return this.spec.taints || [];
|
||||
}
|
||||
|
||||
getRoleLabels(): string {
|
||||
isMasterNode(): boolean {
|
||||
return this.getRoleLabelItems()
|
||||
.some(roleLabel => masterNodeLabels.includes(roleLabel));
|
||||
}
|
||||
|
||||
getRoleLabelItems(): string[] {
|
||||
const { labels } = this.metadata;
|
||||
|
||||
if (!labels || typeof labels !== "object") {
|
||||
return "";
|
||||
}
|
||||
|
||||
const roleLabels: string[] = [];
|
||||
|
||||
if (!isObject(labels)) {
|
||||
return roleLabels;
|
||||
}
|
||||
|
||||
for (const labelKey of Object.keys(labels)) {
|
||||
const match = nodeRoleLabelKeyMatcher.match(labelKey);
|
||||
|
||||
@ -214,7 +229,11 @@ export class Node extends KubeObject<NodeStatus, NodeSpec, KubeObjectScope.Clust
|
||||
roleLabels.push(labels["node.kubernetes.io/role"]);
|
||||
}
|
||||
|
||||
return roleLabels.join(", ");
|
||||
return roleLabels;
|
||||
}
|
||||
|
||||
getRoleLabels(): string {
|
||||
return this.getRoleLabelItems().join(", ");
|
||||
}
|
||||
|
||||
getCpuCapacity() {
|
||||
|
||||
@ -23,7 +23,7 @@ export async function execHelm(args: string[], { encoding, ...rest }: BaseEncodi
|
||||
try {
|
||||
const opts = { ...options };
|
||||
|
||||
opts.env ??= process.env;
|
||||
opts.env ??= { ...process.env };
|
||||
|
||||
if (!opts.env.HTTPS_PROXY && UserStore.getInstance().httpsProxy) {
|
||||
opts.env.HTTPS_PROXY = UserStore.getInstance().httpsProxy;
|
||||
|
||||
@ -156,7 +156,7 @@ export class Kubectl {
|
||||
try {
|
||||
const args = [
|
||||
"version",
|
||||
"--client", "true",
|
||||
"--client",
|
||||
"--output", "json",
|
||||
];
|
||||
const { stdout } = await promiseExecFile(path, args);
|
||||
|
||||
@ -19,11 +19,11 @@ export class NodeStore extends KubeObjectStore<Node, NodeApi> {
|
||||
}
|
||||
|
||||
@computed get masterNodes() {
|
||||
return this.items.filter(node => node.getRoleLabels().includes("master"));
|
||||
return this.items.filter(node => node.isMasterNode());
|
||||
}
|
||||
|
||||
@computed get workerNodes() {
|
||||
return this.items.filter(node => !node.getRoleLabels().includes("master"));
|
||||
return this.items.filter(node => !node.isMasterNode());
|
||||
}
|
||||
|
||||
getWarningsCount(): number {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user