mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix http(s) formatting and add some tests
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
722bd4a666
commit
c4f17a3138
108
src/common/k8s-api/__tests__/ingress.api.ts
Normal file
108
src/common/k8s-api/__tests__/ingress.api.ts
Normal file
@ -0,0 +1,108 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { computeRuleDeclarations, Ingress } from "../endpoints";
|
||||
|
||||
describe("computeRuleDeclarations", () => {
|
||||
it("given no tls field, should format links as http://", () => {
|
||||
const ingress = new Ingress({
|
||||
apiVersion: "networking.k8s.io/v1",
|
||||
kind: "Ingress",
|
||||
metadata: {
|
||||
name: "foo",
|
||||
resourceVersion: "1",
|
||||
uid: "bar",
|
||||
},
|
||||
});
|
||||
|
||||
const result = computeRuleDeclarations(ingress, {
|
||||
host: "foo.bar",
|
||||
http: {
|
||||
paths: [{
|
||||
backend: {
|
||||
service: {
|
||||
name: "my-service",
|
||||
port: {
|
||||
number: 8080,
|
||||
},
|
||||
},
|
||||
},
|
||||
}],
|
||||
},
|
||||
});
|
||||
|
||||
expect(result[0].url).toBe("http://foo.bar/");
|
||||
});
|
||||
|
||||
it("given no tls entries, should format links as http://", () => {
|
||||
const ingress = new Ingress({
|
||||
apiVersion: "networking.k8s.io/v1",
|
||||
kind: "Ingress",
|
||||
metadata: {
|
||||
name: "foo",
|
||||
resourceVersion: "1",
|
||||
uid: "bar",
|
||||
},
|
||||
});
|
||||
|
||||
ingress.spec = {
|
||||
tls: [],
|
||||
};
|
||||
|
||||
const result = computeRuleDeclarations(ingress, {
|
||||
host: "foo.bar",
|
||||
http: {
|
||||
paths: [{
|
||||
backend: {
|
||||
service: {
|
||||
name: "my-service",
|
||||
port: {
|
||||
number: 8080,
|
||||
},
|
||||
},
|
||||
},
|
||||
}],
|
||||
},
|
||||
});
|
||||
|
||||
expect(result[0].url).toBe("http://foo.bar/");
|
||||
});
|
||||
|
||||
it("given some tls entries, should format links as https://", () => {
|
||||
const ingress = new Ingress({
|
||||
apiVersion: "networking.k8s.io/v1",
|
||||
kind: "Ingress",
|
||||
metadata: {
|
||||
name: "foo",
|
||||
resourceVersion: "1",
|
||||
uid: "bar",
|
||||
},
|
||||
});
|
||||
|
||||
ingress.spec = {
|
||||
tls: [{
|
||||
secretName: "my-secret",
|
||||
}],
|
||||
};
|
||||
|
||||
const result = computeRuleDeclarations(ingress, {
|
||||
host: "foo.bar",
|
||||
http: {
|
||||
paths: [{
|
||||
backend: {
|
||||
service: {
|
||||
name: "my-service",
|
||||
port: {
|
||||
number: 8080,
|
||||
},
|
||||
},
|
||||
},
|
||||
}],
|
||||
},
|
||||
});
|
||||
|
||||
expect(result[0].url).toBe("https://foo.bar/");
|
||||
});
|
||||
});
|
||||
@ -42,8 +42,8 @@ export interface ILoadBalancerIngress {
|
||||
|
||||
// extensions/v1beta1
|
||||
export interface ExtensionsBackend {
|
||||
serviceName: string;
|
||||
servicePort: number | string;
|
||||
serviceName?: string;
|
||||
servicePort?: number | string;
|
||||
}
|
||||
|
||||
// networking.k8s.io/v1
|
||||
@ -96,7 +96,7 @@ export interface IngressRule {
|
||||
}
|
||||
|
||||
export interface Ingress {
|
||||
spec: {
|
||||
spec?: {
|
||||
tls?: {
|
||||
secretName: string;
|
||||
}[];
|
||||
@ -200,7 +200,7 @@ export class Ingress extends KubeObject {
|
||||
|
||||
export function computeRuleDeclarations(ingress: Ingress, rule: IngressRule): ComputedIngressRoute[] {
|
||||
const { host = "*", http: { paths } = { paths: [] }} = rule;
|
||||
const protocol = (ingress.spec.tls?.length ?? 0) > 0
|
||||
const protocol = (ingress.spec?.tls?.length ?? 0) === 0
|
||||
? "http"
|
||||
: "https";
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user