mirror of https://github.com/portainer/portainer
fix(k8s/application): validate load balancer ports inputs (#4426)
* fix(k8s/application): validate load balancer ports inputs * fix(k8s/application): allow user to only change the protocol on the first port mappingpull/4588/head
parent
7a03351df8
commit
121d33538d
|
@ -1353,7 +1353,7 @@
|
|||
class="btn btn-primary"
|
||||
ng-model="publishedPort.Protocol"
|
||||
uib-btn-radio="'TCP'"
|
||||
ng-change="ctrl.onChangePortMappingContainerPort()"
|
||||
ng-change="ctrl.onChangePortProtocol($index)"
|
||||
ng-disabled="ctrl.isProtocolOptionDisabled($index, 'TCP')"
|
||||
>TCP</label
|
||||
>
|
||||
|
@ -1361,7 +1361,7 @@
|
|||
class="btn btn-primary"
|
||||
ng-model="publishedPort.Protocol"
|
||||
uib-btn-radio="'UDP'"
|
||||
ng-change="ctrl.onChangePortMappingContainerPort()"
|
||||
ng-change="ctrl.onChangePortProtocol($index)"
|
||||
ng-disabled="ctrl.isProtocolOptionDisabled($index, 'UDP')"
|
||||
>UDP</label
|
||||
>
|
||||
|
|
|
@ -303,6 +303,9 @@ class KubernetesCreateApplicationController {
|
|||
const ingresses = this.filteredIngresses;
|
||||
p.IngressName = ingresses && ingresses.length ? ingresses[0].Name : undefined;
|
||||
p.IngressHost = ingresses && ingresses.length ? ingresses[0].Host : undefined;
|
||||
if (this.formValues.PublishedPorts.length) {
|
||||
p.Protocol = this.formValues.PublishedPorts[0].Protocol;
|
||||
}
|
||||
this.formValues.PublishedPorts.push(p);
|
||||
}
|
||||
|
||||
|
@ -335,6 +338,7 @@ class KubernetesCreateApplicationController {
|
|||
this.onChangePortMappingNodePort();
|
||||
this.onChangePortMappingIngressRoute();
|
||||
this.onChangePortMappingLoadBalancer();
|
||||
this.onChangePortProtocol();
|
||||
}
|
||||
|
||||
onChangePortMappingContainerPort() {
|
||||
|
@ -403,6 +407,16 @@ class KubernetesCreateApplicationController {
|
|||
state.hasDuplicates = false;
|
||||
}
|
||||
}
|
||||
|
||||
onChangePortProtocol(index) {
|
||||
this.onChangePortMappingContainerPort();
|
||||
if (this.formValues.PublishingType === KubernetesApplicationPublishingTypes.LOAD_BALANCER) {
|
||||
const newPorts = _.filter(this.formValues.PublishedPorts, { IsNew: true });
|
||||
_.forEach(newPorts, (port) => {
|
||||
port.Protocol = index ? this.formValues.PublishedPorts[index].Protocol : newPorts[0].Protocol;
|
||||
});
|
||||
}
|
||||
}
|
||||
/* #endregion */
|
||||
|
||||
/* #region STATE VALIDATION FUNCTIONS */
|
||||
|
@ -561,6 +575,10 @@ class KubernetesCreateApplicationController {
|
|||
return this.state.isEdit && !this.formValues.Placements[index].IsNew;
|
||||
}
|
||||
|
||||
isNewAndNotFirst(index) {
|
||||
return !this.state.isEdit && index !== 0;
|
||||
}
|
||||
|
||||
showPlacementPolicySection() {
|
||||
const placements = _.filter(this.formValues.Placements, { NeedsDeletion: false });
|
||||
return placements.length !== 0;
|
||||
|
@ -600,8 +618,17 @@ class KubernetesCreateApplicationController {
|
|||
return this.state.isEdit && this.formValues.PublishedPorts.length > 0 && ports.length > 0;
|
||||
}
|
||||
|
||||
isEditLBWithPorts() {
|
||||
return this.formValues.PublishingType === KubernetesApplicationPublishingTypes.LOAD_BALANCER && _.filter(this.formValues.PublishedPorts, { IsNew: false }).length;
|
||||
}
|
||||
|
||||
isProtocolOptionDisabled(index, protocol) {
|
||||
return this.disableLoadBalancerEdit() || (this.isEditAndNotNewPublishedPort(index) && this.formValues.PublishedPorts[index].Protocol !== protocol);
|
||||
return (
|
||||
this.disableLoadBalancerEdit() ||
|
||||
(this.isEditAndNotNewPublishedPort(index) && this.formValues.PublishedPorts[index].Protocol !== protocol) ||
|
||||
(this.isEditLBWithPorts() && this.formValues.PublishedPorts[index].Protocol !== protocol) ||
|
||||
(this.isNewAndNotFirst(index) && this.formValues.PublishedPorts[index].Protocol !== protocol)
|
||||
);
|
||||
}
|
||||
|
||||
/* #endregion */
|
||||
|
|
Loading…
Reference in New Issue