mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 06:49:40 +02:00
feat(app): add ingress to app service form [EE-5569] (#9106)
This commit is contained in:
parent
8c16fbb8aa
commit
89c1d0e337
47 changed files with 1929 additions and 1181 deletions
|
@ -13,6 +13,8 @@ import { KubernetesHorizontalPodAutoScalerHelper } from 'Kubernetes/horizontal-p
|
|||
import { KubernetesHorizontalPodAutoScalerConverter } from 'Kubernetes/horizontal-pod-auto-scaler/converter';
|
||||
import KubernetesPodConverter from 'Kubernetes/pod/converter';
|
||||
import { notifyError } from '@/portainer/services/notifications';
|
||||
import { KubernetesIngressConverter } from 'Kubernetes/ingress/converter';
|
||||
import { generateNewIngressesFromFormPaths } from '@/react/kubernetes/applications/CreateView/application-services/utils';
|
||||
|
||||
class KubernetesApplicationService {
|
||||
/* #region CONSTRUCTOR */
|
||||
|
@ -70,6 +72,12 @@ class KubernetesApplicationService {
|
|||
return apiService;
|
||||
}
|
||||
|
||||
_generateIngressPatchPromises(oldIngresses, newIngresses) {
|
||||
return _.map(newIngresses, (newIng) => {
|
||||
const oldIng = _.find(oldIngresses, { Name: newIng.Name });
|
||||
return this.KubernetesIngressService.patch(oldIng, newIng);
|
||||
});
|
||||
}
|
||||
/* #endregion */
|
||||
|
||||
/* #region GET */
|
||||
|
@ -214,6 +222,18 @@ class KubernetesApplicationService {
|
|||
notifyError('Unable to create service', error);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
//Generate all ingresses from current form by passing services object
|
||||
const newServicePorts = formValues.Services.flatMap((service) => service.Ports);
|
||||
const newIngresses = generateNewIngressesFromFormPaths(formValues.OriginalIngresses, newServicePorts);
|
||||
if (newIngresses) {
|
||||
//Update original ingress with current ingress
|
||||
await Promise.all(this._generateIngressPatchPromises(formValues.OriginalIngresses, newIngresses));
|
||||
}
|
||||
} catch (error) {
|
||||
notifyError('Unable to update service', error);
|
||||
}
|
||||
}
|
||||
|
||||
const apiService = this._getApplicationApiService(app);
|
||||
|
@ -256,7 +276,7 @@ class KubernetesApplicationService {
|
|||
* To synchronise with kubernetes resource creation, update and delete summary output, any new resources created
|
||||
* in this method should also be displayed in the summary output (getUpdatedApplicationResources)
|
||||
*/
|
||||
async patchAsync(oldFormValues, newFormValues) {
|
||||
async patchAsync(oldFormValues, newFormValues, originalServicePorts) {
|
||||
const [oldApp, oldHeadlessService, oldServices, , oldClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(oldFormValues);
|
||||
const [newApp, newHeadlessService, newServices, , newClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(newFormValues);
|
||||
const oldApiService = this._getApplicationApiService(oldApp);
|
||||
|
@ -341,6 +361,21 @@ class KubernetesApplicationService {
|
|||
});
|
||||
}
|
||||
|
||||
// Update ingresses
|
||||
if (newServices) {
|
||||
try {
|
||||
//Generate all ingresses from current form by passing services object
|
||||
const newServicePorts = newFormValues.Services.flatMap((service) => service.Ports);
|
||||
const newIngresses = generateNewIngressesFromFormPaths(newFormValues.OriginalIngresses, newServicePorts, originalServicePorts);
|
||||
if (newIngresses) {
|
||||
//Update original ingress with current ingress
|
||||
await Promise.all(this._generateIngressPatchPromises(newFormValues.OriginalIngresses, newIngresses));
|
||||
}
|
||||
} catch (error) {
|
||||
notifyError('Unable to update service', error);
|
||||
}
|
||||
}
|
||||
|
||||
const newKind = KubernetesHorizontalPodAutoScalerHelper.getApplicationTypeString(newApp);
|
||||
const newAutoScaler = KubernetesHorizontalPodAutoScalerConverter.applicationFormValuesToModel(newFormValues, newKind);
|
||||
if (!oldFormValues.AutoScaler.IsUsed) {
|
||||
|
@ -384,11 +419,11 @@ class KubernetesApplicationService {
|
|||
//
|
||||
// patch(oldValues: KubernetesApplication, newValues: KubernetesApplication, partial: (undefined | false)): Promise<unknown>
|
||||
// patch(oldValues: KubernetesApplicationFormValues, newValues: KubernetesApplicationFormValues, partial: true): Promise<unknown>
|
||||
patch(oldValues, newValues, partial = false) {
|
||||
patch(oldValues, newValues, partial = false, originalServicePorts) {
|
||||
if (partial) {
|
||||
return this.$async(this.patchPartialAsync, oldValues, newValues);
|
||||
}
|
||||
return this.$async(this.patchAsync, oldValues, newValues);
|
||||
return this.$async(this.patchAsync, oldValues, newValues, originalServicePorts);
|
||||
}
|
||||
/* #endregion */
|
||||
|
||||
|
@ -412,6 +447,16 @@ class KubernetesApplicationService {
|
|||
if (application.ServiceType) {
|
||||
// delete headless service && non-headless service
|
||||
await this.KubernetesServiceService.delete(application.Services);
|
||||
if (application.Ingresses.length) {
|
||||
const originalIngresses = await this.KubernetesIngressService.get(payload.Namespace);
|
||||
const formValues = {
|
||||
OriginalIngresses: originalIngresses,
|
||||
PublishedPorts: KubernetesApplicationHelper.generatePublishedPortsFormValuesFromPublishedPorts(application.ServiceType, application.PublishedPorts),
|
||||
};
|
||||
const ingresses = KubernetesIngressConverter.applicationFormValuesToDeleteIngresses(formValues, application);
|
||||
|
||||
await Promise.all(this._generateIngressPatchPromises(formValues.OriginalIngresses, ingresses));
|
||||
}
|
||||
}
|
||||
if (!_.isEmpty(application.AutoScaler)) {
|
||||
await this.KubernetesHorizontalPodAutoScalerService.delete(application.AutoScaler);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue