1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Do not crash if ingress is missing status.loadbalancer.ingress property (#5665)

This commit is contained in:
Lauri Nevala 2022-06-21 18:24:02 +03:00 committed by GitHub
parent 0784085bf4
commit 666d90dd3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 2 deletions

View File

@ -5,6 +5,53 @@
import { computeRuleDeclarations, Ingress } from "../endpoints"; import { computeRuleDeclarations, Ingress } from "../endpoints";
describe("Ingress", () => {
it("given no loadbalancer ingresses in status property, loadbalancers should be an empty array", () => {
const ingress = new Ingress({
apiVersion: "networking.k8s.io/v1",
kind: "Ingress",
metadata: {
name: "foo",
resourceVersion: "1",
uid: "bar",
namespace: "default",
selfLink: "/apis/networking.k8s.io/v1/ingresses/default/foo",
},
status: {
loadBalancer: {},
},
});
expect(ingress.getLoadBalancers()).toEqual([]);
});
it("given loadbalancer ingresses in status property, loadbalancers should be flat array of ip adresses and hostnames", () => {
const ingress = new Ingress({
apiVersion: "networking.k8s.io/v1",
kind: "Ingress",
metadata: {
name: "foo",
resourceVersion: "1",
uid: "bar",
namespace: "default",
selfLink: "/apis/networking.k8s.io/v1/ingresses/default/foo",
},
status: {
loadBalancer: {
ingress: [{
ip: "10.0.0.27",
},
{
hostname: "localhost",
}],
},
},
});
expect(ingress.getLoadBalancers()).toEqual(["10.0.0.27", "localhost"]);
});
});
describe("computeRuleDeclarations", () => { describe("computeRuleDeclarations", () => {
it("given no tls field, should format links as http://", () => { it("given no tls field, should format links as http://", () => {
const ingress = new Ingress({ const ingress = new Ingress({

View File

@ -136,7 +136,7 @@ export interface IngressSpec {
export interface IngressStatus { export interface IngressStatus {
loadBalancer: { loadBalancer: {
ingress: ILoadBalancerIngress[]; ingress?: ILoadBalancerIngress[];
}; };
} }
@ -199,7 +199,7 @@ export class Ingress extends KubeObject<IngressStatus, IngressSpec, KubeObjectSc
} }
getLoadBalancers() { getLoadBalancers() {
return this.status?.loadBalancer.ingress.map(address => ( return this.status?.loadBalancer?.ingress?.map(address => (
address.hostname || address.ip address.hostname || address.ip
)) ?? []; )) ?? [];
} }