diff --git a/src/common/__tests__/kube-helpers.test.ts b/src/common/__tests__/kube-helpers.test.ts index ddecc6bde8..2a346bfef5 100644 --- a/src/common/__tests__/kube-helpers.test.ts +++ b/src/common/__tests__/kube-helpers.test.ts @@ -1,5 +1,5 @@ import { KubeConfig } from "@kubernetes/client-node"; -import { validateKubeConfig, loadConfig } from "../kube-helpers"; +import { validateKubeConfig, loadConfig, getNodeWarningConditions } from "../kube-helpers"; const kubeconfig = ` apiVersion: v1 @@ -251,4 +251,43 @@ describe("kube helpers", () => { }); }); }); + + describe("getNodeWarningConditions", () => { + it("should return an empty array if no status or no conditions", () => { + expect(getNodeWarningConditions({}).length).toBe(0); + }); + + it("should return an empty array if all conditions are good", () => { + expect(getNodeWarningConditions({ + status: { + conditions: [ + { + type: "Ready", + status: "foobar" + } + ] + } + }).length).toBe(0); + }); + + it("should all not ready conditions", () => { + const conds = getNodeWarningConditions({ + status: { + conditions: [ + { + type: "Ready", + status: "foobar" + }, + { + type: "NotReady", + status: "true" + }, + ] + } + }); + + expect(conds.length).toBe(1); + expect(conds[0].type).toBe("NotReady"); + }); + }); }); diff --git a/src/common/kube-helpers.ts b/src/common/kube-helpers.ts index fb4691fedb..e4a1168699 100644 --- a/src/common/kube-helpers.ts +++ b/src/common/kube-helpers.ts @@ -174,9 +174,9 @@ export function podHasIssues(pod: V1Pod) { } export function getNodeWarningConditions(node: V1Node) { - return node.status.conditions.filter(c => + return node.status?.conditions?.filter(c => c.status.toLowerCase() === "true" && c.type !== "Ready" && c.type !== "HostUpgrades" - ); + ) ?? []; } /**