mirror of https://github.com/portainer/portainer
chore(deps): upgrade eslint and use eslint-plugin (#4989)
parent
5fd92d8a3f
commit
ab30793c48
|
@ -133,7 +133,7 @@ angular.module('portainer.docker').factory('ImageService', [
|
|||
|
||||
Image.create({}, imageConfiguration)
|
||||
.$promise.then(function success(data) {
|
||||
var err = data.length > 0 && data[data.length - 1].hasOwnProperty('message');
|
||||
var err = data.length > 0 && data[data.length - 1].message;
|
||||
if (err) {
|
||||
var detail = data[data.length - 1];
|
||||
deferred.reject({ msg: detail.message });
|
||||
|
|
|
@ -16,7 +16,7 @@ angular.module('portainer.integrations.storidge').factory('StoridgeNodeService',
|
|||
var nodes = [];
|
||||
|
||||
for (var key in nodeData) {
|
||||
if (nodeData.hasOwnProperty(key)) {
|
||||
if (Object.prototype.hasOwnProperty.call(nodeData, key)) {
|
||||
nodes.push(new StoridgeNodeModel(key, nodeData[key]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ angular.module('portainer.integrations.storidge').factory('StoridgeSnapshotServi
|
|||
var snapshotsData = data.snapshots;
|
||||
let snapshotsArray = [];
|
||||
for (const key in snapshotsData) {
|
||||
if (snapshotsData.hasOwnProperty(key)) {
|
||||
if (Object.prototype.hasOwnProperty.call(snapshotsData, key)) {
|
||||
snapshotsArray.push(snapshotsData[key]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,122 +89,110 @@ class KubernetesApplicationService {
|
|||
|
||||
/* #region GET */
|
||||
async getAsync(namespace, name) {
|
||||
try {
|
||||
const [deployment, daemonSet, statefulSet, pod, pods, autoScalers, ingresses] = await Promise.allSettled([
|
||||
this.KubernetesDeploymentService.get(namespace, name),
|
||||
this.KubernetesDaemonSetService.get(namespace, name),
|
||||
this.KubernetesStatefulSetService.get(namespace, name),
|
||||
this.KubernetesPodService.get(namespace, name),
|
||||
this.KubernetesPodService.get(namespace),
|
||||
this.KubernetesHorizontalPodAutoScalerService.get(namespace),
|
||||
this.KubernetesIngressService.get(namespace),
|
||||
]);
|
||||
const [deployment, daemonSet, statefulSet, pod, pods, autoScalers, ingresses] = await Promise.allSettled([
|
||||
this.KubernetesDeploymentService.get(namespace, name),
|
||||
this.KubernetesDaemonSetService.get(namespace, name),
|
||||
this.KubernetesStatefulSetService.get(namespace, name),
|
||||
this.KubernetesPodService.get(namespace, name),
|
||||
this.KubernetesPodService.get(namespace),
|
||||
this.KubernetesHorizontalPodAutoScalerService.get(namespace),
|
||||
this.KubernetesIngressService.get(namespace),
|
||||
]);
|
||||
|
||||
// const pod = _.find(pods.value, ['metadata.namespace', namespace, 'metadata.name', name]);
|
||||
|
||||
let rootItem;
|
||||
let converterFunc;
|
||||
if (deployment.status === 'fulfilled') {
|
||||
rootItem = deployment;
|
||||
converterFunc = KubernetesApplicationConverter.apiDeploymentToApplication;
|
||||
} else if (daemonSet.status === 'fulfilled') {
|
||||
rootItem = daemonSet;
|
||||
converterFunc = KubernetesApplicationConverter.apiDaemonSetToApplication;
|
||||
} else if (statefulSet.status === 'fulfilled') {
|
||||
rootItem = statefulSet;
|
||||
converterFunc = KubernetesApplicationConverter.apiStatefulSetToapplication;
|
||||
} else if (pod.status === 'fulfilled') {
|
||||
rootItem = pod;
|
||||
converterFunc = KubernetesApplicationConverter.apiPodToApplication;
|
||||
} else {
|
||||
throw new PortainerError('Unable to determine which association to use to convert application');
|
||||
}
|
||||
|
||||
const services = await this.KubernetesServiceService.get(namespace);
|
||||
const boundService = KubernetesServiceHelper.findApplicationBoundService(services, rootItem.value.Raw);
|
||||
const service = boundService ? await this.KubernetesServiceService.get(namespace, boundService.metadata.name) : {};
|
||||
|
||||
const application = converterFunc(rootItem.value.Raw, pods.value, service.Raw, ingresses.value);
|
||||
application.Yaml = rootItem.value.Yaml;
|
||||
application.Raw = rootItem.value.Raw;
|
||||
application.Pods = _.map(application.Pods, (item) => KubernetesPodConverter.apiToModel(item));
|
||||
application.Containers = KubernetesApplicationHelper.associateContainersAndApplication(application);
|
||||
|
||||
const boundScaler = KubernetesHorizontalPodAutoScalerHelper.findApplicationBoundScaler(autoScalers.value, application);
|
||||
const scaler = boundScaler ? await this.KubernetesHorizontalPodAutoScalerService.get(namespace, boundScaler.Name) : undefined;
|
||||
application.AutoScaler = scaler;
|
||||
|
||||
await this.KubernetesHistoryService.get(application);
|
||||
|
||||
if (service.Yaml) {
|
||||
application.Yaml += '---\n' + service.Yaml;
|
||||
}
|
||||
if (scaler && scaler.Yaml) {
|
||||
application.Yaml += '---\n' + scaler.Yaml;
|
||||
}
|
||||
// TODO: refactor @LP
|
||||
// append ingress yaml ?
|
||||
return application;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
let rootItem;
|
||||
let converterFunc;
|
||||
if (deployment.status === 'fulfilled') {
|
||||
rootItem = deployment;
|
||||
converterFunc = KubernetesApplicationConverter.apiDeploymentToApplication;
|
||||
} else if (daemonSet.status === 'fulfilled') {
|
||||
rootItem = daemonSet;
|
||||
converterFunc = KubernetesApplicationConverter.apiDaemonSetToApplication;
|
||||
} else if (statefulSet.status === 'fulfilled') {
|
||||
rootItem = statefulSet;
|
||||
converterFunc = KubernetesApplicationConverter.apiStatefulSetToapplication;
|
||||
} else if (pod.status === 'fulfilled') {
|
||||
rootItem = pod;
|
||||
converterFunc = KubernetesApplicationConverter.apiPodToApplication;
|
||||
} else {
|
||||
throw new PortainerError('Unable to determine which association to use to convert application');
|
||||
}
|
||||
|
||||
const services = await this.KubernetesServiceService.get(namespace);
|
||||
const boundService = KubernetesServiceHelper.findApplicationBoundService(services, rootItem.value.Raw);
|
||||
const service = boundService ? await this.KubernetesServiceService.get(namespace, boundService.metadata.name) : {};
|
||||
|
||||
const application = converterFunc(rootItem.value.Raw, pods.value, service.Raw, ingresses.value);
|
||||
application.Yaml = rootItem.value.Yaml;
|
||||
application.Raw = rootItem.value.Raw;
|
||||
application.Pods = _.map(application.Pods, (item) => KubernetesPodConverter.apiToModel(item));
|
||||
application.Containers = KubernetesApplicationHelper.associateContainersAndApplication(application);
|
||||
|
||||
const boundScaler = KubernetesHorizontalPodAutoScalerHelper.findApplicationBoundScaler(autoScalers.value, application);
|
||||
const scaler = boundScaler ? await this.KubernetesHorizontalPodAutoScalerService.get(namespace, boundScaler.Name) : undefined;
|
||||
application.AutoScaler = scaler;
|
||||
|
||||
await this.KubernetesHistoryService.get(application);
|
||||
|
||||
if (service.Yaml) {
|
||||
application.Yaml += '---\n' + service.Yaml;
|
||||
}
|
||||
if (scaler && scaler.Yaml) {
|
||||
application.Yaml += '---\n' + scaler.Yaml;
|
||||
}
|
||||
// TODO: refactor @LP
|
||||
// append ingress yaml ?
|
||||
return application;
|
||||
}
|
||||
|
||||
async getAllAsync(namespace) {
|
||||
try {
|
||||
const namespaces = namespace ? [namespace] : _.map(await this.KubernetesNamespaceService.get(), 'Name');
|
||||
const namespaces = namespace ? [namespace] : _.map(await this.KubernetesNamespaceService.get(), 'Name');
|
||||
|
||||
const convertToApplication = (item, converterFunc, services, pods, ingresses) => {
|
||||
const service = KubernetesServiceHelper.findApplicationBoundService(services, item);
|
||||
const application = converterFunc(item, pods, service, ingresses);
|
||||
application.Containers = KubernetesApplicationHelper.associateContainersAndApplication(application);
|
||||
return application;
|
||||
};
|
||||
const convertToApplication = (item, converterFunc, services, pods, ingresses) => {
|
||||
const service = KubernetesServiceHelper.findApplicationBoundService(services, item);
|
||||
const application = converterFunc(item, pods, service, ingresses);
|
||||
application.Containers = KubernetesApplicationHelper.associateContainersAndApplication(application);
|
||||
return application;
|
||||
};
|
||||
|
||||
const res = await Promise.all(
|
||||
_.map(namespaces, async (ns) => {
|
||||
const [deployments, daemonSets, statefulSets, services, pods, ingresses, autoScalers] = await Promise.all([
|
||||
this.KubernetesDeploymentService.get(ns),
|
||||
this.KubernetesDaemonSetService.get(ns),
|
||||
this.KubernetesStatefulSetService.get(ns),
|
||||
this.KubernetesServiceService.get(ns),
|
||||
this.KubernetesPodService.get(ns),
|
||||
this.KubernetesIngressService.get(ns),
|
||||
this.KubernetesHorizontalPodAutoScalerService.get(ns),
|
||||
]);
|
||||
const res = await Promise.all(
|
||||
_.map(namespaces, async (ns) => {
|
||||
const [deployments, daemonSets, statefulSets, services, pods, ingresses, autoScalers] = await Promise.all([
|
||||
this.KubernetesDeploymentService.get(ns),
|
||||
this.KubernetesDaemonSetService.get(ns),
|
||||
this.KubernetesStatefulSetService.get(ns),
|
||||
this.KubernetesServiceService.get(ns),
|
||||
this.KubernetesPodService.get(ns),
|
||||
this.KubernetesIngressService.get(ns),
|
||||
this.KubernetesHorizontalPodAutoScalerService.get(ns),
|
||||
]);
|
||||
|
||||
const deploymentApplications = _.map(deployments, (item) =>
|
||||
convertToApplication(item, KubernetesApplicationConverter.apiDeploymentToApplication, services, pods, ingresses)
|
||||
);
|
||||
const daemonSetApplications = _.map(daemonSets, (item) =>
|
||||
convertToApplication(item, KubernetesApplicationConverter.apiDaemonSetToApplication, services, pods, ingresses)
|
||||
);
|
||||
const statefulSetApplications = _.map(statefulSets, (item) =>
|
||||
convertToApplication(item, KubernetesApplicationConverter.apiStatefulSetToapplication, services, pods, ingresses)
|
||||
);
|
||||
const deploymentApplications = _.map(deployments, (item) =>
|
||||
convertToApplication(item, KubernetesApplicationConverter.apiDeploymentToApplication, services, pods, ingresses)
|
||||
);
|
||||
const daemonSetApplications = _.map(daemonSets, (item) => convertToApplication(item, KubernetesApplicationConverter.apiDaemonSetToApplication, services, pods, ingresses));
|
||||
const statefulSetApplications = _.map(statefulSets, (item) =>
|
||||
convertToApplication(item, KubernetesApplicationConverter.apiStatefulSetToapplication, services, pods, ingresses)
|
||||
);
|
||||
|
||||
const boundPods = _.concat(_.flatMap(deploymentApplications, 'Pods'), _.flatMap(daemonSetApplications, 'Pods'), _.flatMap(statefulSetApplications, 'Pods'));
|
||||
const unboundPods = _.without(pods, ...boundPods);
|
||||
const nakedPodsApplications = _.map(unboundPods, (item) => convertToApplication(item, KubernetesApplicationConverter.apiPodToApplication, services, pods, ingresses));
|
||||
const boundPods = _.concat(_.flatMap(deploymentApplications, 'Pods'), _.flatMap(daemonSetApplications, 'Pods'), _.flatMap(statefulSetApplications, 'Pods'));
|
||||
const unboundPods = _.without(pods, ...boundPods);
|
||||
const nakedPodsApplications = _.map(unboundPods, (item) => convertToApplication(item, KubernetesApplicationConverter.apiPodToApplication, services, pods, ingresses));
|
||||
|
||||
const applications = _.concat(deploymentApplications, daemonSetApplications, statefulSetApplications, nakedPodsApplications);
|
||||
_.forEach(applications, (app) => {
|
||||
app.Pods = _.map(app.Pods, (item) => KubernetesPodConverter.apiToModel(item));
|
||||
});
|
||||
await Promise.all(
|
||||
_.forEach(applications, async (application) => {
|
||||
const boundScaler = KubernetesHorizontalPodAutoScalerHelper.findApplicationBoundScaler(autoScalers, application);
|
||||
const scaler = boundScaler ? await this.KubernetesHorizontalPodAutoScalerService.get(ns, boundScaler.Name) : undefined;
|
||||
application.AutoScaler = scaler;
|
||||
})
|
||||
);
|
||||
return applications;
|
||||
})
|
||||
);
|
||||
return _.flatten(res);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const applications = _.concat(deploymentApplications, daemonSetApplications, statefulSetApplications, nakedPodsApplications);
|
||||
_.forEach(applications, (app) => {
|
||||
app.Pods = _.map(app.Pods, (item) => KubernetesPodConverter.apiToModel(item));
|
||||
});
|
||||
await Promise.all(
|
||||
_.forEach(applications, async (application) => {
|
||||
const boundScaler = KubernetesHorizontalPodAutoScalerHelper.findApplicationBoundScaler(autoScalers, application);
|
||||
const scaler = boundScaler ? await this.KubernetesHorizontalPodAutoScalerService.get(ns, boundScaler.Name) : undefined;
|
||||
application.AutoScaler = scaler;
|
||||
})
|
||||
);
|
||||
return applications;
|
||||
})
|
||||
);
|
||||
return _.flatten(res);
|
||||
}
|
||||
|
||||
get(namespace, name) {
|
||||
|
@ -226,42 +214,38 @@ class KubernetesApplicationService {
|
|||
* also be displayed in the summary output (getCreatedApplicationResources)
|
||||
*/
|
||||
async createAsync(formValues) {
|
||||
try {
|
||||
let [app, headlessService, service, claims] = KubernetesApplicationConverter.applicationFormValuesToApplication(formValues);
|
||||
let [app, headlessService, service, claims] = KubernetesApplicationConverter.applicationFormValuesToApplication(formValues);
|
||||
|
||||
if (service) {
|
||||
await this.KubernetesServiceService.create(service);
|
||||
if (formValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(formValues, service.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(formValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
if (service) {
|
||||
await this.KubernetesServiceService.create(service);
|
||||
if (formValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(formValues, service.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(formValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
|
||||
const apiService = this._getApplicationApiService(app);
|
||||
|
||||
if (app instanceof KubernetesStatefulSet) {
|
||||
app.VolumeClaims = claims;
|
||||
headlessService = await this.KubernetesServiceService.create(headlessService);
|
||||
app.ServiceName = headlessService.metadata.name;
|
||||
} else {
|
||||
const claimPromises = _.map(claims, (item) => {
|
||||
if (!item.PreviousName && !item.Id) {
|
||||
return this.KubernetesPersistentVolumeClaimService.create(item);
|
||||
}
|
||||
});
|
||||
await Promise.all(_.without(claimPromises, undefined));
|
||||
}
|
||||
|
||||
if (formValues.AutoScaler.IsUsed && formValues.DeploymentType !== KubernetesApplicationDeploymentTypes.GLOBAL) {
|
||||
const kind = KubernetesHorizontalPodAutoScalerHelper.getApplicationTypeString(app);
|
||||
const autoScaler = KubernetesHorizontalPodAutoScalerConverter.applicationFormValuesToModel(formValues, kind);
|
||||
await this.KubernetesHorizontalPodAutoScalerService.create(autoScaler);
|
||||
}
|
||||
|
||||
await apiService.create(app);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
const apiService = this._getApplicationApiService(app);
|
||||
|
||||
if (app instanceof KubernetesStatefulSet) {
|
||||
app.VolumeClaims = claims;
|
||||
headlessService = await this.KubernetesServiceService.create(headlessService);
|
||||
app.ServiceName = headlessService.metadata.name;
|
||||
} else {
|
||||
const claimPromises = _.map(claims, (item) => {
|
||||
if (!item.PreviousName && !item.Id) {
|
||||
return this.KubernetesPersistentVolumeClaimService.create(item);
|
||||
}
|
||||
});
|
||||
await Promise.all(_.without(claimPromises, undefined));
|
||||
}
|
||||
|
||||
if (formValues.AutoScaler.IsUsed && formValues.DeploymentType !== KubernetesApplicationDeploymentTypes.GLOBAL) {
|
||||
const kind = KubernetesHorizontalPodAutoScalerHelper.getApplicationTypeString(app);
|
||||
const autoScaler = KubernetesHorizontalPodAutoScalerConverter.applicationFormValuesToModel(formValues, kind);
|
||||
await this.KubernetesHorizontalPodAutoScalerService.create(autoScaler);
|
||||
}
|
||||
|
||||
await apiService.create(app);
|
||||
}
|
||||
|
||||
create(formValues) {
|
||||
|
@ -277,97 +261,89 @@ class KubernetesApplicationService {
|
|||
* in this method should also be displayed in the summary output (getUpdatedApplicationResources)
|
||||
*/
|
||||
async patchAsync(oldFormValues, newFormValues) {
|
||||
try {
|
||||
const [oldApp, oldHeadlessService, oldService, oldClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(oldFormValues);
|
||||
const [newApp, newHeadlessService, newService, newClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(newFormValues);
|
||||
const oldApiService = this._getApplicationApiService(oldApp);
|
||||
const newApiService = this._getApplicationApiService(newApp);
|
||||
const [oldApp, oldHeadlessService, oldService, oldClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(oldFormValues);
|
||||
const [newApp, newHeadlessService, newService, newClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(newFormValues);
|
||||
const oldApiService = this._getApplicationApiService(oldApp);
|
||||
const newApiService = this._getApplicationApiService(newApp);
|
||||
|
||||
if (oldApiService !== newApiService) {
|
||||
await this.delete(oldApp);
|
||||
if (oldService) {
|
||||
await this.KubernetesServiceService.delete(oldService);
|
||||
}
|
||||
return await this.create(newFormValues);
|
||||
}
|
||||
|
||||
if (newApp instanceof KubernetesStatefulSet) {
|
||||
await this.KubernetesServiceService.patch(oldHeadlessService, newHeadlessService);
|
||||
} else {
|
||||
const claimPromises = _.map(newClaims, (newClaim) => {
|
||||
if (!newClaim.PreviousName && !newClaim.Id) {
|
||||
return this.KubernetesPersistentVolumeClaimService.create(newClaim);
|
||||
} else if (!newClaim.Id) {
|
||||
const oldClaim = _.find(oldClaims, { Name: newClaim.PreviousName });
|
||||
return this.KubernetesPersistentVolumeClaimService.patch(oldClaim, newClaim);
|
||||
}
|
||||
});
|
||||
await Promise.all(claimPromises);
|
||||
}
|
||||
|
||||
await newApiService.patch(oldApp, newApp);
|
||||
|
||||
if (oldService && newService) {
|
||||
await this.KubernetesServiceService.patch(oldService, newService);
|
||||
if (newFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS || oldFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const oldIngresses = KubernetesIngressConverter.applicationFormValuesToIngresses(oldFormValues, oldService.Name);
|
||||
const newIngresses = KubernetesIngressConverter.applicationFormValuesToIngresses(newFormValues, newService.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(oldIngresses, newIngresses));
|
||||
}
|
||||
} else if (!oldService && newService) {
|
||||
await this.KubernetesServiceService.create(newService);
|
||||
if (newFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(newFormValues, newService.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(newFormValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
} else if (oldService && !newService) {
|
||||
if (oldApiService !== newApiService) {
|
||||
await this.delete(oldApp);
|
||||
if (oldService) {
|
||||
await this.KubernetesServiceService.delete(oldService);
|
||||
if (oldFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(newFormValues, oldService.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(oldFormValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
}
|
||||
return await this.create(newFormValues);
|
||||
}
|
||||
|
||||
const newKind = KubernetesHorizontalPodAutoScalerHelper.getApplicationTypeString(newApp);
|
||||
const newAutoScaler = KubernetesHorizontalPodAutoScalerConverter.applicationFormValuesToModel(newFormValues, newKind);
|
||||
if (!oldFormValues.AutoScaler.IsUsed) {
|
||||
if (newFormValues.AutoScaler.IsUsed) {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.create(newAutoScaler);
|
||||
}
|
||||
} else {
|
||||
const oldKind = KubernetesHorizontalPodAutoScalerHelper.getApplicationTypeString(oldApp);
|
||||
const oldAutoScaler = KubernetesHorizontalPodAutoScalerConverter.applicationFormValuesToModel(oldFormValues, oldKind);
|
||||
if (newFormValues.AutoScaler.IsUsed) {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.patch(oldAutoScaler, newAutoScaler);
|
||||
} else {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.delete(oldAutoScaler);
|
||||
if (newApp instanceof KubernetesStatefulSet) {
|
||||
await this.KubernetesServiceService.patch(oldHeadlessService, newHeadlessService);
|
||||
} else {
|
||||
const claimPromises = _.map(newClaims, (newClaim) => {
|
||||
if (!newClaim.PreviousName && !newClaim.Id) {
|
||||
return this.KubernetesPersistentVolumeClaimService.create(newClaim);
|
||||
} else if (!newClaim.Id) {
|
||||
const oldClaim = _.find(oldClaims, { Name: newClaim.PreviousName });
|
||||
return this.KubernetesPersistentVolumeClaimService.patch(oldClaim, newClaim);
|
||||
}
|
||||
});
|
||||
await Promise.all(claimPromises);
|
||||
}
|
||||
|
||||
await newApiService.patch(oldApp, newApp);
|
||||
|
||||
if (oldService && newService) {
|
||||
await this.KubernetesServiceService.patch(oldService, newService);
|
||||
if (newFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS || oldFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const oldIngresses = KubernetesIngressConverter.applicationFormValuesToIngresses(oldFormValues, oldService.Name);
|
||||
const newIngresses = KubernetesIngressConverter.applicationFormValuesToIngresses(newFormValues, newService.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(oldIngresses, newIngresses));
|
||||
}
|
||||
} else if (!oldService && newService) {
|
||||
await this.KubernetesServiceService.create(newService);
|
||||
if (newFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(newFormValues, newService.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(newFormValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
} else if (oldService && !newService) {
|
||||
await this.KubernetesServiceService.delete(oldService);
|
||||
if (oldFormValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(newFormValues, oldService.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(oldFormValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
}
|
||||
|
||||
const newKind = KubernetesHorizontalPodAutoScalerHelper.getApplicationTypeString(newApp);
|
||||
const newAutoScaler = KubernetesHorizontalPodAutoScalerConverter.applicationFormValuesToModel(newFormValues, newKind);
|
||||
if (!oldFormValues.AutoScaler.IsUsed) {
|
||||
if (newFormValues.AutoScaler.IsUsed) {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.create(newAutoScaler);
|
||||
}
|
||||
} else {
|
||||
const oldKind = KubernetesHorizontalPodAutoScalerHelper.getApplicationTypeString(oldApp);
|
||||
const oldAutoScaler = KubernetesHorizontalPodAutoScalerConverter.applicationFormValuesToModel(oldFormValues, oldKind);
|
||||
if (newFormValues.AutoScaler.IsUsed) {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.patch(oldAutoScaler, newAutoScaler);
|
||||
} else {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.delete(oldAutoScaler);
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
// this function accepts KubernetesApplication as parameters
|
||||
async patchPartialAsync(oldApp, newApp) {
|
||||
try {
|
||||
const oldAppPayload = {
|
||||
Name: oldApp.Name,
|
||||
Namespace: oldApp.ResourcePool,
|
||||
StackName: oldApp.StackName,
|
||||
Note: oldApp.Note,
|
||||
};
|
||||
const newAppPayload = {
|
||||
Name: newApp.Name,
|
||||
Namespace: newApp.ResourcePool,
|
||||
StackName: newApp.StackName,
|
||||
Note: newApp.Note,
|
||||
};
|
||||
const apiService = this._getApplicationApiService(oldApp);
|
||||
await apiService.patch(oldAppPayload, newAppPayload);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const oldAppPayload = {
|
||||
Name: oldApp.Name,
|
||||
Namespace: oldApp.ResourcePool,
|
||||
StackName: oldApp.StackName,
|
||||
Note: oldApp.Note,
|
||||
};
|
||||
const newAppPayload = {
|
||||
Name: newApp.Name,
|
||||
Namespace: newApp.ResourcePool,
|
||||
StackName: newApp.StackName,
|
||||
Note: newApp.Note,
|
||||
};
|
||||
const apiService = this._getApplicationApiService(oldApp);
|
||||
await apiService.patch(oldAppPayload, newAppPayload);
|
||||
}
|
||||
|
||||
// accept either formValues or applications as parameters
|
||||
|
@ -384,42 +360,38 @@ class KubernetesApplicationService {
|
|||
|
||||
/* #region DELETE */
|
||||
async deleteAsync(application) {
|
||||
try {
|
||||
const payload = {
|
||||
Namespace: application.ResourcePool || application.Namespace,
|
||||
Name: application.Name,
|
||||
};
|
||||
const servicePayload = angular.copy(payload);
|
||||
servicePayload.Name = application.Name;
|
||||
const payload = {
|
||||
Namespace: application.ResourcePool || application.Namespace,
|
||||
Name: application.Name,
|
||||
};
|
||||
const servicePayload = angular.copy(payload);
|
||||
servicePayload.Name = application.Name;
|
||||
|
||||
const apiService = this._getApplicationApiService(application);
|
||||
await apiService.delete(payload);
|
||||
const apiService = this._getApplicationApiService(application);
|
||||
await apiService.delete(payload);
|
||||
|
||||
if (apiService === this.KubernetesStatefulSetService) {
|
||||
const headlessServicePayload = angular.copy(payload);
|
||||
headlessServicePayload.Name = application instanceof KubernetesStatefulSet ? application.ServiceName : application.HeadlessServiceName;
|
||||
await this.KubernetesServiceService.delete(headlessServicePayload);
|
||||
}
|
||||
if (apiService === this.KubernetesStatefulSetService) {
|
||||
const headlessServicePayload = angular.copy(payload);
|
||||
headlessServicePayload.Name = application instanceof KubernetesStatefulSet ? application.ServiceName : application.HeadlessServiceName;
|
||||
await this.KubernetesServiceService.delete(headlessServicePayload);
|
||||
}
|
||||
|
||||
if (application.ServiceType) {
|
||||
await this.KubernetesServiceService.delete(servicePayload);
|
||||
const isIngress = _.filter(application.PublishedPorts, (p) => p.IngressRules.length).length;
|
||||
if (isIngress) {
|
||||
const originalIngresses = await this.KubernetesIngressService.get(payload.Namespace);
|
||||
const formValues = {
|
||||
OriginalIngresses: originalIngresses,
|
||||
PublishedPorts: KubernetesApplicationHelper.generatePublishedPortsFormValuesFromPublishedPorts(application.ServiceType, application.PublishedPorts),
|
||||
};
|
||||
_.forEach(formValues.PublishedPorts, (p) => (p.NeedsDeletion = true));
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(formValues, servicePayload.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(formValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
if (application.ServiceType) {
|
||||
await this.KubernetesServiceService.delete(servicePayload);
|
||||
const isIngress = _.filter(application.PublishedPorts, (p) => p.IngressRules.length).length;
|
||||
if (isIngress) {
|
||||
const originalIngresses = await this.KubernetesIngressService.get(payload.Namespace);
|
||||
const formValues = {
|
||||
OriginalIngresses: originalIngresses,
|
||||
PublishedPorts: KubernetesApplicationHelper.generatePublishedPortsFormValuesFromPublishedPorts(application.ServiceType, application.PublishedPorts),
|
||||
};
|
||||
_.forEach(formValues.PublishedPorts, (p) => (p.NeedsDeletion = true));
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(formValues, servicePayload.Name);
|
||||
await Promise.all(this._generateIngressPatchPromises(formValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
if (!_.isEmpty(application.AutoScaler)) {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.delete(application.AutoScaler);
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
if (!_.isEmpty(application.AutoScaler)) {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.delete(application.AutoScaler);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -430,13 +402,9 @@ class KubernetesApplicationService {
|
|||
|
||||
/* #region ROLLBACK */
|
||||
async rollbackAsync(application, targetRevision) {
|
||||
try {
|
||||
const payload = KubernetesApplicationRollbackHelper.getPatchPayload(application, targetRevision);
|
||||
const apiService = this._getApplicationApiService(application);
|
||||
await apiService.rollback(application.ResourcePool, application.Name, payload);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const payload = KubernetesApplicationRollbackHelper.getPatchPayload(application, targetRevision);
|
||||
const apiService = this._getApplicationApiService(application);
|
||||
await apiService.rollback(application.ResourcePool, application.Name, payload);
|
||||
}
|
||||
|
||||
rollback(application, targetRevision) {
|
||||
|
|
|
@ -26,35 +26,27 @@ class KubernetesConfigurationService {
|
|||
* GET
|
||||
*/
|
||||
async getAsync(namespace, name) {
|
||||
try {
|
||||
const [configMap, secret] = await Promise.allSettled([this.KubernetesConfigMapService.get(namespace, name), this.KubernetesSecretService.get(namespace, name)]);
|
||||
let configuration;
|
||||
if (secret.status === 'fulfilled') {
|
||||
configuration = KubernetesConfigurationConverter.secretToConfiguration(secret.value);
|
||||
return configuration;
|
||||
}
|
||||
configuration = KubernetesConfigurationConverter.configMapToConfiguration(configMap.value);
|
||||
const [configMap, secret] = await Promise.allSettled([this.KubernetesConfigMapService.get(namespace, name), this.KubernetesSecretService.get(namespace, name)]);
|
||||
let configuration;
|
||||
if (secret.status === 'fulfilled') {
|
||||
configuration = KubernetesConfigurationConverter.secretToConfiguration(secret.value);
|
||||
return configuration;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
configuration = KubernetesConfigurationConverter.configMapToConfiguration(configMap.value);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
async getAllAsync(namespace) {
|
||||
try {
|
||||
const namespaces = namespace ? [namespace] : _.map(await this.KubernetesNamespaceService.get(), 'Name');
|
||||
const res = await Promise.all(
|
||||
_.map(namespaces, async (ns) => {
|
||||
const [configMaps, secrets] = await Promise.all([this.KubernetesConfigMapService.get(ns), this.KubernetesSecretService.get(ns)]);
|
||||
const secretsConfigurations = _.map(secrets, (secret) => KubernetesConfigurationConverter.secretToConfiguration(secret));
|
||||
const configMapsConfigurations = _.map(configMaps, (configMap) => KubernetesConfigurationConverter.configMapToConfiguration(configMap));
|
||||
return _.concat(configMapsConfigurations, secretsConfigurations);
|
||||
})
|
||||
);
|
||||
return _.flatten(res);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const namespaces = namespace ? [namespace] : _.map(await this.KubernetesNamespaceService.get(), 'Name');
|
||||
const res = await Promise.all(
|
||||
_.map(namespaces, async (ns) => {
|
||||
const [configMaps, secrets] = await Promise.all([this.KubernetesConfigMapService.get(ns), this.KubernetesSecretService.get(ns)]);
|
||||
const secretsConfigurations = _.map(secrets, (secret) => KubernetesConfigurationConverter.secretToConfiguration(secret));
|
||||
const configMapsConfigurations = _.map(configMaps, (configMap) => KubernetesConfigurationConverter.configMapToConfiguration(configMap));
|
||||
return _.concat(configMapsConfigurations, secretsConfigurations);
|
||||
})
|
||||
);
|
||||
return _.flatten(res);
|
||||
}
|
||||
|
||||
get(namespace, name) {
|
||||
|
@ -70,16 +62,12 @@ class KubernetesConfigurationService {
|
|||
async createAsync(formValues) {
|
||||
formValues.ConfigurationOwner = KubernetesCommonHelper.ownerToLabel(formValues.ConfigurationOwner);
|
||||
|
||||
try {
|
||||
if (formValues.Type === KubernetesConfigurationTypes.CONFIGMAP) {
|
||||
const configMap = KubernetesConfigMapConverter.configurationFormValuesToConfigMap(formValues);
|
||||
await this.KubernetesConfigMapService.create(configMap);
|
||||
} else {
|
||||
const secret = KubernetesSecretConverter.configurationFormValuesToSecret(formValues);
|
||||
await this.KubernetesSecretService.create(secret);
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
if (formValues.Type === KubernetesConfigurationTypes.CONFIGMAP) {
|
||||
const configMap = KubernetesConfigMapConverter.configurationFormValuesToConfigMap(formValues);
|
||||
await this.KubernetesConfigMapService.create(configMap);
|
||||
} else {
|
||||
const secret = KubernetesSecretConverter.configurationFormValuesToSecret(formValues);
|
||||
await this.KubernetesSecretService.create(secret);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,18 +79,14 @@ class KubernetesConfigurationService {
|
|||
* UPDATE
|
||||
*/
|
||||
async updateAsync(formValues, configuration) {
|
||||
try {
|
||||
if (formValues.Type === KubernetesConfigurationTypes.CONFIGMAP) {
|
||||
const configMap = KubernetesConfigMapConverter.configurationFormValuesToConfigMap(formValues);
|
||||
configMap.ConfigurationOwner = configuration.ConfigurationOwner;
|
||||
await this.KubernetesConfigMapService.update(configMap);
|
||||
} else {
|
||||
const secret = KubernetesSecretConverter.configurationFormValuesToSecret(formValues);
|
||||
secret.ConfigurationOwner = configuration.ConfigurationOwner;
|
||||
await this.KubernetesSecretService.update(secret);
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
if (formValues.Type === KubernetesConfigurationTypes.CONFIGMAP) {
|
||||
const configMap = KubernetesConfigMapConverter.configurationFormValuesToConfigMap(formValues);
|
||||
configMap.ConfigurationOwner = configuration.ConfigurationOwner;
|
||||
await this.KubernetesConfigMapService.update(configMap);
|
||||
} else {
|
||||
const secret = KubernetesSecretConverter.configurationFormValuesToSecret(formValues);
|
||||
secret.ConfigurationOwner = configuration.ConfigurationOwner;
|
||||
await this.KubernetesSecretService.update(secret);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,14 +98,10 @@ class KubernetesConfigurationService {
|
|||
* DELETE
|
||||
*/
|
||||
async deleteAsync(config) {
|
||||
try {
|
||||
if (config.Type === KubernetesConfigurationTypes.CONFIGMAP) {
|
||||
await this.KubernetesConfigMapService.delete(config);
|
||||
} else {
|
||||
await this.KubernetesSecretService.delete(config);
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
if (config.Type === KubernetesConfigurationTypes.CONFIGMAP) {
|
||||
await this.KubernetesConfigMapService.delete(config);
|
||||
} else {
|
||||
await this.KubernetesSecretService.delete(config);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,39 +14,31 @@ export function KubernetesResourcePoolService($async, EndpointService, Kubernete
|
|||
};
|
||||
|
||||
async function getOne(name) {
|
||||
try {
|
||||
const namespace = await KubernetesNamespaceService.get(name);
|
||||
const [quotaAttempt] = await Promise.allSettled([KubernetesResourceQuotaService.get(name, KubernetesResourceQuotaHelper.generateResourceQuotaName(name))]);
|
||||
const pool = KubernetesResourcePoolConverter.apiToResourcePool(namespace);
|
||||
if (quotaAttempt.status === 'fulfilled') {
|
||||
pool.Quota = quotaAttempt.value;
|
||||
pool.Yaml += '---\n' + quotaAttempt.value.Yaml;
|
||||
}
|
||||
return pool;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
const namespace = await KubernetesNamespaceService.get(name);
|
||||
const [quotaAttempt] = await Promise.allSettled([KubernetesResourceQuotaService.get(name, KubernetesResourceQuotaHelper.generateResourceQuotaName(name))]);
|
||||
const pool = KubernetesResourcePoolConverter.apiToResourcePool(namespace);
|
||||
if (quotaAttempt.status === 'fulfilled') {
|
||||
pool.Quota = quotaAttempt.value;
|
||||
pool.Yaml += '---\n' + quotaAttempt.value.Yaml;
|
||||
}
|
||||
return pool;
|
||||
}
|
||||
|
||||
async function getAll() {
|
||||
try {
|
||||
const namespaces = await KubernetesNamespaceService.get();
|
||||
const pools = await Promise.all(
|
||||
_.map(namespaces, async (namespace) => {
|
||||
const name = namespace.Name;
|
||||
const [quotaAttempt] = await Promise.allSettled([KubernetesResourceQuotaService.get(name, KubernetesResourceQuotaHelper.generateResourceQuotaName(name))]);
|
||||
const pool = KubernetesResourcePoolConverter.apiToResourcePool(namespace);
|
||||
if (quotaAttempt.status === 'fulfilled') {
|
||||
pool.Quota = quotaAttempt.value;
|
||||
pool.Yaml += '---\n' + quotaAttempt.value.Yaml;
|
||||
}
|
||||
return pool;
|
||||
})
|
||||
);
|
||||
return pools;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const namespaces = await KubernetesNamespaceService.get();
|
||||
const pools = await Promise.all(
|
||||
_.map(namespaces, async (namespace) => {
|
||||
const name = namespace.Name;
|
||||
const [quotaAttempt] = await Promise.allSettled([KubernetesResourceQuotaService.get(name, KubernetesResourceQuotaHelper.generateResourceQuotaName(name))]);
|
||||
const pool = KubernetesResourcePoolConverter.apiToResourcePool(namespace);
|
||||
if (quotaAttempt.status === 'fulfilled') {
|
||||
pool.Quota = quotaAttempt.value;
|
||||
pool.Yaml += '---\n' + quotaAttempt.value.Yaml;
|
||||
}
|
||||
return pool;
|
||||
})
|
||||
);
|
||||
return pools;
|
||||
}
|
||||
|
||||
function get(name) {
|
||||
|
@ -58,80 +50,68 @@ export function KubernetesResourcePoolService($async, EndpointService, Kubernete
|
|||
|
||||
function create(formValues) {
|
||||
return $async(async () => {
|
||||
try {
|
||||
const [namespace, quota, ingresses, registries] = KubernetesResourcePoolConverter.formValuesToResourcePool(formValues);
|
||||
await KubernetesNamespaceService.create(namespace);
|
||||
const [namespace, quota, ingresses, registries] = KubernetesResourcePoolConverter.formValuesToResourcePool(formValues);
|
||||
await KubernetesNamespaceService.create(namespace);
|
||||
|
||||
if (quota) {
|
||||
await KubernetesResourceQuotaService.create(quota);
|
||||
}
|
||||
const ingressPromises = _.map(ingresses, (i) => KubernetesIngressService.create(i));
|
||||
await Promise.all(ingressPromises);
|
||||
|
||||
const endpointId = formValues.EndpointId;
|
||||
const registriesPromises = _.map(registries, (r) => EndpointService.updateRegistryAccess(endpointId, r.Id, r.RegistryAccesses[endpointId]));
|
||||
await Promise.all(registriesPromises);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
if (quota) {
|
||||
await KubernetesResourceQuotaService.create(quota);
|
||||
}
|
||||
const ingressPromises = _.map(ingresses, (i) => KubernetesIngressService.create(i));
|
||||
await Promise.all(ingressPromises);
|
||||
|
||||
const endpointId = formValues.EndpointId;
|
||||
const registriesPromises = _.map(registries, (r) => EndpointService.updateRegistryAccess(endpointId, r.Id, r.RegistryAccesses[endpointId]));
|
||||
await Promise.all(registriesPromises);
|
||||
});
|
||||
}
|
||||
|
||||
function patch(oldFormValues, newFormValues) {
|
||||
return $async(async () => {
|
||||
try {
|
||||
const [oldNamespace, oldQuota, oldIngresses, oldRegistries] = KubernetesResourcePoolConverter.formValuesToResourcePool(oldFormValues);
|
||||
const [newNamespace, newQuota, newIngresses, newRegistries] = KubernetesResourcePoolConverter.formValuesToResourcePool(newFormValues);
|
||||
void oldNamespace, newNamespace;
|
||||
const [oldNamespace, oldQuota, oldIngresses, oldRegistries] = KubernetesResourcePoolConverter.formValuesToResourcePool(oldFormValues);
|
||||
const [newNamespace, newQuota, newIngresses, newRegistries] = KubernetesResourcePoolConverter.formValuesToResourcePool(newFormValues);
|
||||
void oldNamespace, newNamespace;
|
||||
|
||||
if (oldQuota && newQuota) {
|
||||
await KubernetesResourceQuotaService.patch(oldQuota, newQuota);
|
||||
} else if (!oldQuota && newQuota) {
|
||||
await KubernetesResourceQuotaService.create(newQuota);
|
||||
} else if (oldQuota && !newQuota) {
|
||||
await KubernetesResourceQuotaService.delete(oldQuota);
|
||||
}
|
||||
|
||||
const create = _.filter(newIngresses, (ing) => !_.find(oldIngresses, { Name: ing.Name }));
|
||||
const del = _.filter(oldIngresses, (ing) => !_.find(newIngresses, { Name: ing.Name }));
|
||||
const patch = _.without(newIngresses, ...create);
|
||||
|
||||
const createPromises = _.map(create, (i) => KubernetesIngressService.create(i));
|
||||
const delPromises = _.map(del, (i) => KubernetesIngressService.delete(i.Namespace, i.Name));
|
||||
const patchPromises = _.map(patch, (ing) => {
|
||||
const old = _.find(oldIngresses, { Name: ing.Name });
|
||||
ing.Paths = angular.copy(old.Paths);
|
||||
ing.PreviousHost = old.Host;
|
||||
return KubernetesIngressService.patch(old, ing);
|
||||
});
|
||||
|
||||
const promises = _.flatten([createPromises, delPromises, patchPromises]);
|
||||
await Promise.all(promises);
|
||||
|
||||
const endpointId = newFormValues.EndpointId;
|
||||
const keptRegistries = _.intersectionBy(oldRegistries, newRegistries, 'Id');
|
||||
const removedRegistries = _.without(oldRegistries, ...keptRegistries);
|
||||
|
||||
const newRegistriesPromises = _.map(newRegistries, (r) => EndpointService.updateRegistryAccess(endpointId, r.Id, r.RegistryAccesses[endpointId]));
|
||||
const removedRegistriesPromises = _.map(removedRegistries, (r) => {
|
||||
_.pull(r.RegistryAccesses[endpointId].Namespaces, newFormValues.Name);
|
||||
return EndpointService.updateRegistryAccess(endpointId, r.Id, r.RegistryAccesses[endpointId]);
|
||||
});
|
||||
|
||||
await Promise.all(_.concat(newRegistriesPromises, removedRegistriesPromises));
|
||||
} catch (err) {
|
||||
throw err;
|
||||
if (oldQuota && newQuota) {
|
||||
await KubernetesResourceQuotaService.patch(oldQuota, newQuota);
|
||||
} else if (!oldQuota && newQuota) {
|
||||
await KubernetesResourceQuotaService.create(newQuota);
|
||||
} else if (oldQuota && !newQuota) {
|
||||
await KubernetesResourceQuotaService.delete(oldQuota);
|
||||
}
|
||||
|
||||
const create = _.filter(newIngresses, (ing) => !_.find(oldIngresses, { Name: ing.Name }));
|
||||
const del = _.filter(oldIngresses, (ing) => !_.find(newIngresses, { Name: ing.Name }));
|
||||
const patch = _.without(newIngresses, ...create);
|
||||
|
||||
const createPromises = _.map(create, (i) => KubernetesIngressService.create(i));
|
||||
const delPromises = _.map(del, (i) => KubernetesIngressService.delete(i.Namespace, i.Name));
|
||||
const patchPromises = _.map(patch, (ing) => {
|
||||
const old = _.find(oldIngresses, { Name: ing.Name });
|
||||
ing.Paths = angular.copy(old.Paths);
|
||||
ing.PreviousHost = old.Host;
|
||||
return KubernetesIngressService.patch(old, ing);
|
||||
});
|
||||
|
||||
const promises = _.flatten([createPromises, delPromises, patchPromises]);
|
||||
await Promise.all(promises);
|
||||
|
||||
const endpointId = newFormValues.EndpointId;
|
||||
const keptRegistries = _.intersectionBy(oldRegistries, newRegistries, 'Id');
|
||||
const removedRegistries = _.without(oldRegistries, ...keptRegistries);
|
||||
|
||||
const newRegistriesPromises = _.map(newRegistries, (r) => EndpointService.updateRegistryAccess(endpointId, r.Id, r.RegistryAccesses[endpointId]));
|
||||
const removedRegistriesPromises = _.map(removedRegistries, (r) => {
|
||||
_.pull(r.RegistryAccesses[endpointId].Namespaces, newFormValues.Name);
|
||||
return EndpointService.updateRegistryAccess(endpointId, r.Id, r.RegistryAccesses[endpointId]);
|
||||
});
|
||||
|
||||
await Promise.all(_.concat(newRegistriesPromises, removedRegistriesPromises));
|
||||
});
|
||||
}
|
||||
|
||||
function _delete(pool) {
|
||||
return $async(async () => {
|
||||
try {
|
||||
await KubernetesNamespaceService.delete(pool.Namespace);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
await KubernetesNamespaceService.delete(pool.Namespace);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,13 +14,9 @@ class KubernetesStackService {
|
|||
* GET
|
||||
*/
|
||||
async getAllAsync(namespace) {
|
||||
try {
|
||||
const applications = await this.KubernetesApplicationService.get(namespace);
|
||||
const stacks = _.map(applications, (item) => item.StackName);
|
||||
return _.uniq(_.without(stacks, '-'));
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const applications = await this.KubernetesApplicationService.get(namespace);
|
||||
const stacks = _.map(applications, (item) => item.StackName);
|
||||
return _.uniq(_.without(stacks, '-'));
|
||||
}
|
||||
|
||||
get(namespace) {
|
||||
|
|
|
@ -20,28 +20,20 @@ class KubernetesVolumeService {
|
|||
* GET
|
||||
*/
|
||||
async getAsync(namespace, name) {
|
||||
try {
|
||||
const [pvc, pool] = await Promise.all([this.KubernetesPersistentVolumeClaimService.get(namespace, name), this.KubernetesResourcePoolService.get(namespace)]);
|
||||
return KubernetesVolumeConverter.pvcToVolume(pvc, pool);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const [pvc, pool] = await Promise.all([this.KubernetesPersistentVolumeClaimService.get(namespace, name), this.KubernetesResourcePoolService.get(namespace)]);
|
||||
return KubernetesVolumeConverter.pvcToVolume(pvc, pool);
|
||||
}
|
||||
|
||||
async getAllAsync(namespace) {
|
||||
try {
|
||||
const data = await this.KubernetesResourcePoolService.get(namespace);
|
||||
const pools = data instanceof Array ? data : [data];
|
||||
const res = await Promise.all(
|
||||
_.map(pools, async (pool) => {
|
||||
const pvcs = await this.KubernetesPersistentVolumeClaimService.get(pool.Namespace.Name);
|
||||
return _.map(pvcs, (pvc) => KubernetesVolumeConverter.pvcToVolume(pvc, pool));
|
||||
})
|
||||
);
|
||||
return _.flatten(res);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
const data = await this.KubernetesResourcePoolService.get(namespace);
|
||||
const pools = data instanceof Array ? data : [data];
|
||||
const res = await Promise.all(
|
||||
_.map(pools, async (pool) => {
|
||||
const pvcs = await this.KubernetesPersistentVolumeClaimService.get(pool.Namespace.Name);
|
||||
return _.map(pvcs, (pvc) => KubernetesVolumeConverter.pvcToVolume(pvc, pool));
|
||||
})
|
||||
);
|
||||
return _.flatten(res);
|
||||
}
|
||||
|
||||
get(namespace, name) {
|
||||
|
@ -55,11 +47,7 @@ class KubernetesVolumeService {
|
|||
* DELETE
|
||||
*/
|
||||
async deleteAsync(volume) {
|
||||
try {
|
||||
await this.KubernetesPersistentVolumeClaimService.delete(volume.PersistentVolumeClaim);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
await this.KubernetesPersistentVolumeClaimService.delete(volume.PersistentVolumeClaim);
|
||||
}
|
||||
|
||||
delete(volume) {
|
||||
|
|
|
@ -77,26 +77,22 @@ angular.module('portainer.app').factory('AccessService', [
|
|||
}
|
||||
|
||||
async function accessesAsync(entity, parent) {
|
||||
try {
|
||||
if (!entity) {
|
||||
throw new Error('Unable to retrieve accesses');
|
||||
}
|
||||
if (!entity.UserAccessPolicies) {
|
||||
entity.UserAccessPolicies = {};
|
||||
}
|
||||
if (!entity.TeamAccessPolicies) {
|
||||
entity.TeamAccessPolicies = {};
|
||||
}
|
||||
if (parent && !parent.UserAccessPolicies) {
|
||||
parent.UserAccessPolicies = {};
|
||||
}
|
||||
if (parent && !parent.TeamAccessPolicies) {
|
||||
parent.TeamAccessPolicies = {};
|
||||
}
|
||||
return await getAccesses(entity.UserAccessPolicies, entity.TeamAccessPolicies, parent ? parent.UserAccessPolicies : {}, parent ? parent.TeamAccessPolicies : {});
|
||||
} catch (err) {
|
||||
throw err;
|
||||
if (!entity) {
|
||||
throw new Error('Unable to retrieve accesses');
|
||||
}
|
||||
if (!entity.UserAccessPolicies) {
|
||||
entity.UserAccessPolicies = {};
|
||||
}
|
||||
if (!entity.TeamAccessPolicies) {
|
||||
entity.TeamAccessPolicies = {};
|
||||
}
|
||||
if (parent && !parent.UserAccessPolicies) {
|
||||
parent.UserAccessPolicies = {};
|
||||
}
|
||||
if (parent && !parent.TeamAccessPolicies) {
|
||||
parent.TeamAccessPolicies = {};
|
||||
}
|
||||
return await getAccesses(entity.UserAccessPolicies, entity.TeamAccessPolicies, parent ? parent.UserAccessPolicies : {}, parent ? parent.TeamAccessPolicies : {});
|
||||
}
|
||||
|
||||
function accesses(entity, parent) {
|
||||
|
|
10
package.json
10
package.json
|
@ -119,10 +119,10 @@
|
|||
"cssnano": "^3.10.0",
|
||||
"cypress": "^5.2.0",
|
||||
"cypress-wait-until": "^1.7.1",
|
||||
"eslint": "5.16.0",
|
||||
"eslint-config-prettier": "^6.10.1",
|
||||
"eslint-loader": "^2.1.2",
|
||||
"eslint-plugin-import": "^2.20.2",
|
||||
"eslint": "^7.24.0",
|
||||
"eslint-config-prettier": "^8.2.0",
|
||||
"eslint-plugin-import": "^2.22.1",
|
||||
"eslint-webpack-plugin": "^2.5.3",
|
||||
"file-loader": "^1.1.11",
|
||||
"grunt": "^1.1.0",
|
||||
"grunt-cli": "^1.3.2",
|
||||
|
@ -175,4 +175,4 @@
|
|||
"*.js": "eslint --cache --fix",
|
||||
"*.{js,css,md,html}": "prettier --write"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ const CleanTerminalPlugin = require('clean-terminal-webpack-plugin');
|
|||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
const CleanWebpackPlugin = require('clean-webpack-plugin');
|
||||
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
|
||||
const ESLintPlugin = require('eslint-webpack-plugin');
|
||||
|
||||
const pkg = require('../package.json');
|
||||
const projectRoot = path.resolve(__dirname, '..');
|
||||
|
||||
|
@ -37,14 +39,7 @@ module.exports = {
|
|||
{
|
||||
test: /\.js$/,
|
||||
exclude: /node_modules/,
|
||||
use: [
|
||||
'babel-loader',
|
||||
'auto-ngtemplate-loader',
|
||||
{
|
||||
// enforce: 'pre',
|
||||
loader: 'eslint-loader',
|
||||
},
|
||||
],
|
||||
use: ['babel-loader', 'auto-ngtemplate-loader'],
|
||||
},
|
||||
{
|
||||
test: /\.html$/,
|
||||
|
@ -81,6 +76,7 @@ module.exports = {
|
|||
writeToDisk: true,
|
||||
},
|
||||
plugins: [
|
||||
new ESLintPlugin(),
|
||||
new HtmlWebpackPlugin({
|
||||
template: './app/index.html',
|
||||
templateParameters: {
|
||||
|
|
Loading…
Reference in New Issue