feat(vm): cocoon vm clone --nics N to override snapshot NIC count#43
Merged
Conversation
a79b0f5 to
cdc5ccc
Compare
clone has always inherited NIC count from the snapshot. With the new runtime net resize, a VM resized down to 0 NICs then snapshot'd produces a clone that can't recover networking later: CH started in host netns because NetworkConfigs was empty, so a subsequent vm net adds NICs in the per-VM netns CH never entered. Mirror cocoon vm run's --nics: passing --nics N at clone time forces N NICs at clone start, putting CH into the per-VM netns from the start and keeping the rest of the lifecycle aligned with --nics ≥ 1 path. -1 (default) preserves inheritance from snapshot. Adjust the vm net error to point users at the clone override when they hit the zero-NIC resize-up wall.
cdc5ccc to
4dbc79d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
--nics Nflag tococoon vm cloneto override the NIC count inherited from the snapshot at clone time.-1(default) keeps inheritance behavior.Why
The new
cocoon vm net(PR #42) allows runtime NIC resize on running VMs — but only when CH was started with at least 1 NIC. CH process's netns is decided at boot:A VM resized to 0 NICs → snapshot'd → cloned ends up with CH in host netns because
NetworkConfigsis empty. A latervm net --nics 1creates per-VM-netns plumbing CH cannot reach (it ends up making a phantom TAP in host netns, no traffic flows).Linux + CH doesn't allow changing another process's netns from outside, so we can't fix it at
vm nettime without breaking the netns boundary (persisting BridgeDev, adding NetnsPath to VMRecord, etc.).This PR sidesteps the problem cleanly: at clone time the user picks the NIC count. If they want to recover networking after a zero-NIC snapshot,
clone --nics 1puts the new clone on the standard "started with N NICs" path, CH lands in the per-VM netns at boot, andvm netresize later works as designed.Also updates the
vm netzero-NIC error to point users at this new flag.Tested
cocoon vm clone --nics 1 SNAPSHOT_WITH_0_NICSon a Linux OCI ubuntu produces a clone with the expected per-VM netns + working DHCP.cocoon vm clone --nics 0on a snapshot with NICs strips them at clone (intentional zero start; can't resize up later, consistent withvm run --nics 0).cocoon vm clone SNAPSHOT(no--nics) preserves snapshot's NIC count (unchanged behavior).make lint+go test ./...green.Test plan
--nics 1and verify DHCP--nics 0and verify VM has no networking--nicsinherits as before🤖 Generated with Claude Code