Skip to content

[FEATURE] Add option to select network interface model while importing VM #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025

Conversation

votdev
Copy link
Member

@votdev votdev commented Apr 17, 2025

Problem:
The network interface model of an imported VM is set to "VirtIO" by default.

Solution:
Add the field DefaultNetworkInterfaceModel to VirtualMachineImportSpec and NetworkInterfaceModel to NetworkMapping. With this new fields it is possible to customize the interface models of the VM NICs.

The DefaultNetworkInterfaceModel field is always used when:

  • Auto-detection fails (OpenStack source client does not have auto-detection, therefor this field is used for every network interface).
  • No network mapping is provided and a "pod-network" is auto-created.
    It defaults to "virtio".

Related Issue:
harvester/harvester#7999

Test plan:
Case 1

  1. Create a VM import that looks like this:
apiVersion: migration.harvesterhci.io/v1beta1
kind: VirtualMachineImport
metadata:
  name: cirros-tiny
  namespace: default
spec:
  virtualMachineName: "cirros-tiny"
  networkMapping:
  - sourceNetwork: "shared"
    destinationNetwork: "default/vlan1"
    networkInterfaceModel: e1000a
...
  1. Import the YAML file.
  2. The following error message should be displayed.
The VirtualMachineImport "cirros-tiny" is invalid: spec.networkMapping[0].networkInterfaceModel: Unsupported value: "e1000a": supported values: "e1000", "e1000e", "ne2k_pci", "pcnet", "rtl8139", "virtio", ""

Case 2

  1. Create a VM import that looks like this:
apiVersion: migration.harvesterhci.io/v1beta1
kind: VirtualMachineImport
metadata:
  name: cirros-tiny
  namespace: default
spec:
  virtualMachineName: "cirros-tiny"
  networkMapping:
  - sourceNetwork: "shared"
    destinationNetwork: "default/vlan1"
    networkInterfaceModel: e1000
...
  1. Import the YAML file.
  2. The VM should be imported. Go to Virtual Machines in the UI and choose Edit YAML. The following code should exist:
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  ...
  name: cirros-tiny
  namespace: default
  ...
spec:
  template:
    spec:
      domain:
        devices:
          interfaces:
            - bridge: {}
              macAddress: fa:16:3e:25:90:74
              model: e1000
              name: migrated-0

The interface migrated-0 with model e1000 should be configured.

Case 3

  1. Create a VM import that looks like this:
apiVersion: migration.harvesterhci.io/v1beta1
kind: VirtualMachineImport
metadata:
  name: cirros-tiny
  namespace: default
spec:
  virtualMachineName: "cirros-tiny"
  defaultNetworkInterfaceModel: foo
...
  1. Import the YAML file.
  2. The following error message should be displayed.
The VirtualMachineImport "cirros-tiny" is invalid: spec.defaultNetworkInterfaceModel: Unsupported value: "foo": supported values: "e1000", "e1000e", "ne2k_pci", "pcnet", "rtl8139", "virtio", ""

Case 4

  1. Create a VM import that looks like this:
apiVersion: migration.harvesterhci.io/v1beta1
kind: VirtualMachineImport
metadata:
  name: cirros-tiny
  namespace: default
spec:
  virtualMachineName: "cirros-tiny"
  defaultNetworkInterfaceModel: e1000e
...
  1. Import the YAML file.
  2. The VM should be imported. Go to Virtual Machines in the UI and choose Edit YAML. The following code should exist:
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  ...
  name: cirros-tiny
  namespace: default
  ...
spec:
  template:
    spec:
      domain:
        devices:
          interfaces:
            - macAddress: 22:e5:2f:6c:b0:1f
              masquerade: {}
              model: e1000e
              name: pod-network

The interface pod-network with model e1000e should be configured.

@votdev votdev self-assigned this Apr 17, 2025
@votdev votdev force-pushed the issue_7999_net_iface_model branch 2 times, most recently from 4cf59e8 to 17576f8 Compare May 5, 2025 12:46
@votdev votdev marked this pull request as ready for review May 5, 2025 14:15
@Copilot Copilot AI review requested due to automatic review settings May 5, 2025 14:15
@votdev votdev force-pushed the issue_7999_net_iface_model branch from 17576f8 to 165aa7e Compare May 5, 2025 14:15
Copilot

This comment was marked as resolved.

w13915984028
w13915984028 previously approved these changes May 6, 2025
Copy link
Member

@w13915984028 w13915984028 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

result = append(result, source.NetworkInfo{
NetworkName: obj.DeviceInfo.GetDescription().Summary,
MAC: obj.MacAddress,
Model: migration.NetworkInterfaceModelPcnet,
})
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there default case to process? if above cases are all not hit

Copy link
Member Author

@votdev votdev May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because the processed list of devices can contain other hardware/devices than NICs.

@votdev votdev changed the title Add option to select network interface model while importing VM [FEATURE] Add option to select network interface model while importing VM May 7, 2025
Name: "pod-network",
Model: defaultNetworkInterfaceModel,
InterfaceBindingMethod: kubevirt.InterfaceBindingMethod{
Masquerade: &kubevirt.InterfaceMasquerade{},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason not using the bridge interface here?

Copy link
Member Author

@votdev votdev May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I can't say anything here as I have adopted the code 1:1.

@ibrokethecloud added the origin code. Could you tell use more please?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is no valid source to destination mapping we default to adding the masquerade network which is the current default behaviour of harvester during vm creation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. Thanks for clarifying. I was just considering what might be the most compatible configuration :D

ibrokethecloud
ibrokethecloud previously approved these changes May 21, 2025
Copy link
Collaborator

@ibrokethecloud ibrokethecloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. thanks.

starbops
starbops previously approved these changes May 21, 2025
Copy link
Member

@starbops starbops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you.

…rvester using the vm-import-controller

Add the field `DefaultNetworkInterfaceModel` to `VirtualMachineImportSpec` and `NetworkInterfaceModel` to `NetworkMapping`. With this new fields it is possible to customize the interface models of the VM NICs.

Related to: harvester/harvester#7999

Signed-off-by: Volker Theile <[email protected]>
@votdev votdev dismissed stale reviews from starbops, ibrokethecloud, and w13915984028 via 3d9b2f6 May 26, 2025 08:41
@votdev votdev force-pushed the issue_7999_net_iface_model branch from 19ef681 to 3d9b2f6 Compare May 26, 2025 08:41
@votdev votdev merged commit d3ad44e into harvester:main May 26, 2025
2 checks passed
@votdev votdev deleted the issue_7999_net_iface_model branch May 26, 2025 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants