fix: instance type missing when using CPU type

This commit is contained in:
jialin
2026-05-27 12:14:15 +08:00
committed by jialin
parent 7287f8c81b
commit d0bc206c83
2 changed files with 24 additions and 9 deletions
@@ -159,7 +159,6 @@ const AddModal: React.FC<AddModalProps> = ({
description: saveInstanceDataInDescription(instanceType) description: saveInstanceDataInDescription(instanceType)
}); });
} }
// update form // update form
form.current?.applyInstanceType?.(instanceType); form.current?.applyInstanceType?.(instanceType);
}; };
@@ -196,9 +196,16 @@ export const getAcceleratorMax = (
// Picks the candidate (cluster + type name) that should fulfill a requested // Picks the candidate (cluster + type name) that should fulfill a requested
// accelerator count: the first candidate of the smallest tier whose // accelerator count: the first candidate of the smallest tier whose
// onceMaxRequest is >= the requested count. // onceMaxRequest is >= the requested count and whose cpu/ram/localStorage
// remaining are all > 0.
export const pickCandidateForAccelerator = < export const pickCandidateForAccelerator = <
C extends { cluster: string; name: string } C extends {
cluster: string;
name: string;
cpu?: { remaining?: string | null } | null;
ram?: { remaining?: string | null } | null;
localStorage?: { remaining?: string | null } | null;
}
>( >(
tiers: tiers:
| { onceMaxRequest: string; candidates?: C[] | null }[] | { onceMaxRequest: string; candidates?: C[] | null }[]
@@ -207,13 +214,22 @@ export const pickCandidateForAccelerator = <
count: number count: number
): C | null => { ): C | null => {
if (!tiers?.length) return null; if (!tiers?.length) return null;
const hasResources = (c: C) =>
parseQuantity(c.cpu?.remaining) > 0 &&
parseQuantity(c.ram?.remaining) > 0 &&
parseQuantity(c.localStorage?.remaining) > 0;
const sorted = [...tiers].sort( const sorted = [...tiers].sort(
(a, b) => parseQuantity(a.onceMaxRequest) - parseQuantity(b.onceMaxRequest) (a, b) => parseQuantity(a.onceMaxRequest) - parseQuantity(b.onceMaxRequest)
); );
const tier = sorted.find((t) =>
count === 0 // count === 0 ? parseQuantity(tier.onceMaxRequest) > count; this is CPU-only case.
? parseQuantity(t.onceMaxRequest) > count for (const tier of sorted) {
: parseQuantity(t.onceMaxRequest) >= count const fits = parseQuantity(tier.onceMaxRequest) >= count;
); if (!fits) continue;
return tier?.candidates?.[0] ?? null; const candidate = tier.candidates?.find(hasResources);
if (candidate) return candidate;
}
return null;
}; };