1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 07:49:41 +02:00

refactor(app): backport technical changes (#4679)

* refactor(app): backport technical changes

* refactor(app): remove EE only features

* feat(app): small review changes to match EE codebase layout on some files

Co-authored-by: xAt0mZ <baron_l@epitech.eu>
This commit is contained in:
Alice Groux 2021-02-26 16:50:33 +01:00 committed by GitHub
parent 158bdae10e
commit ccf6babc02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 951 additions and 976 deletions

View file

@ -1,4 +1,4 @@
import * as _ from 'lodash-es';
import _ from 'lodash-es';
import { KubernetesPortMapping, KubernetesPortMappingPort } from 'Kubernetes/models/port/models';
import { KubernetesServiceTypes } from 'Kubernetes/models/service/models';
import { KubernetesConfigurationTypes } from 'Kubernetes/models/configuration/models';
@ -322,7 +322,7 @@ class KubernetesApplicationHelper {
const pvc = _.find(persistentVolumeClaims, (item) => _.startsWith(item.Name, folder.PersistentVolumeClaimName));
const res = new KubernetesApplicationPersistedFolderFormValue(pvc.StorageClass);
res.PersistentVolumeClaimName = folder.PersistentVolumeClaimName;
res.Size = parseInt(pvc.Storage.slice(0, -2));
res.Size = parseInt(pvc.Storage, 10);
res.SizeUnit = pvc.Storage.slice(-2);
res.ContainerPath = folder.MountPath;
return res;

View file

@ -16,5 +16,13 @@ class KubernetesCommonHelper {
label = _.replace(label, /[-_.]*$/g, '');
return label;
}
static assignOrDeleteIfEmptyOrZero(obj, path, value) {
if (!value || value === 0 || (value instanceof Array && !value.length)) {
_.unset(obj, path);
} else {
_.set(obj, path, value);
}
}
}
export default KubernetesCommonHelper;

View file

@ -4,6 +4,28 @@ class KubernetesResourceQuotaHelper {
static generateResourceQuotaName(name) {
return KubernetesPortainerResourceQuotaPrefix + name;
}
static formatBytes(bytes, decimals = 0, base10 = true) {
const res = {
Size: 0,
SizeUnit: 'B',
};
if (bytes === 0) {
return res;
}
const k = base10 ? 1000 : 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return {
Size: parseFloat((bytes / Math.pow(k, i)).toFixed(dm)),
SizeUnit: sizes[i],
};
}
}
export default KubernetesResourceQuotaHelper;

View file

@ -26,7 +26,7 @@ class KubernetesResourceReservationHelper {
}
static parseCPU(cpu) {
let res = parseInt(cpu);
let res = parseInt(cpu, 10);
if (_.endsWith(cpu, 'm')) {
res /= 1000;
}