1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-25 00:09:40 +02:00

fix(k8s/ingress): ensure new ports are only added to ingress only if app is published via ingress (#6153)

* fix(k8s/ingress): ensure new ports are only added to ingress only if app is published via ingress

* refactor(k8s/ingress): removed deleted ports of ingress in a single pass
This commit is contained in:
LP B 2021-11-30 05:14:52 +01:00 committed by GitHub
parent 69c17986d9
commit b6fbf8eecc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 32 deletions

View file

@ -7,6 +7,7 @@ import {
KubernetesResourcePoolIngressClassFormValue,
KubernetesResourcePoolIngressClassHostFormValue,
} from 'Kubernetes/models/resource-pool/formValues';
import { KubernetesApplicationPublishingTypes } from '../models/application/models';
import { KubernetesIngress, KubernetesIngressRule } from './models';
import { KubernetesIngressCreatePayload, KubernetesIngressRuleCreatePayload, KubernetesIngressRulePathCreatePayload } from './payloads';
import { KubernetesIngressClassAnnotation, KubernetesIngressClassRewriteTargetAnnotations } from './constants';
@ -45,23 +46,31 @@ export class KubernetesIngressConverter {
return res;
}
/**
* Converts Application Form Value (from Create Application View) to Ingresses
* @param {KubernetesApplicationFormValues} formValues
* @param {string} serviceName
* @returns {KubernetesIngressRule[]}
*/
static applicationFormValuesToIngresses(formValues, serviceName) {
const isPublishingToIngress = formValues.PublishingType === KubernetesApplicationPublishingTypes.INGRESS;
const ingresses = angular.copy(formValues.OriginalIngresses);
_.forEach(formValues.PublishedPorts, (p) => {
const ingress = _.find(ingresses, { Name: p.IngressName });
if (ingress && p.NeedsDeletion) {
const path = _.find(ingress.Paths, { Port: p.ContainerPort, ServiceName: serviceName, Path: p.IngressRoute });
_.remove(ingress.Paths, path);
} else if (ingress && p.IsNew) {
const rule = new KubernetesIngressRule();
rule.IngressName = ingress.Name;
rule.ServiceName = serviceName;
rule.Port = p.ContainerPort;
if (p.IngressRoute) {
rule.Path = _.startsWith(p.IngressRoute, '/') ? p.IngressRoute : '/' + p.IngressRoute;
if (ingress) {
if (p.NeedsDeletion) {
_.remove(ingress.Paths, (path) => path.Port === p.ContainerPort && path.ServiceName === serviceName && path.Path === p.IngressRoute);
} else if (isPublishingToIngress && p.IsNew) {
const rule = new KubernetesIngressRule();
rule.IngressName = ingress.Name;
rule.ServiceName = serviceName;
rule.Port = p.ContainerPort;
if (p.IngressRoute) {
rule.Path = _.startsWith(p.IngressRoute, '/') ? p.IngressRoute : '/' + p.IngressRoute;
}
rule.Host = p.IngressHost;
ingress.Paths.push(rule);
}
rule.Host = p.IngressHost;
ingress.Paths.push(rule);
}
});
return ingresses;
@ -69,7 +78,8 @@ export class KubernetesIngressConverter {
/**
*
* @param {KubernetesResourcePoolIngressClassFormValue} formValues
* @param {KubernetesResourcePoolIngressClassFormValue[]} formValues
* @returns {KubernetesIngress} Ingress
*/
static resourcePoolIngressClassFormValueToIngress(formValues) {
const res = new KubernetesIngress();