Skip to content

Commit

Permalink
feat: changes to the error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Olga Lavtar <[email protected]>
  • Loading branch information
olavtar committed Nov 8, 2024
1 parent f8cdf8a commit a630a93
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
57 changes: 37 additions & 20 deletions frontend/src/pages/modelServing/screens/projects/nimUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,29 +130,46 @@ export const getNIMResourcesToDelete = async (
servingRuntime: ServingRuntimeKind,
): Promise<Promise<void>[]> => {
const resourcesToDelete: Promise<void>[] = [];
try {
const count = await fetchInferenceServiceCount(projectName);
if (count === 0) {
return resourcesToDelete;
}
const pvcName = servingRuntime.spec.volumes?.find((vol) =>
vol.persistentVolumeClaim?.claimName.startsWith('nim-pvc'),
)?.persistentVolumeClaim?.claimName;

let nimSecretName: string | undefined;
let imagePullSecretName: string | undefined;

servingRuntime.spec.containers.some((container) =>
container.env?.some((env) => {
const secretName = env.valueFrom?.secretKeyRef?.name;
if (secretName === NIM_SECRET_NAME) {
nimSecretName = secretName;
} else if (secretName === NIM_NGC_SECRET_NAME) {
imagePullSecretName = secretName;
}
return nimSecretName && imagePullSecretName;
}),
);

const count = await fetchInferenceServiceCount(projectName);
const pvcName = servingRuntime.spec.volumes?.find((vol) => vol.persistentVolumeClaim?.claimName)
?.persistentVolumeClaim?.claimName;

const containerWithEnv = servingRuntime.spec.containers.find(
(container) => container.env && container.env.some((env) => env.valueFrom?.secretKeyRef?.name),
);

const nimSecretName = containerWithEnv?.env?.find((env) => env.valueFrom?.secretKeyRef?.name)
?.valueFrom?.secretKeyRef?.name;

const imagePullSecretName = servingRuntime.spec.imagePullSecrets?.[0]?.name ?? undefined;

if (pvcName) {
resourcesToDelete.push(deletePvc(pvcName, projectName).then(() => undefined));
}
if (pvcName) {
resourcesToDelete.push(deletePvc(pvcName, projectName).then(() => undefined));
}

if (nimSecretName && imagePullSecretName && count === 1) {
resourcesToDelete.push(
deleteSecret(projectName, nimSecretName).then(() => undefined),
deleteSecret(projectName, imagePullSecretName).then(() => undefined),
if (nimSecretName && imagePullSecretName && count === 1) {
resourcesToDelete.push(
deleteSecret(projectName, nimSecretName).then(() => undefined),
deleteSecret(projectName, imagePullSecretName).then(() => undefined),
);
}
} catch (error) {
// eslint-disable-next-line no-console
console.error(
`Error fetching inference service count for project "${projectName}": ${error.message}`,
);
return [];
}

return resourcesToDelete;
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/pages/modelServing/screens/projects/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,10 @@ export const fetchInferenceServiceCount = async (namespace: string): Promise<num
const inferenceServices = await getInferenceServiceContext(namespace);
return inferenceServices.length;
} catch (error) {
return 0;
throw new Error(
`Failed to fetch inference services for namespace "${namespace}": ${
error instanceof Error ? error.message : error
}`,
);
}
};

0 comments on commit a630a93

Please sign in to comment.