fix(service): fix service name starting from zero EE-2807 (#6694)

* fix service name index
pull/6714/head
Richard Wei 2022-03-31 10:34:29 +13:00 committed by GitHub
parent fb7f24df9c
commit ec3d7026d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 10 deletions

View File

@ -21,26 +21,32 @@ export default class KubeServicesViewController {
p.Selector = this.formValues.Selector;
p.Name = this.getUniqName();
this.state.nameIndex += 1;
this.formValues.Services.push(p);
}
getUniqName() {
let name = this.formValues.Name + '-' + this.state.nameIndex;
//services name will follow thia patten: service, service-2, service-3...
let nameIndex = 2;
let UniqName = this.formValues.Name;
const services = this.formValues.Services;
services.forEach((service) => {
if (service.Name === name) {
this.state.nameIndex += 1;
name = this.formValues.Name + '-' + this.state.nameIndex;
}
const sortServices = services.sort((a, b) => {
return a.Name.localeCompare(b.Name);
});
const UniqName = this.formValues.Name + '-' + this.state.nameIndex;
if (sortServices.length !== 0) {
sortServices.forEach((service) => {
if (service.Name === UniqName) {
UniqName = this.formValues.Name + '-' + nameIndex;
nameIndex += 1;
}
});
}
return UniqName;
}
deleteService(index) {
this.formValues.Services.splice(index, 1);
this.state.nameIndex -= 1;
}
addPort(index) {
@ -98,7 +104,6 @@ export default class KubeServicesViewController {
},
],
selected: KubernetesApplicationPublishingTypes.CLUSTER_IP,
nameIndex: this.formValues.Services.length,
endpointId: this.EndpointProvider.endpointID(),
};
}