Enhancement: support nested services via labels for mixed layout-only groups (#5295)

This commit is contained in:
shamoon 2025-05-20 23:29:22 -07:00 committed by GitHub
parent 564a0880b0
commit ea37ab2f78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -135,6 +135,28 @@ function pruneEmptyGroups(groups) {
}); });
} }
function mergeLayoutGroupsIntoConfigured(configuredGroups, layoutGroups) {
for (const layoutGroup of layoutGroups) {
const existing = findGroupByName(configuredGroups, layoutGroup.name);
if (existing) {
if (layoutGroup.groups?.length) {
existing.groups ??= [];
for (const sub of layoutGroup.groups) {
const existingSub = findGroupByName(existing.groups, sub.name);
if (!existingSub) {
existing.groups.push(sub);
} else {
// recursive merge if needed
mergeLayoutGroupsIntoConfigured([existingSub], [sub]);
}
}
}
} else {
configuredGroups.push(layoutGroup);
}
}
}
export async function servicesResponse() { export async function servicesResponse() {
let discoveredDockerServices; let discoveredDockerServices;
let discoveredKubernetesServices; let discoveredKubernetesServices;
@ -191,14 +213,10 @@ export async function servicesResponse() {
const definedLayouts = initialSettings.layout ? Object.keys(initialSettings.layout) : null; const definedLayouts = initialSettings.layout ? Object.keys(initialSettings.layout) : null;
if (definedLayouts) { if (definedLayouts) {
// this handles cases where groups are only defined in the settings.yaml layout and not in the services.yaml // this handles cases where groups are only defined in the settings.yaml layout and not in the services.yaml
const layoutConfiguredGroups = Object.entries(initialSettings.layout).map(([key, value]) => const layoutGroups = Object.entries(initialSettings.layout).map(([key, value]) =>
convertLayoutGroupToGroup(key, value), convertLayoutGroupToGroup(key, value),
); );
layoutConfiguredGroups.forEach((group) => { mergeLayoutGroupsIntoConfigured(configuredServices, layoutGroups);
if (!configuredServices.find((serviceGroup) => serviceGroup.name === group.name)) {
configuredServices.push(group);
}
});
} }
mergedGroupsNames.forEach((groupName) => { mergedGroupsNames.forEach((groupName) => {