mirror of https://github.com/rancher/dashboard.git
PR feedback checking targetPort is number
removed a function that coerced target port to a number all the time which is not valid as it can be a string
This commit is contained in:
parent
aa33b16785
commit
e45da6c823
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { isEmpty, isNaN } from 'lodash';
|
import { isEmpty } from 'lodash';
|
||||||
import ArrayList from '@/components/form/ArrayList';
|
import ArrayList from '@/components/form/ArrayList';
|
||||||
import CreateEditView from '@/mixins/create-edit-view';
|
import CreateEditView from '@/mixins/create-edit-view';
|
||||||
import KeyValue from '@/components/form/KeyValue';
|
import KeyValue from '@/components/form/KeyValue';
|
||||||
|
|
@ -150,16 +150,6 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
updateServicePorts(servicePorts) {
|
updateServicePorts(servicePorts) {
|
||||||
servicePorts.forEach((sp) => {
|
|
||||||
if (!isEmpty(sp?.targetPort)) {
|
|
||||||
const tpCoerced = parseInt(sp.targetPort, 10);
|
|
||||||
|
|
||||||
if (!isNaN(tpCoerced)) {
|
|
||||||
sp.targetPort = tpCoerced;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.$set(this.value.spec, 'ports', servicePorts);
|
this.$set(this.value.spec, 'ports', servicePorts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,10 +58,12 @@ export function servicePort(spec, getters, errors, validatorArgs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetPort) {
|
if (targetPort) {
|
||||||
|
const tpIanaDisplayKey = getters['i18n/t']('validation.service.ports.targetPort.ianaAt', { position: idx });
|
||||||
const tp = parseInt(targetPort, 10);
|
const tp = parseInt(targetPort, 10);
|
||||||
|
const tpTest = new RegExp('^\\d+$');
|
||||||
|
const targetPortIsNumber = tpTest.test(targetPort);
|
||||||
|
|
||||||
if (isNaN(tp)) {
|
if (!targetPortIsNumber) { // not a number
|
||||||
const tpIanaDisplayKey = getters['i18n/t']('validation.service.ports.targetPort.ianaAt', { position: idx });
|
|
||||||
/* [rfc6335](https://tools.ietf.org/rfc/rfc6335.txt) port name (IANA_SVC_NAME)
|
/* [rfc6335](https://tools.ietf.org/rfc/rfc6335.txt) port name (IANA_SVC_NAME)
|
||||||
An alphanumeric (a-z, and 0-9) string, with a maximum length of 15 characters,
|
An alphanumeric (a-z, and 0-9) string, with a maximum length of 15 characters,
|
||||||
with the '-' character allowed anywhere except the first or the last character or adjacent to another '-' character,
|
with the '-' character allowed anywhere except the first or the last character or adjacent to another '-' character,
|
||||||
|
|
@ -118,16 +120,18 @@ export function externalName(spec, getters, errors, validatorArgs) {
|
||||||
No proxying will be involved.
|
No proxying will be involved.
|
||||||
Must be a valid RFC-1123 hostname (https://tools.ietf.org/html/rfc1123) and requires Type to be ExternalName.
|
Must be a valid RFC-1123 hostname (https://tools.ietf.org/html/rfc1123) and requires Type to be ExternalName.
|
||||||
*/
|
*/
|
||||||
if (spec?.type !== 'ExternalName' && isEmpty(spec?.externalName)) {
|
if (spec?.type === 'ExternalName') {
|
||||||
errors.push(getters['i18n/t']('validation.service.clusterIp.none'));
|
if (isEmpty(spec?.externalName)) {
|
||||||
} else {
|
errors.push(getters['i18n/t']('validation.service.externalName.none'));
|
||||||
const hostNameErrors = validateHostname(spec.externalName, 'ExternalName', getters, undefined, errors);
|
} else {
|
||||||
|
const hostNameErrors = validateHostname(spec.externalName, 'ExternalName', getters, undefined, errors);
|
||||||
|
|
||||||
if (!isEmpty(hostNameErrors)) {
|
if (!isEmpty(hostNameErrors)) {
|
||||||
if (errors.length && errors.length > 0) {
|
if (errors.length && errors.length > 0) {
|
||||||
errors = [...errors, ...hostNameErrors];
|
errors = [...errors, ...hostNameErrors];
|
||||||
} else {
|
} else {
|
||||||
errors = hostNameErrors;
|
errors = hostNameErrors;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue