mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
refactor(namespace): migrate namespace edit to react [r8s-125] (#38)
This commit is contained in:
parent
40c7742e46
commit
ce7e0d8d60
108 changed files with 3183 additions and 2194 deletions
64
app/react/kubernetes/namespaces/resourceQuotaUtils.ts
Normal file
64
app/react/kubernetes/namespaces/resourceQuotaUtils.ts
Normal file
|
@ -0,0 +1,64 @@
|
|||
import { endsWith } from 'lodash';
|
||||
import filesizeParser from 'filesize-parser';
|
||||
|
||||
export const KubernetesPortainerResourceQuotaPrefix = 'portainer-rq-';
|
||||
|
||||
export function generateResourceQuotaName(name: string) {
|
||||
return `${KubernetesPortainerResourceQuotaPrefix}${name}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* parseCPU converts a CPU string to a number in cores.
|
||||
* It supports m (milli), u (micro), n (nano), p (pico) suffixes.
|
||||
*
|
||||
* If given an empty string, it returns 0.
|
||||
*/
|
||||
export function parseCPU(cpu: string) {
|
||||
let res = parseInt(cpu, 10);
|
||||
if (Number.isNaN(res)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (endsWith(cpu, 'm')) {
|
||||
// milli
|
||||
res /= 1000;
|
||||
} else if (endsWith(cpu, 'u')) {
|
||||
// micro
|
||||
res /= 1000000;
|
||||
} else if (endsWith(cpu, 'n')) {
|
||||
// nano
|
||||
res /= 1000000000;
|
||||
} else if (endsWith(cpu, 'p')) {
|
||||
// pico
|
||||
res /= 1000000000000;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
export function terabytesValue(value: string | number) {
|
||||
return gigabytesValue(value) / 1000;
|
||||
}
|
||||
|
||||
export function gigabytesValue(value: string | number) {
|
||||
return megaBytesValue(value) / 1000;
|
||||
}
|
||||
|
||||
export function megaBytesValue(value: string | number) {
|
||||
return Math.floor(safeFilesizeParser(value, 10) / 1000 / 1000);
|
||||
}
|
||||
|
||||
export function bytesValue(mem: string | number) {
|
||||
return safeFilesizeParser(mem, 10) * 1000 * 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default base is 2, you can use base 10 if you want
|
||||
* https://github.com/patrickkettner/filesize-parser#readme
|
||||
*/
|
||||
function safeFilesizeParser(value: string | number, base: 2 | 10 = 2) {
|
||||
if (!value || Number.isNaN(value)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return filesizeParser(value, { base });
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue