-
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.
* feat: added ability to deploy more than one NIM model. (#3453) * feat: added ability to deploy more than one NIM model. Signed-off-by: Olga Lavtar <[email protected]> * feat: refactored NIM related logic to nimUtils Signed-off-by: Olga Lavtar <[email protected]> * feat: changes to the error handling Signed-off-by: Olga Lavtar <[email protected]> * feat: changes to the error handling Signed-off-by: Olga Lavtar <[email protected]> * feat: changes .some for .forEach Signed-off-by: Olga Lavtar <[email protected]> * feat: deleting secrets fix Signed-off-by: Olga Lavtar <[email protected]> * feat: deploying the same model pvc fix Signed-off-by: Olga Lavtar <[email protected]> * feat: added a unit test for getNIMResourcesToDelete Signed-off-by: Olga Lavtar <[email protected]> * feat: will add a unit test for getNIMResourcesToDelete later Signed-off-by: Olga Lavtar <[email protected]> --------- Signed-off-by: Olga Lavtar <[email protected]> * feat: Modify NIM enablement process (#3455) * Modify NIM enablement process * Clean up code and remove unnecessary manifests * Add logic to check the conditions of the odh-nim-account CR * Added more check for enabled integration apps * If failed to fetch integration app status, should show error on the related tile in the enable application page, should not remove the tile * check integration app status in explore application page * Fix lint issue * Fix lint issue * add annotations to the secret and the account CR * Update backend/src/routes/api/integrations/nim/index.ts Co-authored-by: Andrew Ballantyne <[email protected]> * Update backend/src/routes/api/components/list.ts Co-authored-by: Andrew Ballantyne <[email protected]> * clean up * feat: listing all NIM accounts in the namespace, returning the first one. Signed-off-by: Olga Lavtar <[email protected]> * Avoid mutating object in useWatchIntegrationComponents * Clean up * feat: added logic for displaying the tile correctly Signed-off-by: Olga Lavtar <[email protected]> * feat: changes for enabling Signed-off-by: Olga Lavtar <[email protected]> * feat: updated mock component with the new properties. Signed-off-by: Olga Lavtar <[email protected]> * feat: addressed PR comments with updates and improvements Signed-off-by: Olga Lavtar <[email protected]> * feat: backend bug fix Signed-off-by: Olga Lavtar <[email protected]> * feat: Missed change from previous commit Signed-off-by: Olga Lavtar <[email protected]> * feat: fix for the enabled page and enabled.cy.ts Signed-off-by: Olga Lavtar <[email protected]> --------- Signed-off-by: Olga Lavtar <[email protected]> Co-authored-by: Andrew Ballantyne <[email protected]> Co-authored-by: Olga Lavtar <[email protected]> * Fix NIM selection issue (#3482) * Fix NIM selection issue * Switch back to using a numerical value --------- Signed-off-by: Olga Lavtar <[email protected]> Co-authored-by: olavtar <[email protected]> Co-authored-by: yu zhao <[email protected]> Co-authored-by: Olga Lavtar <[email protected]>
- Loading branch information
1 parent
b09ef1b
commit 411cc1e
Showing
32 changed files
with
837 additions
and
678 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { FastifyReply, FastifyRequest } from 'fastify'; | ||
import { secureAdminRoute } from '../../../../utils/route-security'; | ||
import { KubeFastifyInstance } from '../../../../types'; | ||
import { isString } from 'lodash'; | ||
import { createNIMAccount, createNIMSecret, getNIMAccount, isAppEnabled } from './nimUtils'; | ||
|
||
module.exports = async (fastify: KubeFastifyInstance) => { | ||
const { namespace } = fastify.kube; | ||
const PAGE_NOT_FOUND_MESSAGE = '404 page not found'; | ||
|
||
fastify.get( | ||
'/', | ||
secureAdminRoute(fastify)(async (request: FastifyRequest, reply: FastifyReply) => { | ||
await getNIMAccount(fastify, namespace) | ||
.then((response) => { | ||
if (response) { | ||
// Installed | ||
const isEnabled = isAppEnabled(response); | ||
reply.send({ isInstalled: true, isEnabled: isEnabled, canInstall: false, error: '' }); | ||
} else { | ||
// Not installed | ||
fastify.log.info(`NIM account does not exist`); | ||
reply.send({ isInstalled: false, isEnabled: false, canInstall: true, error: '' }); | ||
} | ||
}) | ||
.catch((e) => { | ||
if (e.response?.statusCode === 404) { | ||
// 404 error means the Account CRD does not exist, so cannot create CR based on it. | ||
if ( | ||
isString(e.response.body) && | ||
e.response.body.trim() === PAGE_NOT_FOUND_MESSAGE.trim() | ||
) { | ||
fastify.log.info(`NIM not installed, ${e.response?.body}`); | ||
reply.send({ | ||
isInstalled: false, | ||
isEnabled: false, | ||
canInstall: false, | ||
error: 'NIM not installed', | ||
}); | ||
} | ||
} else { | ||
fastify.log.error(`An unexpected error occurred: ${e.message || e}`); | ||
reply.send({ | ||
isInstalled: false, | ||
isAppEnabled: false, | ||
canInstall: false, | ||
error: 'An unexpected error occurred. Please try again later.', | ||
}); | ||
} | ||
}); | ||
}), | ||
); | ||
|
||
fastify.post( | ||
'/', | ||
secureAdminRoute(fastify)( | ||
async ( | ||
request: FastifyRequest<{ | ||
Body: { [key: string]: string }; | ||
}>, | ||
reply: FastifyReply, | ||
) => { | ||
const enableValues = request.body; | ||
|
||
await createNIMSecret(fastify, namespace, enableValues) | ||
.then(async () => { | ||
await createNIMAccount(fastify, namespace) | ||
.then((response) => { | ||
const isEnabled = isAppEnabled(response); | ||
reply.send({ | ||
isInstalled: true, | ||
isEnabled: isEnabled, | ||
canInstall: false, | ||
error: '', | ||
}); | ||
}) | ||
.catch((e) => { | ||
const message = `Failed to create NIM account, ${e.response?.body?.message}`; | ||
fastify.log.error(message); | ||
reply.status(e.response.statusCode).send(new Error(message)); | ||
}); | ||
}) | ||
.catch((e) => { | ||
if (e.response?.statusCode === 409) { | ||
fastify.log.error(`NIM secret already exists, skipping creation.`); | ||
reply.status(409).send(new Error(`NIM secret already exists, skipping creation.`)); | ||
} else { | ||
fastify.log.error(`Failed to create NIM secret. ${e.response?.body?.message}`); | ||
reply | ||
.status(e.response.statusCode) | ||
.send(new Error(`Failed to create NIM secret, ${e.response?.body?.message}`)); | ||
} | ||
}); | ||
}, | ||
), | ||
); | ||
}; |
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,91 @@ | ||
import { KubeFastifyInstance, NIMAccountKind, SecretKind } from '../../../../types'; | ||
|
||
const NIM_SECRET_NAME = 'nvidia-nim-access'; | ||
const NIM_ACCOUNT_NAME = 'odh-nim-account'; | ||
|
||
export const isAppEnabled = (app: NIMAccountKind): boolean => { | ||
const conditions = app?.status?.conditions || []; | ||
return ( | ||
conditions.find( | ||
(condition) => condition.type === 'AccountStatus' && condition.status === 'True', | ||
) !== undefined | ||
); | ||
}; | ||
|
||
export const getNIMAccount = async ( | ||
fastify: KubeFastifyInstance, | ||
namespace: string, | ||
): Promise<NIMAccountKind | undefined> => { | ||
const { customObjectsApi } = fastify.kube; | ||
try { | ||
const response = await customObjectsApi.listNamespacedCustomObject( | ||
'nim.opendatahub.io', | ||
'v1', | ||
namespace, | ||
'accounts', | ||
); | ||
// Get the list of accounts from the response | ||
const accounts = response.body as { | ||
items: NIMAccountKind[]; | ||
}; | ||
|
||
return accounts.items[0] || undefined; | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
|
||
export const createNIMAccount = async ( | ||
fastify: KubeFastifyInstance, | ||
namespace: string, | ||
): Promise<NIMAccountKind> => { | ||
const { customObjectsApi } = fastify.kube; | ||
const account = { | ||
apiVersion: 'nim.opendatahub.io/v1', | ||
kind: 'Account', | ||
metadata: { | ||
name: NIM_ACCOUNT_NAME, | ||
namespace, | ||
labels: { | ||
'opendatahub.io/managed': 'true', | ||
}, | ||
}, | ||
spec: { | ||
apiKeySecret: { | ||
name: NIM_SECRET_NAME, | ||
}, | ||
}, | ||
}; | ||
const response = await customObjectsApi.createNamespacedCustomObject( | ||
'nim.opendatahub.io', | ||
'v1', | ||
namespace, | ||
'accounts', | ||
account, | ||
); | ||
return Promise.resolve(response.body as NIMAccountKind); | ||
}; | ||
|
||
export const createNIMSecret = async ( | ||
fastify: KubeFastifyInstance, | ||
namespace: string, | ||
enableValues: { [key: string]: string }, | ||
): Promise<SecretKind> => { | ||
const { coreV1Api } = fastify.kube; | ||
const nimSecret = { | ||
apiVersion: 'v1', | ||
kind: 'Secret', | ||
metadata: { | ||
name: NIM_SECRET_NAME, | ||
namespace, | ||
labels: { | ||
'opendatahub.io/managed': 'true', | ||
}, | ||
}, | ||
type: 'Opaque', | ||
stringData: enableValues, | ||
}; | ||
|
||
const response = await coreV1Api.createNamespacedSecret(namespace, nimSecret); | ||
return Promise.resolve(response.body as SecretKind); | ||
}; |
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
Oops, something went wrong.