From 5a0d7f283de64db2962cf17a4e629337579af238 Mon Sep 17 00:00:00 2001 From: Andy Lee Date: Tue, 23 Sep 2025 16:32:39 +0800 Subject: [PATCH] fix: unable to create VM when choosing L2VlanNetwork (#534) * fix: unable to create VM via l2vlan network Signed-off-by: Andy Lee * refactor: based on discussion Signed-off-by: Andy Lee * refactor: add comment Signed-off-by: Andy Lee --------- Signed-off-by: Andy Lee --- pkg/harvester/mixins/harvester-vm/index.js | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pkg/harvester/mixins/harvester-vm/index.js b/pkg/harvester/mixins/harvester-vm/index.js index 0dc93d31..ebbd2496 100644 --- a/pkg/harvester/mixins/harvester-vm/index.js +++ b/pkg/harvester/mixins/harvester-vm/index.js @@ -892,7 +892,7 @@ export default { }); const specInterfaces = this.spec?.template?.spec?.domain?.devices?.interfaces; - const mergedInterfaces = this.mergeDeviceList(specInterfaces, interfaces); + const mergedInterfaces = this.mergeInterfaceList(specInterfaces, interfaces); const spec = { ...this.spec.template.spec, @@ -1551,6 +1551,32 @@ export default { this.refreshYamlEditor(); }, + mergeInterfaceList(specInterfaceList, interfaceList) { + if (!specInterfaceList || specInterfaceList.length === 0) { + return interfaceList; + } + const specInterfaceMap = new Map(specInterfaceList.map((iface) => [iface.name, iface])); + + return interfaceList.map((iface) => { + const specInterface = specInterfaceMap.get(iface.name); + + if (specInterface) { + const merged = { ...specInterface, ...iface }; + + // currently we only have bridge and masquerade network type, they are mutually exclusive + if (iface['bridge']) { + delete merged['masquerade']; + } else { + delete merged['bridge']; + } + + return merged; + } + + return iface; + }); + }, + mergeDeviceList(specDeviceList, deviceList) { if (!specDeviceList || specDeviceList.length === 0) { return deviceList;