diff --git a/backend/src/routes/api/service/mlmd/index.ts b/backend/src/routes/api/service/mlmd/index.ts index b22f09385a..7e2ae110ad 100644 --- a/backend/src/routes/api/service/mlmd/index.ts +++ b/backend/src/routes/api/service/mlmd/index.ts @@ -9,8 +9,7 @@ export default proxyService( plural: 'datasciencepipelinesapplications', }, { - port: 8443, - prefix: 'ds-pipeline-md-', + constructUrl: (resource) => resource.status?.components.mlmdProxy.url, }, { // Use port forwarding for local development: diff --git a/backend/src/routes/api/service/pipelines/index.ts b/backend/src/routes/api/service/pipelines/index.ts index 53bceb0b53..b1612dfdbe 100644 --- a/backend/src/routes/api/service/pipelines/index.ts +++ b/backend/src/routes/api/service/pipelines/index.ts @@ -9,8 +9,7 @@ export default proxyService( plural: 'datasciencepipelinesapplications', }, { - port: 8443, - prefix: 'ds-pipeline-', + constructUrl: (resource) => resource.status?.components.apiServer.url, }, { // Use port forwarding for local development: diff --git a/backend/src/types.ts b/backend/src/types.ts index 77990dd7b0..a8cd2743f6 100644 --- a/backend/src/types.ts +++ b/backend/src/types.ts @@ -1145,6 +1145,16 @@ export type DSPipelineKind = K8sResourceCommon & { }; status?: { conditions?: K8sCondition[]; + components: { + apiServer: { + externalUrl: string; + url: string; + }; + mlmdProxy: { + externalUrl: string; + url: string; + }; + }; }; }; diff --git a/backend/src/utils/proxy.ts b/backend/src/utils/proxy.ts index 394f152db2..63de0960cb 100644 --- a/backend/src/utils/proxy.ts +++ b/backend/src/utils/proxy.ts @@ -5,6 +5,7 @@ import { isK8sStatus, passThroughResource } from '../routes/api/k8s/pass-through import { DEV_MODE } from './constants'; import { createCustomError } from './requestUtils'; import { getAccessToken, getDirectCallOptions } from './directCallUtils'; +import { EitherNotBoth } from '../typeHelpers'; export const getParam = >(req: F, name: string): string => (req.params as { [key: string]: string })[name]; @@ -25,16 +26,20 @@ const notFoundError = (kind: string, name: string, e?: any, overrideMessage?: st 404, ); }; - export const proxyService = ( model: { apiGroup: string; apiVersion: string; plural: string; kind: string } | null, - service: { - port: number | string; - prefix?: string; - suffix?: string; - namespace?: string; - }, + service: EitherNotBoth< + { + port: number | string; + prefix?: string; + suffix?: string; + namespace?: string; + }, + { + constructUrl: (resource: K) => string; + } + >, local: { host: string; port: number | string; @@ -70,7 +75,7 @@ export const proxyService = const namespace = service.namespace ?? getParam(request, 'namespace'); const name = getParam(request, 'name'); - const doServiceRequest = () => { + const doServiceRequest = (resource?: K) => { const scheme = tls ? 'https' : 'http'; const upstream = DEV_MODE @@ -78,7 +83,9 @@ export const proxyService = // kubectl port-forward -n svc/ : `${scheme}://${local.host}:${local.port}` : // Construct service URL - `${scheme}://${service.prefix || ''}${name}${ + service.constructUrl + ? service.constructUrl(resource) + : `${scheme}://${service.prefix || ''}${name}${ service.suffix ?? '' }.${namespace}.svc.cluster.local:${service.port}`; @@ -108,7 +115,7 @@ export const proxyService = request.headers.authorization = `Bearer ${token}`; } - doServiceRequest(); + doServiceRequest(resource); } else { done(notFoundError(model.kind, name, undefined, 'service unavailable')); }