Skip to content

Commit 8519304

Browse files
lfinmauritiusclaude
andcommitted
feat(vm-instance): allow pinning a static IP on secondary interfaces
`networks[].name` is the only per-interface field the chart exposes, so a tenant cannot choose the address of a VM's secondary interface, and `VMInstance.status` does not report it either. kube-ovn already accepts a per-network annotation for exactly this, `<nad>.<namespace>.ovn.kubernetes.io/ip_address`. This adds an optional `networks[].ipAddress` that renders it. The key is built from the same two expressions the template already uses to compose the multus reference `<namespace>/<nad>`, so the annotated network and the attached network cannot disagree. That matters more than it looks: a key kube-ovn does not recognise is ignored silently, with no admission error, and IPAM then allocates some other address. Rendering is unchanged byte for byte when `ipAddress` is unset. With it set, exactly one annotation line is added, for each interface that asks for one. `subnets`, the deprecated alias of `networks`, shares the `Network` type and so gains the field as well; it resolves through the same variable. No CIDR membership check: the chart does not know the subnet, which belongs to the `vpc` application. kube-ovn rejects an address outside the subnet. Generated files are updated accordingly, and unit tests cover the rendered annotation, its absence, the per-interface scoping and the deprecated alias. Co-Authored-By: Claude Opus 5 <[email protected]>
1 parent 5fe9450 commit 8519304

7 files changed

Lines changed: 125 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. Empty lets kube-ovn IPAM allocate one. The address must belong to the subnet CIDR; kube-ovn rejects one outside it. | `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. Empty lets kube-ovn IPAM allocate one. The address must belong to the subnet CIDR; kube-ovn rejects one outside it. | `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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ spec:
4141
ovn.kubernetes.io/mac_address: {{ $ovnIP.spec.macAddress | quote }}
4242
ovn.kubernetes.io/ip_address: {{ $ovnIP.spec.ipAddress | quote }}
4343
{{- end }}
44+
{{- range $net := $networks }}
45+
{{- if $net.ipAddress }}
46+
{{ printf "%s.%s.ovn.kubernetes.io/ip_address" $net.name $.Release.Namespace }}: {{ $net.ipAddress | quote }}
47+
{{- end }}
48+
{{- end }}
4449
labels:
4550
{{- include "virtual-machine.labels" . | nindent 8 }}
4651
spec:
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
suite: vm-instance static IP address on secondary interfaces
2+
3+
# kube-ovn pins an address on a secondary interface through a PER-NETWORK annotation key,
4+
# `<nad>.<namespace>.ovn.kubernetes.io/ip_address`. The key is built from the same two
5+
# expressions the chart already uses to compose the multus reference `<namespace>/<nad>`,
6+
# so a network named here and a network attached below can never disagree. A key kube-ovn
7+
# does not recognise is ignored silently — no admission error — which is why the exact
8+
# form is asserted rather than described.
9+
#
10+
# `instanceType` is left empty and `resources` supplied instead: the guards at the top of
11+
# vm.yaml resolve instance types through `lookup`, which no live cluster backs here.
12+
release:
13+
name: test-vm
14+
namespace: tenant-test
15+
templates:
16+
- templates/vm.yaml
17+
set:
18+
instanceType: ""
19+
instanceProfile: ""
20+
resources:
21+
cpu: 2
22+
sockets: 1
23+
memory: 4Gi
24+
_cluster:
25+
scheduling: {}
26+
tests:
27+
- it: pins the requested address through the per-network annotation
28+
set:
29+
networks:
30+
- name: subnet-a
31+
ipAddress: 10.77.7.5
32+
documentSelector:
33+
path: kind
34+
value: VirtualMachine
35+
asserts:
36+
- equal:
37+
path: spec.template.metadata.annotations["subnet-a.tenant-test.ovn.kubernetes.io/ip_address"]
38+
value: "10.77.7.5"
39+
40+
- it: omits the annotation when no address is requested
41+
set:
42+
networks:
43+
- name: subnet-a
44+
documentSelector:
45+
path: kind
46+
value: VirtualMachine
47+
asserts:
48+
- notExists:
49+
path: spec.template.metadata.annotations["subnet-a.tenant-test.ovn.kubernetes.io/ip_address"]
50+
51+
- it: annotates only the interfaces that ask for an address
52+
set:
53+
networks:
54+
- name: subnet-a
55+
ipAddress: 10.77.7.5
56+
- name: subnet-b
57+
documentSelector:
58+
path: kind
59+
value: VirtualMachine
60+
asserts:
61+
- equal:
62+
path: spec.template.metadata.annotations["subnet-a.tenant-test.ovn.kubernetes.io/ip_address"]
63+
value: "10.77.7.5"
64+
- notExists:
65+
path: spec.template.metadata.annotations["subnet-b.tenant-test.ovn.kubernetes.io/ip_address"]
66+
67+
# `subnets` is the deprecated alias of `networks` and shares its type, so it gains the
68+
# field too. It resolves to the same variable, and this pins that it keeps doing so.
69+
- it: honours the address through the deprecated subnets alias
70+
set:
71+
subnets:
72+
- name: subnet-a
73+
ipAddress: 10.77.7.9
74+
documentSelector:
75+
path: kind
76+
value: VirtualMachine
77+
asserts:
78+
- equal:
79+
path: spec.template.metadata.annotations["subnet-a.tenant-test.ovn.kubernetes.io/ip_address"]
80+
value: "10.77.7.9"

‎packages/apps/vm-instance/values.schema.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@
9090
"items": {
9191
"type": "object",
9292
"properties": {
93+
"ipAddress": {
94+
"description": "Static IPv4 address for this interface. Empty lets kube-ovn IPAM allocate one. The address must belong to the subnet CIDR; kube-ovn rejects one outside it.",
95+
"type": "string"
96+
},
9397
"name": {
9498
"description": "Network attachment name.",
9599
"type": "string",
@@ -107,6 +111,10 @@
107111
"items": {
108112
"type": "object",
109113
"properties": {
114+
"ipAddress": {
115+
"description": "Static IPv4 address for this interface. Empty lets kube-ovn IPAM allocate one. The address must belong to the subnet CIDR; kube-ovn rejects one outside it.",
116+
"type": "string"
117+
},
110118
"name": {
111119
"description": "Network attachment name.",
112120
"type": "string",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
## @typedef {struct} Network - Network to attach the VM to.
1515
## @field {string} [name] - Network attachment name.
1616
## @x-cozystack-options {source: network}
17+
## @field {string} [ipAddress] - Static IPv4 address for this interface. Empty lets kube-ovn IPAM allocate one. The address must belong to the subnet CIDR; kube-ovn rejects one outside it.
1718

1819
## @typedef {struct} GPU - GPU device configuration.
1920
## @field {string} name - The name of the GPU resource to attach.

0 commit comments

Comments
 (0)