From a64d85283bf62c99a0ab25cab2cf6050e7742db6 Mon Sep 17 00:00:00 2001 From: Luca Stocchi <49404737+lstocchi@users.noreply.github.com> Date: Fri, 24 Nov 2023 15:00:40 +0100 Subject: [PATCH] fix: add path prop for route object (#4981) * fix: add path prop for route object Signed-off-by: lstocchi * Update packages/renderer/src/lib/ingresses-routes/ingress-route-utils.spec.ts Co-authored-by: Philippe Martin Signed-off-by: Luca Stocchi <49404737+lstocchi@users.noreply.github.com> * fix: fix route in deployToKube Signed-off-by: lstocchi --------- Signed-off-by: lstocchi Signed-off-by: Luca Stocchi <49404737+lstocchi@users.noreply.github.com> Co-authored-by: Philippe Martin --- .../main/src/plugin/api/openshift-types.ts | 3 +- .../src/lib/ingresses-routes/RouteUI.ts | 3 +- .../ingress-route-utils.spec.ts | 30 +++++++++++++++++-- .../ingresses-routes/ingress-route-utils.ts | 3 +- .../src/lib/pod/DeployPodToKube.svelte | 2 +- 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/packages/main/src/plugin/api/openshift-types.ts b/packages/main/src/plugin/api/openshift-types.ts index 467148647b0c0..1648733ccb613 100644 --- a/packages/main/src/plugin/api/openshift-types.ts +++ b/packages/main/src/plugin/api/openshift-types.ts @@ -26,9 +26,10 @@ export type V1Route = { }; spec: { host: string; - port: { + port?: { targetPort: string; }; + path?: string; tls: { insecureEdgeTerminationPolicy: string; termination: string; diff --git a/packages/renderer/src/lib/ingresses-routes/RouteUI.ts b/packages/renderer/src/lib/ingresses-routes/RouteUI.ts index 2d81afe426880..f341f6681afaa 100644 --- a/packages/renderer/src/lib/ingresses-routes/RouteUI.ts +++ b/packages/renderer/src/lib/ingresses-routes/RouteUI.ts @@ -25,7 +25,8 @@ export interface RouteUI { name: string; namespace: string; host: string; - port: string; + port?: string; + path?: string; to: RouteToReference; selected: boolean; } diff --git a/packages/renderer/src/lib/ingresses-routes/ingress-route-utils.spec.ts b/packages/renderer/src/lib/ingresses-routes/ingress-route-utils.spec.ts index 7ef9d1e96bfa0..446dd3550af32 100644 --- a/packages/renderer/src/lib/ingresses-routes/ingress-route-utils.spec.ts +++ b/packages/renderer/src/lib/ingresses-routes/ingress-route-utils.spec.ts @@ -63,7 +63,7 @@ test('expect basic UI conversion for ingress', async () => { expect(ingressUI.rules).equal(ingress.spec?.rules); }); -test('expect basic UI conversion for route', async () => { +test('expect basic UI conversion for route with port', async () => { const route = { metadata: { name: 'my-route', @@ -84,7 +84,33 @@ test('expect basic UI conversion for route', async () => { expect(routeUI.name).toEqual('my-route'); expect(routeUI.namespace).toEqual('test-namespace'); expect(routeUI.host).toEqual(route.spec.host); - expect(routeUI.port).toEqual(route.spec.port.targetPort); + expect(routeUI.port).toEqual(route.spec.port?.targetPort); + expect(routeUI.path).toBeUndefined(); + expect(routeUI.to.kind).toEqual(route.spec.to.kind); + expect(routeUI.to.name).toEqual(route.spec.to.name); +}); + +test('expect basic UI conversion for route with path', async () => { + const route = { + metadata: { + name: 'my-route', + namespace: 'test-namespace', + }, + spec: { + host: 'foo.bar.com', + path: '/test', + to: { + kind: 'Service', + name: 'service', + }, + }, + } as V1Route; + const routeUI = ingressRouteUtils.getRouteUI(route); + expect(routeUI.name).toEqual('my-route'); + expect(routeUI.namespace).toEqual('test-namespace'); + expect(routeUI.host).toEqual(route.spec.host); + expect(routeUI.port).toBeUndefined(); + expect(routeUI.path).toEqual(route.spec.path); expect(routeUI.to.kind).toEqual(route.spec.to.kind); expect(routeUI.to.name).toEqual(route.spec.to.name); }); diff --git a/packages/renderer/src/lib/ingresses-routes/ingress-route-utils.ts b/packages/renderer/src/lib/ingresses-routes/ingress-route-utils.ts index 0b88aa4041948..f2426aaf1505e 100644 --- a/packages/renderer/src/lib/ingresses-routes/ingress-route-utils.ts +++ b/packages/renderer/src/lib/ingresses-routes/ingress-route-utils.ts @@ -35,7 +35,8 @@ export class IngressRouteUtils { name: route.metadata?.name || '', namespace: route.metadata?.namespace || '', host: route.spec.host, - port: route.spec.port.targetPort, + port: route.spec.port?.targetPort, + path: route.spec.path, to: { kind: route.spec.to.kind, name: route.spec.to.name, diff --git a/packages/renderer/src/lib/pod/DeployPodToKube.svelte b/packages/renderer/src/lib/pod/DeployPodToKube.svelte index 4f86c52b7e9bf..8bc4f3ad771c3 100644 --- a/packages/renderer/src/lib/pod/DeployPodToKube.svelte +++ b/packages/renderer/src/lib/pod/DeployPodToKube.svelte @@ -569,7 +569,7 @@ function updateKubeResult() {
    {#each createdRoutes as createdRoute}
  • - Port {createdRoute.spec.port.targetPort} is reachable with route + Port {createdRoute.spec.port?.targetPort} is reachable with route {createdRoute.metadata.name}
  • {/each}