Use array for ingress rule path

https://github.com/rancher/rancher/issues/17529
This commit is contained in:
loganhz 2019-01-24 15:56:47 +08:00 committed by Craig Jellick
parent 2ac136533c
commit d59da85e45
1 changed files with 5 additions and 46 deletions

View File

@ -44,7 +44,7 @@ export default Component.extend({
if (get(this, 'isDefault')) {
this.setDefaultBackend();
} else {
this.setPaths();
set(this, 'rule.paths', get(this, 'pathArray'));
}
}),
@ -69,18 +69,16 @@ export default Component.extend({
initPathArray() {
const pathArray = [];
const paths = get(this, 'rule.paths');
Object.keys(paths).forEach((p) => {
const path = paths[p];
const paths = get(this, 'rule.paths') || [];
paths.forEach((path) => {
if (get(path, 'serviceId')) {
pathArray.pushObject(get(this, 'store').createRecord({
type: 'httpingresspath',
backendType: 'service',
targetPort: `${ get(path, 'targetPort') || '' }`,
serviceId: get(path, 'serviceId').replace('/', ':'),
path: p,
path: get(path, 'path'),
}));
} else if (get(path, 'workloadIds')) {
get(path, 'workloadIds').forEach((workload) => {
@ -88,7 +86,7 @@ export default Component.extend({
backendType: 'workload',
targetPort: get(path, 'targetPort'),
serviceId: workload,
path: p,
path: get(path, 'path'),
});
});
}
@ -114,43 +112,4 @@ export default Component.extend({
});
set(this, 'ingress.defaultBackend', defaultBackend);
},
setPaths() {
const pathArray = get(this, 'pathArray');
const paths = {};
pathArray.forEach((path) => {
const backendType = get(path, 'backendType');
const pathValue = get(path, 'path');
const serviceId = get(path, 'serviceId');
const targetPort = get(path, 'targetPort');
if (backendType === 'service') {
const found = paths[pathValue];
if (found) {
found.serviceId = serviceId;
found.targetPort = targetPort;
} else {
paths[pathValue] = {
serviceId,
targetPort,
};
}
} else if (backendType === 'workload') {
const found = paths[pathValue];
if (found && found.workloadIds) {
found.workloadIds.pushObject(serviceId);
found.targetPort = targetPort;
} else {
paths[pathValue] = {
workloadIds: [serviceId],
targetPort,
};
}
}
})
set(this, 'rule.paths', paths);
}
});