Skip to content

Commit 3f9935e

Browse files
Merge pull request #2614 from pcbailey/bug-cpu-helper-text-incorrect-when-threads-arent-set
CNV-56688: Avoid CPU helper text error if CPU threads is undefined
2 parents ffa2be3 + 13ad342 commit 3f9935e

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/utils/components/CPUMemoryModal/components/CPUInput/components/CPUTopologyInput/components/TotalCPUHelperText/CPUTopologyHelperText.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const CPUTopologyHelperText: FC<CPUTopologyHelperTextProps> = ({ cpu }) => {
1515
const { t } = useKubevirtTranslation();
1616
const { cores, sockets, threads } = cpu || {};
1717

18-
const totalCPU = cores * sockets * threads;
18+
// VMs migrated from vSphere may not have spec.template.spec.domain.cpu.threads set
19+
const totalCPU = cores * sockets * (threads || 1);
1920

2021
return (
2122
<div className="cpu-topology-helper-text">

src/utils/components/CPUMemoryModal/components/CPUInput/utils/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export const getUpdatedCPU = (cpu: V1CPU, newValue: number, fieldChanged: CPUCom
1616
};
1717

1818
export const convertTopologyToVCPUs = (cpu: V1CPU): number =>
19-
cpu?.cores * cpu?.sockets * cpu?.threads;
19+
// VMs migrated from vSphere may not have spec.template.spec.domain.cpu.threads set
20+
cpu?.cores * cpu?.sockets * (cpu?.threads || 1);
2021

2122
export const formatVCPUsAsSockets = (cpu: V1CPU): V1CPU => {
2223
const numVCPUs = convertTopologyToVCPUs(cpu);

src/utils/resources/template/utils/flavor.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export const parseCPU = (cpu: V1CPU): V1CPU => {
2626
*/
2727
export const vCPUCount = (cpu: V1CPU): number => {
2828
const parsedCpu = parseCPU(cpu);
29-
return parsedCpu.sockets * parsedCpu.cores * parsedCpu.threads;
29+
30+
// VMs migrated from vSphere may not have spec.template.spec.domain.cpu.threads set
31+
return parsedCpu.sockets * parsedCpu.cores * (parsedCpu.threads || 1);
3032
};
3133

3234
/**

0 commit comments

Comments
 (0)