mirror of
https://github.com/cozystack/cozystack.git
synced 2026-10-29 16:17:20 +09:00
Keying the network-data on instanceProfile reached every VM that never set the field, because the profile defaults to ubuntu whatever image the disk holds. The sysconfig, NetworkManager and eni renderers turn each match stanza into an interface literally named after the netplan ID, so a non-netplan guest left on the default profile would lose the DHCP it gets today. A VM with neither cloudInit nor sshKeys would also gain a cloud-init disk on upgrade, and KubeVirt's NoCloud instance-id is new to that guest, so its next boot would regenerate host keys as a first boot. The configuration also shadows a static NIC set up through netplan: netplan emits one networkd file per ID, networkd applies only the first file in lexical order that matches a link, and 10-netplan-cozy-en sorts before the file for enp2s0. The external-VLAN recipe claimed otherwise. An explicit netplanDhcp value, off by default, leaves every existing VM rendering exactly as before and lets the documentation say when not to turn it on. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
138 lines
4.7 KiB
YAML
138 lines
4.7 KiB
YAML
suite: vm-instance cloud-init network-data for netplan guests (netplanDhcp)
|
|
|
|
# A netplan guest configures only the interface cloud-init's fallback covers and
|
|
# keeps none of the DHCP-supplied search domains, so the assertions below are on
|
|
# the two properties that change that: every ethernet asks for DHCP, and the
|
|
# link keeps the domains it is offered. Naming an interface instead of matching
|
|
# a glob would satisfy a field assertion and still leave a guest whose NICs
|
|
# enumerate differently unconfigured, which is why the match stanza is asserted
|
|
# rather than the presence of the key.
|
|
release:
|
|
name: test-vm
|
|
namespace: tenant-test
|
|
templates:
|
|
- templates/vm.yaml
|
|
- templates/secret-network-config.yaml
|
|
set:
|
|
fullnameOverride: test-vm
|
|
instanceType: ""
|
|
resources:
|
|
cpu: 1
|
|
sockets: 1
|
|
memory: 1Gi
|
|
_cluster:
|
|
scheduling:
|
|
dedicatedNodesForWindowsVMs: "false"
|
|
kubernetesProvider:
|
|
scheme:
|
|
"instancetype.kubevirt.io/v1beta1/VirtualMachineClusterPreference":
|
|
gvr:
|
|
group: instancetype.kubevirt.io
|
|
version: v1beta1
|
|
resource: virtualmachineclusterpreferences
|
|
namespaced: false
|
|
objects:
|
|
- apiVersion: instancetype.kubevirt.io/v1beta1
|
|
kind: VirtualMachineClusterPreference
|
|
metadata:
|
|
name: ubuntu
|
|
- apiVersion: instancetype.kubevirt.io/v1beta1
|
|
kind: VirtualMachineClusterPreference
|
|
metadata:
|
|
name: rhel.9
|
|
tests:
|
|
- it: gives every ethernet DHCP and keeps the offered search domains
|
|
set:
|
|
netplanDhcp: true
|
|
asserts:
|
|
- template: templates/secret-network-config.yaml
|
|
equal:
|
|
path: stringData.networkdata
|
|
value: |
|
|
network:
|
|
version: 2
|
|
ethernets:
|
|
cozy-en:
|
|
match:
|
|
name: "en*"
|
|
dhcp4: true
|
|
dhcp4-overrides:
|
|
use-domains: true
|
|
cozy-eth:
|
|
match:
|
|
name: "eth*"
|
|
dhcp4: true
|
|
dhcp4-overrides:
|
|
use-domains: true
|
|
|
|
- it: attaches the network-data to the VM even when no user-data is requested
|
|
set:
|
|
netplanDhcp: true
|
|
asserts:
|
|
- template: templates/vm.yaml
|
|
equal:
|
|
path: spec.template.spec.volumes[?(@.name=="cloudinitdisk")].cloudInitNoCloud.networkDataSecretRef.name
|
|
value: test-vm-network-config
|
|
- template: templates/vm.yaml
|
|
notExists:
|
|
path: spec.template.spec.volumes[?(@.name=="cloudinitdisk")].cloudInitNoCloud.secretRef
|
|
- template: templates/vm.yaml
|
|
equal:
|
|
path: spec.template.spec.domain.devices.disks[?(@.name=="cloudinitdisk")].disk
|
|
value: {}
|
|
|
|
- it: carries user-data and network-data side by side
|
|
set:
|
|
netplanDhcp: true
|
|
cloudInit: |
|
|
#cloud-config
|
|
packages:
|
|
- htop
|
|
asserts:
|
|
- template: templates/vm.yaml
|
|
equal:
|
|
path: spec.template.spec.volumes[?(@.name=="cloudinitdisk")].cloudInitNoCloud.secretRef.name
|
|
value: test-vm-cloud-init
|
|
- template: templates/vm.yaml
|
|
equal:
|
|
path: spec.template.spec.volumes[?(@.name=="cloudinitdisk")].cloudInitNoCloud.networkDataSecretRef.name
|
|
value: test-vm-network-config
|
|
|
|
# The default instanceProfile is ubuntu whatever image the disk holds, and a
|
|
# cloud-init disk appearing on a VM that never had one makes the guest's next
|
|
# boot a first boot, so a VM that leaves the key alone must render exactly as
|
|
# before: no network-data and no cloud-init disk.
|
|
- it: leaves a VM on the default profile without network-data or a cloud-init disk
|
|
asserts:
|
|
- template: templates/secret-network-config.yaml
|
|
hasDocuments:
|
|
count: 0
|
|
- template: templates/vm.yaml
|
|
notExists:
|
|
path: spec.template.spec.volumes[?(@.name=="cloudinitdisk")]
|
|
- template: templates/vm.yaml
|
|
notExists:
|
|
path: spec.template.spec.domain.devices.disks[?(@.name=="cloudinitdisk")]
|
|
|
|
- it: keeps user-data alone when the key is off
|
|
set:
|
|
cloudInit: |
|
|
#cloud-config
|
|
asserts:
|
|
- template: templates/vm.yaml
|
|
equal:
|
|
path: spec.template.spec.volumes[?(@.name=="cloudinitdisk")].cloudInitNoCloud.secretRef.name
|
|
value: test-vm-cloud-init
|
|
- template: templates/vm.yaml
|
|
notExists:
|
|
path: spec.template.spec.volumes[?(@.name=="cloudinitdisk")].cloudInitNoCloud.networkDataSecretRef
|
|
|
|
- it: follows the key rather than the instance profile
|
|
set:
|
|
instanceProfile: rhel.9
|
|
netplanDhcp: true
|
|
asserts:
|
|
- template: templates/secret-network-config.yaml
|
|
hasDocuments:
|
|
count: 1
|