Skip to content

Commit b142d27

Browse files
committed
fix(virtual-machine): guard Kube-OVN IP lookup
Helm's `lookup` propagates the discovery error when the requested API group is not served, so the vm-instance chart could not render at all on clusters without the Kube-OVN CRDs. Gate the IP lookup behind `.Capabilities.APIVersions.Has "kubeovn.io/v1/IP"`. The regression suite mocks the IP object through kubernetesProvider and pins both sides: with the API advertised the annotations carry the mocked MAC and IP, without it they are absent even though the object exists. helm-unittest's fake lookup never errors on an unserved kind, so only the second case distinguishes the guard; it fails on main and passes here. Assisted-By: GPT-5 <[email protected]> Signed-off-by: Loïc Fontaine <[email protected]>
1 parent dc2e427 commit b142d27

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ spec:
3535
metadata:
3636
annotations:
3737
kubevirt.io/allow-pod-bridge-network-live-migration: "true"
38+
{{- if .Capabilities.APIVersions.Has "kubeovn.io/v1/IP" }}
3839
{{- $ovnIPName := printf "%s.%s" (include "virtual-machine.fullname" .) .Release.Namespace }}
3940
{{- $ovnIP := lookup "kubeovn.io/v1" "IP" "" $ovnIPName }}
4041
{{- if $ovnIP }}
4142
ovn.kubernetes.io/mac_address: {{ $ovnIP.spec.macAddress | quote }}
4243
ovn.kubernetes.io/ip_address: {{ $ovnIP.spec.ipAddress | quote }}
4344
{{- end }}
45+
{{- end }}
4446
labels:
4547
{{- include "virtual-machine.labels" . | nindent 8 }}
4648
spec:
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
suite: vm-instance Kube-OVN IP pinning follows API discovery
2+
3+
# On a live cluster Helm's `lookup` propagates the discovery error when the
4+
# requested API group is not served, so the chart could not render at all
5+
# without the Kube-OVN CRDs. helm-unittest's fake lookup never errors: it just
6+
# returns nothing for an unserved kind, so an IP object is mocked here to pin
7+
# both sides. With the API advertised the annotations must carry the mocked
8+
# values; with the API absent they must be missing even though the object
9+
# exists, which is the branch the discovery guard adds.
10+
release:
11+
name: test-vm
12+
namespace: tenant-test
13+
templates:
14+
- templates/vm.yaml
15+
set:
16+
fullnameOverride: test-vm
17+
instanceType: ""
18+
instanceProfile: ""
19+
resources:
20+
cpu: 1
21+
sockets: 1
22+
memory: 1Gi
23+
_cluster:
24+
scheduling:
25+
dedicatedNodesForWindowsVMs: "false"
26+
kubernetesProvider:
27+
scheme:
28+
"kubeovn.io/v1/IP":
29+
gvr:
30+
group: kubeovn.io
31+
version: v1
32+
resource: ips
33+
namespaced: false
34+
objects:
35+
- apiVersion: kubeovn.io/v1
36+
kind: IP
37+
metadata:
38+
name: test-vm.tenant-test
39+
spec:
40+
macAddress: "00:00:5E:00:53:01"
41+
ipAddress: "192.0.2.10"
42+
tests:
43+
- it: pins the Kube-OVN IP and MAC when the IP API is served
44+
capabilities:
45+
apiVersions:
46+
- kubeovn.io/v1/IP
47+
asserts:
48+
- equal:
49+
path: spec.template.metadata.annotations["ovn.kubernetes.io/mac_address"]
50+
value: "00:00:5E:00:53:01"
51+
- equal:
52+
path: spec.template.metadata.annotations["ovn.kubernetes.io/ip_address"]
53+
value: "192.0.2.10"
54+
- it: skips the lookup when the IP API is not served, even if an IP object exists
55+
capabilities:
56+
apiVersions: []
57+
asserts:
58+
- notExists:
59+
path: spec.template.metadata.annotations["ovn.kubernetes.io/mac_address"]
60+
- notExists:
61+
path: spec.template.metadata.annotations["ovn.kubernetes.io/ip_address"]

0 commit comments

Comments
 (0)