Skip to content

Commit 3470cb2

Browse files
committed
format byte sizes more nicely in labels
1 parent 9d264a3 commit 3470cb2

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/openshift/actions/DeploymentLabelAction/DeploymentLabelActionModal.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
LogLevel,
5252
parseDuration,
5353
formatDurationForLabel,
54+
formatByteSizeForLabel,
5455
AGENT_LABEL_KEYS,
5556
} from './utils';
5657

@@ -313,7 +314,7 @@ export const DeploymentLabelActionModal: React.FC<CryostatModalProps> = ({ kind,
313314
{
314315
op: 'replace',
315316
path: `/spec/template/metadata/labels/${AGENT_LABEL_KEYS.HARVESTER_EXIT_MAX_SIZE.replace('/', '~1')}`,
316-
value: formData.harvesterExitMaxSizeB.toString(),
317+
value: formatByteSizeForLabel(formData.harvesterExitMaxSizeB),
317318
},
318319
];
319320

@@ -497,7 +498,7 @@ export const DeploymentLabelActionModal: React.FC<CryostatModalProps> = ({ kind,
497498
{
498499
op: 'replace',
499500
path: `/spec/template/metadata/labels/${AGENT_LABEL_KEYS.HARVESTER_EXIT_MAX_SIZE.replace('/', '~1')}`,
500-
value: quickRegisterData.harvesterExitMaxSizeB.toString(),
501+
value: formatByteSizeForLabel(quickRegisterData.harvesterExitMaxSizeB),
501502
},
502503
];
503504
if (cryostatInstance.metadata?.labels?.[AGENT_LABEL_KEYS.LOG_LEVEL]) {

src/openshift/actions/DeploymentLabelAction/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,25 @@ export function formatDurationForLabel(durationMs: number): string {
9898
return `${durationMs}ms`;
9999
}
100100

101+
export function formatByteSizeForLabel(bytes: number): string {
102+
const gi = bytes / (1024 * 1024 * 1024);
103+
if (Number.isInteger(gi) && gi >= 1) {
104+
return `${gi}Gi`;
105+
}
106+
107+
const mi = bytes / (1024 * 1024);
108+
if (Number.isInteger(mi) && mi >= 1) {
109+
return `${mi}Mi`;
110+
}
111+
112+
const ki = bytes / 1024;
113+
if (Number.isInteger(ki) && ki >= 1) {
114+
return `${ki}Ki`;
115+
}
116+
117+
return `${bytes}`;
118+
}
119+
101120
export function getAgentConfig(container: Container): AgentConfig | null {
102121
const labels = container.labels;
103122
if (!labels) {

0 commit comments

Comments
 (0)