-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor model registry routes and configuration
- Loading branch information
Showing
11 changed files
with
127 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import httpProxy from '@fastify/http-proxy'; | ||
import { KubeFastifyInstance } from '../../../../types'; | ||
import { DEV_MODE } from '../../../../utils/constants'; | ||
import { getParam, setParam } from '../../../../utils/proxy'; | ||
|
||
export default async (fastify: KubeFastifyInstance): Promise<void> => { | ||
if (DEV_MODE) { | ||
fastify.register(httpProxy, { | ||
upstream: '', | ||
prefix: '/:name', | ||
rewritePrefix: '', | ||
replyOptions: { | ||
// preHandler must set the `upstream` param | ||
getUpstream: (request) => getParam(request, 'upstream'), | ||
}, | ||
preHandler: (request, _, done) => { | ||
const name = getParam(request, 'name'); | ||
|
||
const upstream = DEV_MODE | ||
? // Use port forwarding for local development: | ||
// kubectl port-forward -n <namespace> svc/<service-name> <local.port>:<service.port> | ||
`http://${process.env.MODEL_REGISTRY_SERVICE_HOST}:${process.env.MODEL_REGISTRY_SERVICE_PORT}` | ||
: // Construct service URL | ||
`http://${name}.odh-model-registries.svc.cluster.local:8080`; | ||
|
||
// assign the `upstream` param so we can dynamically set the upstream URL for http-proxy | ||
setParam(request, 'upstream', upstream); | ||
|
||
fastify.log.info(`Proxy ${request.method} request ${request.url} to ${upstream}`); | ||
done(); | ||
}, | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export const MODEL_REGISTRY_DEFINITION_NAME = 'modelregistry-sample'; // TODO: harcoded value, we need to dynamically fetch this | ||
export const MODEL_REGISTRY_DEFAULT_NAMESPACE = 'shared'; // TODO: harcoded value, we need to check which will be the default namespace | ||
export const MODEL_REGISTRY_DEFAULT_NAMESPACE = 'odh-model-registries'; // The default namespace for the model registry service, controlled by the operator. | ||
export const MODEL_REGISTRY_API_VERSION = 'v1alpha3'; |
Oops, something went wrong.