Skip to content

Commit 5187e11

Browse files
lfinmauritiusclaude
andcommitted
feat(vm-instance): pin a static IP on secondary interfaces on both network backends
networks[] exposes a single field per interface, name. A tenant can attach a VM to a VPC network but cannot choose the interface's address, and nothing reports the allocated one either. Add an optional networks[].ipAddress and pin it through whichever backend the cluster serves, picked from API discovery, never from a lookup. Kube-OVN (kubeovn.io/v1 IP served) reads a per-network annotation key, <nad>.<namespace>.ovn.kubernetes.io/ip_address, on the launcher pod. Cozyplane (sdn.cozystack.io/v1alpha1 VPC served, Kube-OVN absent) reads one launcher pod annotation, sdn.cozystack.io/networks: a JSON list with an entry per pinned NIC keyed by the VPC the NetworkAttachmentDefinition names. Both keys are composed from the same <namespace>/<network> expressions the multus reference uses, so a pinned network and an attached network cannot disagree; a key the backend does not recognise is ignored without any admission error. With neither backend served the render fails: a value that would be dropped silently is worse than a render that says why it stopped. Without ipAddress nothing changes: the rendering is byte-identical on every backend, so existing VMs are untouched. The suite drives both branches from the capability set, mocks the Kube-OVN IP object to pin that the historical pod-network annotations keep rendering next to the new key, and is red on the previous template for every pinning case. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: lfneosequentia <[email protected]>
1 parent b142d27 commit 5187e11

7 files changed

Lines changed: 336 additions & 27 deletions

File tree

‎api/apps/v1alpha1/vminstance/types.go‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/apps/vm-instance/README.md‎

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,34 @@ virtctl ssh <user>@<vm>
3636

3737
### Common parameters
3838

39-
| Name | Description | Type | Value |
40-
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ----------- |
41-
| `external` | Enable external access from outside the cluster. | `bool` | `false` |
42-
| `externalMethod` | Method to pass through traffic to the VM. | `string` | `PortList` |
43-
| `externalPorts` | Ports to forward from outside the cluster. | `[]int` | `[22]` |
44-
| `externalAllowICMP` | Whether to accept ICMP traffic to the VM in PortList mode (preserves ping and PMTU discovery). No effect in WholeIP mode. Default true so ping behaves as users expect even when port filtering is in effect. | `bool` | `true` |
45-
| `runStrategy` | Requested running state of the VirtualMachineInstance | `string` | `Always` |
46-
| `instanceType` | Virtual Machine instance type. | `string` | `u1.medium` |
47-
| `instanceProfile` | Virtual Machine preferences profile. | `string` | `ubuntu` |
48-
| `disks` | List of disks to attach. | `[]object` | `[]` |
49-
| `disks[i].name` | Disk name. | `string` | `""` |
50-
| `disks[i].bus` | Disk bus type (e.g. "sata"). | `string` | `""` |
51-
| `networks` | Networks to attach the VM to. | `[]object` | `[]` |
52-
| `networks[i].name` | Network attachment name. | `string` | `""` |
53-
| `subnets` | Deprecated: use networks instead. | `[]object` | `[]` |
54-
| `subnets[i].name` | Network attachment name. | `string` | `""` |
55-
| `gpus` | List of GPUs to attach (NVIDIA driver requires at least 4 GiB RAM). | `[]object` | `[]` |
56-
| `gpus[i].name` | The name of the GPU resource to attach. | `string` | `""` |
57-
| `cpuModel` | Model specifies the CPU model inside the VMI. List of available models https://github.com/libvirt/libvirt/tree/master/src/cpu_map | `string` | `""` |
58-
| `resources` | Resource configuration for the virtual machine. | `object` | `{}` |
59-
| `resources.cpu` | Number of CPU cores allocated. | `quantity` | `""` |
60-
| `resources.memory` | Amount of memory allocated. | `quantity` | `""` |
61-
| `resources.sockets` | Number of CPU sockets (vCPU topology). | `quantity` | `""` |
62-
| `sshKeys` | List of SSH public keys for authentication. | `[]string` | `[]` |
63-
| `cloudInit` | Cloud-init user data. | `string` | `""` |
64-
| `cloudInitSeed` | Seed string to generate SMBIOS UUID for the VM. | `string` | `""` |
39+
| Name | Description | Type | Value |
40+
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------- | ----------- |
41+
| `external` | Enable external access from outside the cluster. | `bool` | `false` |
42+
| `externalMethod` | Method to pass through traffic to the VM. | `string` | `PortList` |
43+
| `externalPorts` | Ports to forward from outside the cluster. | `[]int` | `[22]` |
44+
| `externalAllowICMP` | Whether to accept ICMP traffic to the VM in PortList mode (preserves ping and PMTU discovery). No effect in WholeIP mode. Default true so ping behaves as users expect even when port filtering is in effect. | `bool` | `true` |
45+
| `runStrategy` | Requested running state of the VirtualMachineInstance | `string` | `Always` |
46+
| `instanceType` | Virtual Machine instance type. | `string` | `u1.medium` |
47+
| `instanceProfile` | Virtual Machine preferences profile. | `string` | `ubuntu` |
48+
| `disks` | List of disks to attach. | `[]object` | `[]` |
49+
| `disks[i].name` | Disk name. | `string` | `""` |
50+
| `disks[i].bus` | Disk bus type (e.g. "sata"). | `string` | `""` |
51+
| `networks` | Networks to attach the VM to. | `[]object` | `[]` |
52+
| `networks[i].name` | Network attachment name. | `string` | `""` |
53+
| `networks[i].ipAddress` | Static IPv4 address for this interface, pinned through the network backend the cluster serves (Kube-OVN or Cozyplane). Empty lets IPAM allocate one. The address must be free and inside the network CIDR; the backend refuses the VM otherwise. | `string` | `""` |
54+
| `subnets` | Deprecated: use networks instead. | `[]object` | `[]` |
55+
| `subnets[i].name` | Network attachment name. | `string` | `""` |
56+
| `subnets[i].ipAddress` | Static IPv4 address for this interface, pinned through the network backend the cluster serves (Kube-OVN or Cozyplane). Empty lets IPAM allocate one. The address must be free and inside the network CIDR; the backend refuses the VM otherwise. | `string` | `""` |
57+
| `gpus` | List of GPUs to attach (NVIDIA driver requires at least 4 GiB RAM). | `[]object` | `[]` |
58+
| `gpus[i].name` | The name of the GPU resource to attach. | `string` | `""` |
59+
| `cpuModel` | Model specifies the CPU model inside the VMI. List of available models https://github.com/libvirt/libvirt/tree/master/src/cpu_map | `string` | `""` |
60+
| `resources` | Resource configuration for the virtual machine. | `object` | `{}` |
61+
| `resources.cpu` | Number of CPU cores allocated. | `quantity` | `""` |
62+
| `resources.memory` | Amount of memory allocated. | `quantity` | `""` |
63+
| `resources.sockets` | Number of CPU sockets (vCPU topology). | `quantity` | `""` |
64+
| `sshKeys` | List of SSH public keys for authentication. | `[]string` | `[]` |
65+
| `cloudInit` | Cloud-init user data. | `string` | `""` |
66+
| `cloudInitSeed` | Seed string to generate SMBIOS UUID for the VM. | `string` | `""` |
6567

6668

6769
## U Series

‎packages/apps/vm-instance/templates/vm.yaml‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,35 @@ spec:
4343
ovn.kubernetes.io/ip_address: {{ $ovnIP.spec.ipAddress | quote }}
4444
{{- end }}
4545
{{- end }}
46+
{{- /*
47+
networks[].ipAddress pins the address of a secondary NIC through whichever
48+
backend the cluster serves. Kube-OVN reads a per-network annotation key,
49+
<nad>.<namespace>.ovn.kubernetes.io/ip_address. Cozyplane reads one launcher
50+
pod annotation, sdn.cozystack.io/networks, a JSON list keyed by the VPC the
51+
NAD names. Both keys are composed from the same <namespace>/<network> the
52+
multus reference below uses, so a pinned network and an attached network
53+
cannot disagree. With neither backend served the render fails: a value that
54+
would be dropped silently is worse than a render that says why it stopped.
55+
*/}}
56+
{{- $pinned := list }}
57+
{{- range $net := $networks }}
58+
{{- if $net.ipAddress }}
59+
{{- $pinned = append $pinned (dict "vpc" (printf "%s/%s" $.Release.Namespace $net.name) "ip" $net.ipAddress) }}
60+
{{- end }}
61+
{{- end }}
62+
{{- if $pinned }}
63+
{{- if .Capabilities.APIVersions.Has "kubeovn.io/v1/IP" }}
64+
{{- range $net := $networks }}
65+
{{- if $net.ipAddress }}
66+
{{ printf "%s.%s.ovn.kubernetes.io/ip_address" $net.name $.Release.Namespace }}: {{ $net.ipAddress | quote }}
67+
{{- end }}
68+
{{- end }}
69+
{{- else if .Capabilities.APIVersions.Has "sdn.cozystack.io/v1alpha1/VPC" }}
70+
sdn.cozystack.io/networks: {{ $pinned | toJson | quote }}
71+
{{- else }}
72+
{{- fail "networks[].ipAddress needs a network backend that pins addresses: neither kubeovn.io/v1 IP nor sdn.cozystack.io/v1alpha1 VPC is served" }}
73+
{{- end }}
74+
{{- end }}
4675
labels:
4776
{{- include "virtual-machine.labels" . | nindent 8 }}
4877
spec:

0 commit comments

Comments
 (0)