Skip to content

Commit 71cf230

Browse files
sircthulhuclaude
andcommitted
fix(migration): preserve VM MAC address during virtual-machine to vm-instance migration
Migration step 2k stores the old MAC in spec.macAddress of the pre-created IP resource, but Kube-OVN reads MAC exclusively from the pod annotation ovn.kubernetes.io/mac_address. Without the annotation, migrated VMs receive a new random MAC, breaking OS-level network config that matches by MAC (e.g. netplan match: macaddress). Add a Flux postRenderer with a kustomize patch to the vm-instance HelmRelease that injects ovn.kubernetes.io/mac_address and ovn.kubernetes.io/ip_address annotations into the VirtualMachine pod template. This ensures the virt-launcher pod is created with the correct MAC from the first boot, with no race conditions or additional waiting. Co-Authored-By: Claude <[email protected]> Signed-off-by: Kirill Ilin <[email protected]>
1 parent adacd44 commit 71cf230

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

  • packages/core/platform/images/migrations/migrations

‎packages/core/platform/images/migrations/migrations/29‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,31 @@ ISEOF
470470
name: cozystack-values'
471471
fi
472472

473+
# Build postRenderers to inject OVN MAC/IP annotations into the VM pod template.
474+
# Kube-OVN reads MAC address exclusively from the pod annotation
475+
# ovn.kubernetes.io/mac_address, not from the IP resource spec.macAddress.
476+
# Without this, migrated VMs receive a new random MAC address, breaking
477+
# OS-level network config that matches by MAC (e.g. netplan).
478+
POST_RENDERERS=""
479+
if [ -n "$OVN_MAC" ]; then
480+
POST_RENDERERS=" postRenderers:
481+
- kustomize:
482+
patches:
483+
- target:
484+
kind: VirtualMachine
485+
patch: |
486+
apiVersion: kubevirt.io/v1
487+
kind: VirtualMachine
488+
metadata:
489+
name: ${NEW_INSTANCE_NAME}
490+
spec:
491+
template:
492+
metadata:
493+
annotations:
494+
ovn.kubernetes.io/mac_address: \"${OVN_MAC}\"
495+
ovn.kubernetes.io/ip_address: \"${OVN_IP}\""
496+
fi
497+
473498
echo " [CREATE] hr/${NEW_INSTANCE_NAME}"
474499
cat <<IHREOF | kubectl -n "$NAMESPACE" apply -f -
475500
apiVersion: helm.toolkit.fluxcd.io/v2
@@ -501,6 +526,7 @@ spec:
501526
name: ${INSTANCE_VALUES_SECRET}
502527
valuesKey: values.yaml
503528
${COZYSTACK_VALUES_FROM}
529+
${POST_RENDERERS}
504530
IHREOF
505531
fi
506532

0 commit comments

Comments
 (0)