You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/kubernetes/converters/resourcePool.js

46 lines
1.7 KiB

import _ from 'lodash-es';
import { KubernetesResourcePool } from 'Kubernetes/models/resource-pool/models';
import { KubernetesNamespace } from 'Kubernetes/models/namespace/models';
import { KubernetesIngressConverter } from 'Kubernetes/ingress/converter';
import KubernetesResourceQuotaConverter from './resourceQuota';
class KubernetesResourcePoolConverter {
static apiToResourcePool(namespace) {
const res = new KubernetesResourcePool();
res.Namespace = namespace;
res.Yaml = namespace.Yaml;
return res;
}
static formValuesToResourcePool(formValues) {
const namespace = new KubernetesNamespace();
namespace.Name = formValues.Name;
namespace.ResourcePoolName = formValues.Name;
namespace.ResourcePoolOwner = formValues.Owner;
namespace.IsSystem = formValues.IsSystem;
const quota = KubernetesResourceQuotaConverter.resourcePoolFormValuesToResourceQuota(formValues);
const ingMap = _.map(formValues.IngressClasses, (c) => {
if (c.Selected) {
c.Namespace = namespace.Name;
return KubernetesIngressConverter.resourcePoolIngressClassFormValueToIngress(c);
}
});
const ingresses = _.without(ingMap, undefined);
const registries = _.map(formValues.Registries, (r) => {
if (!r.RegistryAccesses[formValues.EndpointId]) {
r.RegistryAccesses[formValues.EndpointId] = { Namespaces: [] };
}
if (!_.includes(r.RegistryAccesses[formValues.EndpointId].Namespaces, formValues.Name)) {
r.RegistryAccesses[formValues.EndpointId].Namespaces = [...r.RegistryAccesses[formValues.EndpointId].Namespaces, formValues.Name];
}
return r;
});
return [namespace, quota, ingresses, registries];
}
}
export default KubernetesResourcePoolConverter;