chore(deps): upgrade eslint and use eslint-plugin (#4989)

pull/4964/head
Chaim Lev-Ari 2021-08-24 07:34:18 +03:00 committed by GitHub
parent 5fd92d8a3f
commit ab30793c48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 789 additions and 689 deletions

View File

@ -133,7 +133,7 @@ angular.module('portainer.docker').factory('ImageService', [
Image.create({}, imageConfiguration) Image.create({}, imageConfiguration)
.$promise.then(function success(data) { .$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) { if (err) {
var detail = data[data.length - 1]; var detail = data[data.length - 1];
deferred.reject({ msg: detail.message }); deferred.reject({ msg: detail.message });

View File

@ -16,7 +16,7 @@ angular.module('portainer.integrations.storidge').factory('StoridgeNodeService',
var nodes = []; var nodes = [];
for (var key in nodeData) { for (var key in nodeData) {
if (nodeData.hasOwnProperty(key)) { if (Object.prototype.hasOwnProperty.call(nodeData, key)) {
nodes.push(new StoridgeNodeModel(key, nodeData[key])); nodes.push(new StoridgeNodeModel(key, nodeData[key]));
} }
} }

View File

@ -20,7 +20,7 @@ angular.module('portainer.integrations.storidge').factory('StoridgeSnapshotServi
var snapshotsData = data.snapshots; var snapshotsData = data.snapshots;
let snapshotsArray = []; let snapshotsArray = [];
for (const key in snapshotsData) { for (const key in snapshotsData) {
if (snapshotsData.hasOwnProperty(key)) { if (Object.prototype.hasOwnProperty.call(snapshotsData, key)) {
snapshotsArray.push(snapshotsData[key]); snapshotsArray.push(snapshotsData[key]);
} }
} }

View File

@ -89,122 +89,110 @@ class KubernetesApplicationService {
/* #region GET */ /* #region GET */
async getAsync(namespace, name) { async getAsync(namespace, name) {
try { const [deployment, daemonSet, statefulSet, pod, pods, autoScalers, ingresses] = await Promise.allSettled([
const [deployment, daemonSet, statefulSet, pod, pods, autoScalers, ingresses] = await Promise.allSettled([ this.KubernetesDeploymentService.get(namespace, name),
this.KubernetesDeploymentService.get(namespace, name), this.KubernetesDaemonSetService.get(namespace, name),
this.KubernetesDaemonSetService.get(namespace, name), this.KubernetesStatefulSetService.get(namespace, name),
this.KubernetesStatefulSetService.get(namespace, name), this.KubernetesPodService.get(namespace, name),
this.KubernetesPodService.get(namespace, name), this.KubernetesPodService.get(namespace),
this.KubernetesPodService.get(namespace), this.KubernetesHorizontalPodAutoScalerService.get(namespace),
this.KubernetesHorizontalPodAutoScalerService.get(namespace), this.KubernetesIngressService.get(namespace),
this.KubernetesIngressService.get(namespace), ]);
]);
// const pod = _.find(pods.value, ['metadata.namespace', namespace, 'metadata.name', name]); let rootItem;
let converterFunc;
let rootItem; if (deployment.status === 'fulfilled') {
let converterFunc; rootItem = deployment;
if (deployment.status === 'fulfilled') { converterFunc = KubernetesApplicationConverter.apiDeploymentToApplication;
rootItem = deployment; } else if (daemonSet.status === 'fulfilled') {
converterFunc = KubernetesApplicationConverter.apiDeploymentToApplication; rootItem = daemonSet;
} else if (daemonSet.status === 'fulfilled') { converterFunc = KubernetesApplicationConverter.apiDaemonSetToApplication;
rootItem = daemonSet; } else if (statefulSet.status === 'fulfilled') {
converterFunc = KubernetesApplicationConverter.apiDaemonSetToApplication; rootItem = statefulSet;
} else if (statefulSet.status === 'fulfilled') { converterFunc = KubernetesApplicationConverter.apiStatefulSetToapplication;
rootItem = statefulSet; } else if (pod.status === 'fulfilled') {
converterFunc = KubernetesApplicationConverter.apiStatefulSetToapplication; rootItem = pod;
} else if (pod.status === 'fulfilled') { converterFunc = KubernetesApplicationConverter.apiPodToApplication;
rootItem = pod; } else {
converterFunc = KubernetesApplicationConverter.apiPodToApplication; throw new PortainerError('Unable to determine which association to use to convert application');
} 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;
} }
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) { 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 convertToApplication = (item, converterFunc, services, pods, ingresses) => {
const service = KubernetesServiceHelper.findApplicationBoundService(services, item); const service = KubernetesServiceHelper.findApplicationBoundService(services, item);
const application = converterFunc(item, pods, service, ingresses); const application = converterFunc(item, pods, service, ingresses);
application.Containers = KubernetesApplicationHelper.associateContainersAndApplication(application); application.Containers = KubernetesApplicationHelper.associateContainersAndApplication(application);
return application; return application;
}; };
const res = await Promise.all( const res = await Promise.all(
_.map(namespaces, async (ns) => { _.map(namespaces, async (ns) => {
const [deployments, daemonSets, statefulSets, services, pods, ingresses, autoScalers] = await Promise.all([ const [deployments, daemonSets, statefulSets, services, pods, ingresses, autoScalers] = await Promise.all([
this.KubernetesDeploymentService.get(ns), this.KubernetesDeploymentService.get(ns),
this.KubernetesDaemonSetService.get(ns), this.KubernetesDaemonSetService.get(ns),
this.KubernetesStatefulSetService.get(ns), this.KubernetesStatefulSetService.get(ns),
this.KubernetesServiceService.get(ns), this.KubernetesServiceService.get(ns),
this.KubernetesPodService.get(ns), this.KubernetesPodService.get(ns),
this.KubernetesIngressService.get(ns), this.KubernetesIngressService.get(ns),
this.KubernetesHorizontalPodAutoScalerService.get(ns), this.KubernetesHorizontalPodAutoScalerService.get(ns),
]); ]);
const deploymentApplications = _.map(deployments, (item) => const deploymentApplications = _.map(deployments, (item) =>
convertToApplication(item, KubernetesApplicationConverter.apiDeploymentToApplication, services, pods, ingresses) convertToApplication(item, KubernetesApplicationConverter.apiDeploymentToApplication, services, pods, ingresses)
); );
const daemonSetApplications = _.map(daemonSets, (item) => const daemonSetApplications = _.map(daemonSets, (item) => convertToApplication(item, KubernetesApplicationConverter.apiDaemonSetToApplication, services, pods, ingresses));
convertToApplication(item, KubernetesApplicationConverter.apiDaemonSetToApplication, services, pods, ingresses) const statefulSetApplications = _.map(statefulSets, (item) =>
); convertToApplication(item, KubernetesApplicationConverter.apiStatefulSetToapplication, 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 boundPods = _.concat(_.flatMap(deploymentApplications, 'Pods'), _.flatMap(daemonSetApplications, 'Pods'), _.flatMap(statefulSetApplications, 'Pods'));
const unboundPods = _.without(pods, ...boundPods); const unboundPods = _.without(pods, ...boundPods);
const nakedPodsApplications = _.map(unboundPods, (item) => convertToApplication(item, KubernetesApplicationConverter.apiPodToApplication, services, pods, ingresses)); const nakedPodsApplications = _.map(unboundPods, (item) => convertToApplication(item, KubernetesApplicationConverter.apiPodToApplication, services, pods, ingresses));
const applications = _.concat(deploymentApplications, daemonSetApplications, statefulSetApplications, nakedPodsApplications); const applications = _.concat(deploymentApplications, daemonSetApplications, statefulSetApplications, nakedPodsApplications);
_.forEach(applications, (app) => { _.forEach(applications, (app) => {
app.Pods = _.map(app.Pods, (item) => KubernetesPodConverter.apiToModel(item)); app.Pods = _.map(app.Pods, (item) => KubernetesPodConverter.apiToModel(item));
}); });
await Promise.all( await Promise.all(
_.forEach(applications, async (application) => { _.forEach(applications, async (application) => {
const boundScaler = KubernetesHorizontalPodAutoScalerHelper.findApplicationBoundScaler(autoScalers, application); const boundScaler = KubernetesHorizontalPodAutoScalerHelper.findApplicationBoundScaler(autoScalers, application);
const scaler = boundScaler ? await this.KubernetesHorizontalPodAutoScalerService.get(ns, boundScaler.Name) : undefined; const scaler = boundScaler ? await this.KubernetesHorizontalPodAutoScalerService.get(ns, boundScaler.Name) : undefined;
application.AutoScaler = scaler; application.AutoScaler = scaler;
}) })
); );
return applications; return applications;
}) })
); );
return _.flatten(res); return _.flatten(res);
} catch (err) {
throw err;
}
} }
get(namespace, name) { get(namespace, name) {
@ -226,42 +214,38 @@ class KubernetesApplicationService {
* also be displayed in the summary output (getCreatedApplicationResources) * also be displayed in the summary output (getCreatedApplicationResources)
*/ */
async createAsync(formValues) { async createAsync(formValues) {
try { let [app, headlessService, service, claims] = KubernetesApplicationConverter.applicationFormValuesToApplication(formValues);
let [app, headlessService, service, claims] = KubernetesApplicationConverter.applicationFormValuesToApplication(formValues);
if (service) { if (service) {
await this.KubernetesServiceService.create(service); await this.KubernetesServiceService.create(service);
if (formValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) { if (formValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS) {
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(formValues, service.Name); const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(formValues, service.Name);
await Promise.all(this._generateIngressPatchPromises(formValues.OriginalIngresses, ingresses)); 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) { create(formValues) {
@ -277,97 +261,89 @@ class KubernetesApplicationService {
* in this method should also be displayed in the summary output (getUpdatedApplicationResources) * in this method should also be displayed in the summary output (getUpdatedApplicationResources)
*/ */
async patchAsync(oldFormValues, newFormValues) { async patchAsync(oldFormValues, newFormValues) {
try { const [oldApp, oldHeadlessService, oldService, oldClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(oldFormValues);
const [oldApp, oldHeadlessService, oldService, oldClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(oldFormValues); const [newApp, newHeadlessService, newService, newClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(newFormValues);
const [newApp, newHeadlessService, newService, newClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(newFormValues); const oldApiService = this._getApplicationApiService(oldApp);
const oldApiService = this._getApplicationApiService(oldApp); const newApiService = this._getApplicationApiService(newApp);
const newApiService = this._getApplicationApiService(newApp);
if (oldApiService !== newApiService) { if (oldApiService !== newApiService) {
await this.delete(oldApp); await this.delete(oldApp);
if (oldService) { 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) {
await this.KubernetesServiceService.delete(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); if (newApp instanceof KubernetesStatefulSet) {
const newAutoScaler = KubernetesHorizontalPodAutoScalerConverter.applicationFormValuesToModel(newFormValues, newKind); await this.KubernetesServiceService.patch(oldHeadlessService, newHeadlessService);
if (!oldFormValues.AutoScaler.IsUsed) { } else {
if (newFormValues.AutoScaler.IsUsed) { const claimPromises = _.map(newClaims, (newClaim) => {
await this.KubernetesHorizontalPodAutoScalerService.create(newAutoScaler); if (!newClaim.PreviousName && !newClaim.Id) {
} return this.KubernetesPersistentVolumeClaimService.create(newClaim);
} else { } else if (!newClaim.Id) {
const oldKind = KubernetesHorizontalPodAutoScalerHelper.getApplicationTypeString(oldApp); const oldClaim = _.find(oldClaims, { Name: newClaim.PreviousName });
const oldAutoScaler = KubernetesHorizontalPodAutoScalerConverter.applicationFormValuesToModel(oldFormValues, oldKind); return this.KubernetesPersistentVolumeClaimService.patch(oldClaim, newClaim);
if (newFormValues.AutoScaler.IsUsed) {
await this.KubernetesHorizontalPodAutoScalerService.patch(oldAutoScaler, newAutoScaler);
} else {
await this.KubernetesHorizontalPodAutoScalerService.delete(oldAutoScaler);
} }
});
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 // this function accepts KubernetesApplication as parameters
async patchPartialAsync(oldApp, newApp) { async patchPartialAsync(oldApp, newApp) {
try { const oldAppPayload = {
const oldAppPayload = { Name: oldApp.Name,
Name: oldApp.Name, Namespace: oldApp.ResourcePool,
Namespace: oldApp.ResourcePool, StackName: oldApp.StackName,
StackName: oldApp.StackName, Note: oldApp.Note,
Note: oldApp.Note, };
}; const newAppPayload = {
const newAppPayload = { Name: newApp.Name,
Name: newApp.Name, Namespace: newApp.ResourcePool,
Namespace: newApp.ResourcePool, StackName: newApp.StackName,
StackName: newApp.StackName, Note: newApp.Note,
Note: newApp.Note, };
}; const apiService = this._getApplicationApiService(oldApp);
const apiService = this._getApplicationApiService(oldApp); await apiService.patch(oldAppPayload, newAppPayload);
await apiService.patch(oldAppPayload, newAppPayload);
} catch (err) {
throw err;
}
} }
// accept either formValues or applications as parameters // accept either formValues or applications as parameters
@ -384,42 +360,38 @@ class KubernetesApplicationService {
/* #region DELETE */ /* #region DELETE */
async deleteAsync(application) { async deleteAsync(application) {
try { const payload = {
const payload = { Namespace: application.ResourcePool || application.Namespace,
Namespace: application.ResourcePool || application.Namespace, Name: application.Name,
Name: application.Name, };
}; const servicePayload = angular.copy(payload);
const servicePayload = angular.copy(payload); servicePayload.Name = application.Name;
servicePayload.Name = application.Name;
const apiService = this._getApplicationApiService(application); const apiService = this._getApplicationApiService(application);
await apiService.delete(payload); await apiService.delete(payload);
if (apiService === this.KubernetesStatefulSetService) { if (apiService === this.KubernetesStatefulSetService) {
const headlessServicePayload = angular.copy(payload); const headlessServicePayload = angular.copy(payload);
headlessServicePayload.Name = application instanceof KubernetesStatefulSet ? application.ServiceName : application.HeadlessServiceName; headlessServicePayload.Name = application instanceof KubernetesStatefulSet ? application.ServiceName : application.HeadlessServiceName;
await this.KubernetesServiceService.delete(headlessServicePayload); await this.KubernetesServiceService.delete(headlessServicePayload);
} }
if (application.ServiceType) { if (application.ServiceType) {
await this.KubernetesServiceService.delete(servicePayload); await this.KubernetesServiceService.delete(servicePayload);
const isIngress = _.filter(application.PublishedPorts, (p) => p.IngressRules.length).length; const isIngress = _.filter(application.PublishedPorts, (p) => p.IngressRules.length).length;
if (isIngress) { if (isIngress) {
const originalIngresses = await this.KubernetesIngressService.get(payload.Namespace); const originalIngresses = await this.KubernetesIngressService.get(payload.Namespace);
const formValues = { const formValues = {
OriginalIngresses: originalIngresses, OriginalIngresses: originalIngresses,
PublishedPorts: KubernetesApplicationHelper.generatePublishedPortsFormValuesFromPublishedPorts(application.ServiceType, application.PublishedPorts), PublishedPorts: KubernetesApplicationHelper.generatePublishedPortsFormValuesFromPublishedPorts(application.ServiceType, application.PublishedPorts),
}; };
_.forEach(formValues.PublishedPorts, (p) => (p.NeedsDeletion = true)); _.forEach(formValues.PublishedPorts, (p) => (p.NeedsDeletion = true));
const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(formValues, servicePayload.Name); const ingresses = KubernetesIngressConverter.applicationFormValuesToIngresses(formValues, servicePayload.Name);
await Promise.all(this._generateIngressPatchPromises(formValues.OriginalIngresses, ingresses)); await Promise.all(this._generateIngressPatchPromises(formValues.OriginalIngresses, ingresses));
}
} }
if (!_.isEmpty(application.AutoScaler)) { }
await this.KubernetesHorizontalPodAutoScalerService.delete(application.AutoScaler); if (!_.isEmpty(application.AutoScaler)) {
} await this.KubernetesHorizontalPodAutoScalerService.delete(application.AutoScaler);
} catch (err) {
throw err;
} }
} }
@ -430,13 +402,9 @@ class KubernetesApplicationService {
/* #region ROLLBACK */ /* #region ROLLBACK */
async rollbackAsync(application, targetRevision) { async rollbackAsync(application, targetRevision) {
try { const payload = KubernetesApplicationRollbackHelper.getPatchPayload(application, targetRevision);
const payload = KubernetesApplicationRollbackHelper.getPatchPayload(application, targetRevision); const apiService = this._getApplicationApiService(application);
const apiService = this._getApplicationApiService(application); await apiService.rollback(application.ResourcePool, application.Name, payload);
await apiService.rollback(application.ResourcePool, application.Name, payload);
} catch (err) {
throw err;
}
} }
rollback(application, targetRevision) { rollback(application, targetRevision) {

View File

@ -26,35 +26,27 @@ class KubernetesConfigurationService {
* GET * GET
*/ */
async getAsync(namespace, name) { async getAsync(namespace, name) {
try { const [configMap, secret] = await Promise.allSettled([this.KubernetesConfigMapService.get(namespace, name), this.KubernetesSecretService.get(namespace, name)]);
const [configMap, secret] = await Promise.allSettled([this.KubernetesConfigMapService.get(namespace, name), this.KubernetesSecretService.get(namespace, name)]); let configuration;
let configuration; if (secret.status === 'fulfilled') {
if (secret.status === 'fulfilled') { configuration = KubernetesConfigurationConverter.secretToConfiguration(secret.value);
configuration = KubernetesConfigurationConverter.secretToConfiguration(secret.value);
return configuration;
}
configuration = KubernetesConfigurationConverter.configMapToConfiguration(configMap.value);
return configuration; return configuration;
} catch (err) {
throw err;
} }
configuration = KubernetesConfigurationConverter.configMapToConfiguration(configMap.value);
return configuration;
} }
async getAllAsync(namespace) { 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 res = await Promise.all(
const res = await Promise.all( _.map(namespaces, async (ns) => {
_.map(namespaces, async (ns) => { const [configMaps, secrets] = await Promise.all([this.KubernetesConfigMapService.get(ns), this.KubernetesSecretService.get(ns)]);
const [configMaps, secrets] = await Promise.all([this.KubernetesConfigMapService.get(ns), this.KubernetesSecretService.get(ns)]); const secretsConfigurations = _.map(secrets, (secret) => KubernetesConfigurationConverter.secretToConfiguration(secret));
const secretsConfigurations = _.map(secrets, (secret) => KubernetesConfigurationConverter.secretToConfiguration(secret)); const configMapsConfigurations = _.map(configMaps, (configMap) => KubernetesConfigurationConverter.configMapToConfiguration(configMap));
const configMapsConfigurations = _.map(configMaps, (configMap) => KubernetesConfigurationConverter.configMapToConfiguration(configMap)); return _.concat(configMapsConfigurations, secretsConfigurations);
return _.concat(configMapsConfigurations, secretsConfigurations); })
}) );
); return _.flatten(res);
return _.flatten(res);
} catch (err) {
throw err;
}
} }
get(namespace, name) { get(namespace, name) {
@ -70,16 +62,12 @@ class KubernetesConfigurationService {
async createAsync(formValues) { async createAsync(formValues) {
formValues.ConfigurationOwner = KubernetesCommonHelper.ownerToLabel(formValues.ConfigurationOwner); formValues.ConfigurationOwner = KubernetesCommonHelper.ownerToLabel(formValues.ConfigurationOwner);
try { if (formValues.Type === KubernetesConfigurationTypes.CONFIGMAP) {
if (formValues.Type === KubernetesConfigurationTypes.CONFIGMAP) { const configMap = KubernetesConfigMapConverter.configurationFormValuesToConfigMap(formValues);
const configMap = KubernetesConfigMapConverter.configurationFormValuesToConfigMap(formValues); await this.KubernetesConfigMapService.create(configMap);
await this.KubernetesConfigMapService.create(configMap); } else {
} else { const secret = KubernetesSecretConverter.configurationFormValuesToSecret(formValues);
const secret = KubernetesSecretConverter.configurationFormValuesToSecret(formValues); await this.KubernetesSecretService.create(secret);
await this.KubernetesSecretService.create(secret);
}
} catch (err) {
throw err;
} }
} }
@ -91,18 +79,14 @@ class KubernetesConfigurationService {
* UPDATE * UPDATE
*/ */
async updateAsync(formValues, configuration) { async updateAsync(formValues, configuration) {
try { if (formValues.Type === KubernetesConfigurationTypes.CONFIGMAP) {
if (formValues.Type === KubernetesConfigurationTypes.CONFIGMAP) { const configMap = KubernetesConfigMapConverter.configurationFormValuesToConfigMap(formValues);
const configMap = KubernetesConfigMapConverter.configurationFormValuesToConfigMap(formValues); configMap.ConfigurationOwner = configuration.ConfigurationOwner;
configMap.ConfigurationOwner = configuration.ConfigurationOwner; await this.KubernetesConfigMapService.update(configMap);
await this.KubernetesConfigMapService.update(configMap); } else {
} else { const secret = KubernetesSecretConverter.configurationFormValuesToSecret(formValues);
const secret = KubernetesSecretConverter.configurationFormValuesToSecret(formValues); secret.ConfigurationOwner = configuration.ConfigurationOwner;
secret.ConfigurationOwner = configuration.ConfigurationOwner; await this.KubernetesSecretService.update(secret);
await this.KubernetesSecretService.update(secret);
}
} catch (err) {
throw err;
} }
} }
@ -114,14 +98,10 @@ class KubernetesConfigurationService {
* DELETE * DELETE
*/ */
async deleteAsync(config) { async deleteAsync(config) {
try { if (config.Type === KubernetesConfigurationTypes.CONFIGMAP) {
if (config.Type === KubernetesConfigurationTypes.CONFIGMAP) { await this.KubernetesConfigMapService.delete(config);
await this.KubernetesConfigMapService.delete(config); } else {
} else { await this.KubernetesSecretService.delete(config);
await this.KubernetesSecretService.delete(config);
}
} catch (err) {
throw err;
} }
} }

View File

@ -14,39 +14,31 @@ export function KubernetesResourcePoolService($async, EndpointService, Kubernete
}; };
async function getOne(name) { async function getOne(name) {
try { const namespace = await KubernetesNamespaceService.get(name);
const namespace = await KubernetesNamespaceService.get(name); const [quotaAttempt] = await Promise.allSettled([KubernetesResourceQuotaService.get(name, KubernetesResourceQuotaHelper.generateResourceQuotaName(name))]);
const [quotaAttempt] = await Promise.allSettled([KubernetesResourceQuotaService.get(name, KubernetesResourceQuotaHelper.generateResourceQuotaName(name))]); const pool = KubernetesResourcePoolConverter.apiToResourcePool(namespace);
const pool = KubernetesResourcePoolConverter.apiToResourcePool(namespace); if (quotaAttempt.status === 'fulfilled') {
if (quotaAttempt.status === 'fulfilled') { pool.Quota = quotaAttempt.value;
pool.Quota = quotaAttempt.value; pool.Yaml += '---\n' + quotaAttempt.value.Yaml;
pool.Yaml += '---\n' + quotaAttempt.value.Yaml;
}
return pool;
} catch (err) {
throw err;
} }
return pool;
} }
async function getAll() { async function getAll() {
try { const namespaces = await KubernetesNamespaceService.get();
const namespaces = await KubernetesNamespaceService.get(); const pools = await Promise.all(
const pools = await Promise.all( _.map(namespaces, async (namespace) => {
_.map(namespaces, async (namespace) => { const name = namespace.Name;
const name = namespace.Name; const [quotaAttempt] = await Promise.allSettled([KubernetesResourceQuotaService.get(name, KubernetesResourceQuotaHelper.generateResourceQuotaName(name))]);
const [quotaAttempt] = await Promise.allSettled([KubernetesResourceQuotaService.get(name, KubernetesResourceQuotaHelper.generateResourceQuotaName(name))]); const pool = KubernetesResourcePoolConverter.apiToResourcePool(namespace);
const pool = KubernetesResourcePoolConverter.apiToResourcePool(namespace); if (quotaAttempt.status === 'fulfilled') {
if (quotaAttempt.status === 'fulfilled') { pool.Quota = quotaAttempt.value;
pool.Quota = quotaAttempt.value; pool.Yaml += '---\n' + quotaAttempt.value.Yaml;
pool.Yaml += '---\n' + quotaAttempt.value.Yaml; }
} return pool;
return pool; })
}) );
); return pools;
return pools;
} catch (err) {
throw err;
}
} }
function get(name) { function get(name) {
@ -58,80 +50,68 @@ export function KubernetesResourcePoolService($async, EndpointService, Kubernete
function create(formValues) { function create(formValues) {
return $async(async () => { return $async(async () => {
try { const [namespace, quota, ingresses, registries] = KubernetesResourcePoolConverter.formValuesToResourcePool(formValues);
const [namespace, quota, ingresses, registries] = KubernetesResourcePoolConverter.formValuesToResourcePool(formValues); await KubernetesNamespaceService.create(namespace);
await KubernetesNamespaceService.create(namespace);
if (quota) { if (quota) {
await KubernetesResourceQuotaService.create(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;
} }
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) { function patch(oldFormValues, newFormValues) {
return $async(async () => { return $async(async () => {
try { const [oldNamespace, oldQuota, oldIngresses, oldRegistries] = KubernetesResourcePoolConverter.formValuesToResourcePool(oldFormValues);
const [oldNamespace, oldQuota, oldIngresses, oldRegistries] = KubernetesResourcePoolConverter.formValuesToResourcePool(oldFormValues); const [newNamespace, newQuota, newIngresses, newRegistries] = KubernetesResourcePoolConverter.formValuesToResourcePool(newFormValues);
const [newNamespace, newQuota, newIngresses, newRegistries] = KubernetesResourcePoolConverter.formValuesToResourcePool(newFormValues); void oldNamespace, newNamespace;
void oldNamespace, newNamespace;
if (oldQuota && newQuota) { if (oldQuota && newQuota) {
await KubernetesResourceQuotaService.patch(oldQuota, newQuota); await KubernetesResourceQuotaService.patch(oldQuota, newQuota);
} else if (!oldQuota && newQuota) { } else if (!oldQuota && newQuota) {
await KubernetesResourceQuotaService.create(newQuota); await KubernetesResourceQuotaService.create(newQuota);
} else if (oldQuota && !newQuota) { } else if (oldQuota && !newQuota) {
await KubernetesResourceQuotaService.delete(oldQuota); 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;
} }
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) { function _delete(pool) {
return $async(async () => { return $async(async () => {
try { await KubernetesNamespaceService.delete(pool.Namespace);
await KubernetesNamespaceService.delete(pool.Namespace);
} catch (err) {
throw err;
}
}); });
} }
} }

View File

@ -14,13 +14,9 @@ class KubernetesStackService {
* GET * GET
*/ */
async getAllAsync(namespace) { async getAllAsync(namespace) {
try { const applications = await this.KubernetesApplicationService.get(namespace);
const applications = await this.KubernetesApplicationService.get(namespace); const stacks = _.map(applications, (item) => item.StackName);
const stacks = _.map(applications, (item) => item.StackName); return _.uniq(_.without(stacks, '-'));
return _.uniq(_.without(stacks, '-'));
} catch (err) {
throw err;
}
} }
get(namespace) { get(namespace) {

View File

@ -20,28 +20,20 @@ class KubernetesVolumeService {
* GET * GET
*/ */
async getAsync(namespace, name) { async getAsync(namespace, name) {
try { const [pvc, pool] = await Promise.all([this.KubernetesPersistentVolumeClaimService.get(namespace, name), this.KubernetesResourcePoolService.get(namespace)]);
const [pvc, pool] = await Promise.all([this.KubernetesPersistentVolumeClaimService.get(namespace, name), this.KubernetesResourcePoolService.get(namespace)]); return KubernetesVolumeConverter.pvcToVolume(pvc, pool);
return KubernetesVolumeConverter.pvcToVolume(pvc, pool);
} catch (err) {
throw err;
}
} }
async getAllAsync(namespace) { async getAllAsync(namespace) {
try { const data = await this.KubernetesResourcePoolService.get(namespace);
const data = await this.KubernetesResourcePoolService.get(namespace); const pools = data instanceof Array ? data : [data];
const pools = data instanceof Array ? data : [data]; const res = await Promise.all(
const res = await Promise.all( _.map(pools, async (pool) => {
_.map(pools, async (pool) => { const pvcs = await this.KubernetesPersistentVolumeClaimService.get(pool.Namespace.Name);
const pvcs = await this.KubernetesPersistentVolumeClaimService.get(pool.Namespace.Name); return _.map(pvcs, (pvc) => KubernetesVolumeConverter.pvcToVolume(pvc, pool));
return _.map(pvcs, (pvc) => KubernetesVolumeConverter.pvcToVolume(pvc, pool)); })
}) );
); return _.flatten(res);
return _.flatten(res);
} catch (err) {
throw err;
}
} }
get(namespace, name) { get(namespace, name) {
@ -55,11 +47,7 @@ class KubernetesVolumeService {
* DELETE * DELETE
*/ */
async deleteAsync(volume) { async deleteAsync(volume) {
try { await this.KubernetesPersistentVolumeClaimService.delete(volume.PersistentVolumeClaim);
await this.KubernetesPersistentVolumeClaimService.delete(volume.PersistentVolumeClaim);
} catch (err) {
throw err;
}
} }
delete(volume) { delete(volume) {

View File

@ -77,26 +77,22 @@ angular.module('portainer.app').factory('AccessService', [
} }
async function accessesAsync(entity, parent) { async function accessesAsync(entity, parent) {
try { if (!entity) {
if (!entity) { throw new Error('Unable to retrieve accesses');
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.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) { function accesses(entity, parent) {

View File

@ -119,10 +119,10 @@
"cssnano": "^3.10.0", "cssnano": "^3.10.0",
"cypress": "^5.2.0", "cypress": "^5.2.0",
"cypress-wait-until": "^1.7.1", "cypress-wait-until": "^1.7.1",
"eslint": "5.16.0", "eslint": "^7.24.0",
"eslint-config-prettier": "^6.10.1", "eslint-config-prettier": "^8.2.0",
"eslint-loader": "^2.1.2", "eslint-plugin-import": "^2.22.1",
"eslint-plugin-import": "^2.20.2", "eslint-webpack-plugin": "^2.5.3",
"file-loader": "^1.1.11", "file-loader": "^1.1.11",
"grunt": "^1.1.0", "grunt": "^1.1.0",
"grunt-cli": "^1.3.2", "grunt-cli": "^1.3.2",
@ -175,4 +175,4 @@
"*.js": "eslint --cache --fix", "*.js": "eslint --cache --fix",
"*.{js,css,md,html}": "prettier --write" "*.{js,css,md,html}": "prettier --write"
} }
} }

View File

@ -6,6 +6,8 @@ const CleanTerminalPlugin = require('clean-terminal-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin'); const CleanWebpackPlugin = require('clean-webpack-plugin');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin'); const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const pkg = require('../package.json'); const pkg = require('../package.json');
const projectRoot = path.resolve(__dirname, '..'); const projectRoot = path.resolve(__dirname, '..');
@ -37,14 +39,7 @@ module.exports = {
{ {
test: /\.js$/, test: /\.js$/,
exclude: /node_modules/, exclude: /node_modules/,
use: [ use: ['babel-loader', 'auto-ngtemplate-loader'],
'babel-loader',
'auto-ngtemplate-loader',
{
// enforce: 'pre',
loader: 'eslint-loader',
},
],
}, },
{ {
test: /\.html$/, test: /\.html$/,
@ -81,6 +76,7 @@ module.exports = {
writeToDisk: true, writeToDisk: true,
}, },
plugins: [ plugins: [
new ESLintPlugin(),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
template: './app/index.html', template: './app/index.html',
templateParameters: { templateParameters: {

640
yarn.lock

File diff suppressed because it is too large Load Diff