7e768a54d5
* feat(k8s/resource-pool): add storage quota create/edit * feat(kubernetes): persistent volume claim size validation on app create/edit * feat(k8s/volume): quota validation on volume expansion * fix(k8s/application): remove resource limitation message when then is no resource limitation but volume quota * style(k8s/application): remove HTML layout debug string * feat(k8s/resource-pool): remove warning message on storage quota reduction * fix(k8s/application): available size on storage quota is now properly computed on init * fix(k8s/application): 'flagged for removal' bindings are not considered free space anymore * feat(k8s/application): allow users to use existing available volumes when quotas are exhausted * feat(k8s/resource-pool): storage quota usage bar in edit view * fix(k8s/resource-pool): create RP enable quota by default * refactor(k8s): move all volume related units to base 10 instead of base 2 (remive i suffix) * fix(k8s/application): visual issues caused by latency in computation * feat(k8s/resource-pool): allow standard users to see storage quota usage * feat(k8s/volume): show max available size on volume expand * style(k8s/application): exhausted storage quota message * fix(k8s/application): remove persisted folders entries when selecting RP with all exhausted storage quotas and no available volumes * style(k8s/application): file format after rebase * fix(k8s/application): evaluate quota onInit for app edit * chore(grunt): add prod watch grunt rule and config * fix(k8s/application): display 'no storages' message on all restricted quotas * refactor(k8s/volumes): unify volume parsing * refactor(app): proper prod watch + enforce parseInt radix
89 lines
2.9 KiB
JavaScript
89 lines
2.9 KiB
JavaScript
import _ from 'lodash-es';
|
|
import angular from 'angular';
|
|
import PortainerError from 'Portainer/error';
|
|
import { KubernetesCommonParams } from 'Kubernetes/models/common/params';
|
|
import KubernetesResourceQuotaConverter from 'Kubernetes/converters/resourceQuota';
|
|
|
|
/* @ngInject */
|
|
export function KubernetesResourceQuotaService($async, KubernetesResourceQuotas) {
|
|
return {
|
|
get,
|
|
create,
|
|
patch,
|
|
delete: _delete,
|
|
};
|
|
|
|
async function getOne(namespace, name) {
|
|
try {
|
|
const params = new KubernetesCommonParams();
|
|
params.id = name;
|
|
const [raw, yaml] = await Promise.all([KubernetesResourceQuotas(namespace).get(params).$promise, KubernetesResourceQuotas(namespace).getYaml(params).$promise]);
|
|
return KubernetesResourceQuotaConverter.apiToResourceQuota(raw, yaml);
|
|
} catch (err) {
|
|
throw new PortainerError('Unable to retrieve resource quota', err);
|
|
}
|
|
}
|
|
|
|
async function getAll(namespace) {
|
|
try {
|
|
const data = await KubernetesResourceQuotas(namespace).get().$promise;
|
|
return _.map(data.items, (item) => KubernetesResourceQuotaConverter.apiToResourceQuota(item));
|
|
} catch (err) {
|
|
throw new PortainerError('Unable to retrieve resource quotas', err);
|
|
}
|
|
}
|
|
|
|
function get(namespace, name) {
|
|
if (name) {
|
|
return $async(getOne, namespace, name);
|
|
}
|
|
return $async(getAll, namespace);
|
|
}
|
|
|
|
function create(quota) {
|
|
return $async(async () => {
|
|
try {
|
|
const payload = KubernetesResourceQuotaConverter.createPayload(quota);
|
|
const namespace = payload.metadata.namespace;
|
|
const params = {};
|
|
const data = await KubernetesResourceQuotas(namespace).create(params, payload).$promise;
|
|
return KubernetesResourceQuotaConverter.apiToResourceQuota(data);
|
|
} catch (err) {
|
|
throw new PortainerError('Unable to create quota', err);
|
|
}
|
|
});
|
|
}
|
|
|
|
function patch(oldQuota, newQuota) {
|
|
return $async(async () => {
|
|
try {
|
|
const params = new KubernetesCommonParams();
|
|
params.id = newQuota.Name;
|
|
const namespace = newQuota.Namespace;
|
|
const payload = KubernetesResourceQuotaConverter.patchPayload(oldQuota, newQuota);
|
|
if (!payload.length) {
|
|
return;
|
|
}
|
|
const data = await KubernetesResourceQuotas(namespace).patch(params, payload).$promise;
|
|
return data;
|
|
} catch (err) {
|
|
throw new PortainerError('Unable to patch quota', err);
|
|
}
|
|
});
|
|
}
|
|
|
|
function _delete(quota) {
|
|
return $async(async () => {
|
|
try {
|
|
const params = new KubernetesCommonParams();
|
|
params.id = quota.Name;
|
|
await KubernetesResourceQuotas(quota.Namespace).delete(params).$promise;
|
|
} catch (err) {
|
|
throw new PortainerError('Unable to delete quota', err);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
angular.module('portainer.kubernetes').service('KubernetesResourceQuotaService', KubernetesResourceQuotaService);
|