mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-22 12:43:32 +09:00
## What this PR does Guards the Kube-OVN `IP` lookup behind API discovery. The `vm-instance` chart now renders on clusters using another CNI instead of trying to query a CRD that is not installed. The Helm regression suite mocks the IP object through `kubernetesProvider` and pins both sides: with `kubeovn.io/v1/IP` advertised the annotations carry the mocked MAC and IP, without it they are absent even though the object exists, which is the branch the guard adds. 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. Open PRs #3991, #3978, #3931, and #3900 touch the same template. Their current hunks do not alter this lookup; #3900 adds secondary-interface annotations immediately after it, so it is the only nearby merge hunk to watch. ### Screenshots Not applicable; there is no UI change. ### Downstream repositories - [x] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: ### Release note ```release-note fix(virtual-machine): render VM instances on clusters where the Kube-OVN IP API is not installed. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * VM instances now render correctly in environments without the Kube-OVN IP capability. * OVN IP lookups and MAC/IP annotations are only generated when the required Kube-OVN API is available. * MAC/IP annotations are omitted when the capability is unavailable, even if an IP object exists. * **Tests** * Added coverage for both supported and unsupported Kube-OVN IP discovery scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
159 lines
6.3 KiB
YAML
159 lines
6.3 KiB
YAML
{{- /* The effective type, not the raw value: once complete resources size the
|
|
VM the matcher is gone, and a stale or misspelled instanceType that the
|
|
dashboard gives no way to clear must not fail a render that never
|
|
references it. */}}
|
|
{{- $instanceType := include "virtual-machine.effectiveInstanceType" . }}
|
|
{{- if and $instanceType (not (lookup "instancetype.kubevirt.io/v1beta1" "VirtualMachineClusterInstancetype" "" $instanceType)) }}
|
|
{{- fail (printf "Specified instanceType does not exist in the cluster: %s" $instanceType) }}
|
|
{{- end }}
|
|
{{- if and .Values.instanceProfile (not (lookup "instancetype.kubevirt.io/v1beta1" "VirtualMachineClusterPreference" "" .Values.instanceProfile)) }}
|
|
{{- fail (printf "Specified instanceProfile does not exist in the cluster: %s" .Values.instanceProfile) }}
|
|
{{- end }}
|
|
{{- /* Raw values here, deliberately. This gate asks whether the user supplied
|
|
a sizing source at all, which is a question about their input; every
|
|
other read asks what gets rendered, which is a question about the
|
|
output. The raw instanceType and the effective one cannot disagree on
|
|
this gate's outcome -- a truthy raw value with an empty effective one
|
|
means the resources are complete, so the VM is sized either way -- but
|
|
swapping this one to $instanceType would quietly change what it means. */}}
|
|
{{- if and (not .Values.instanceType) (not (and .Values.resources .Values.resources.cpu .Values.resources.sockets .Values.resources.memory)) }}
|
|
{{- fail "Either instanceType or resources (cpu, sockets, memory) must be specified" }}
|
|
{{- end }}
|
|
{{- $networks := .Values.networks | default .Values.subnets }}
|
|
|
|
apiVersion: kubevirt.io/v1
|
|
kind: VirtualMachine
|
|
metadata:
|
|
name: {{ include "virtual-machine.fullname" . }}
|
|
labels:
|
|
{{- include "virtual-machine.labels" . | nindent 4 }}
|
|
spec:
|
|
{{- if hasKey .Values "runStrategy" }}
|
|
runStrategy: {{ .Values.runStrategy }}
|
|
{{- else }}
|
|
runStrategy: {{ ternary "Always" "Halted" (.Values.running | default true) }}
|
|
{{- end }}
|
|
{{- with $instanceType }}
|
|
instancetype:
|
|
kind: VirtualMachineClusterInstancetype
|
|
name: {{ . }}
|
|
{{- end }}
|
|
{{- with .Values.instanceProfile }}
|
|
preference:
|
|
kind: VirtualMachineClusterPreference
|
|
name: {{ . }}
|
|
{{- end }}
|
|
template:
|
|
metadata:
|
|
annotations:
|
|
kubevirt.io/allow-pod-bridge-network-live-migration: "true"
|
|
{{- if .Capabilities.APIVersions.Has "kubeovn.io/v1/IP" }}
|
|
{{- $ovnIPName := printf "%s.%s" (include "virtual-machine.fullname" .) .Release.Namespace }}
|
|
{{- $ovnIP := lookup "kubeovn.io/v1" "IP" "" $ovnIPName }}
|
|
{{- if $ovnIP }}
|
|
ovn.kubernetes.io/mac_address: {{ $ovnIP.spec.macAddress | quote }}
|
|
ovn.kubernetes.io/ip_address: {{ $ovnIP.spec.ipAddress | quote }}
|
|
{{- end }}
|
|
{{- end }}
|
|
labels:
|
|
{{- include "virtual-machine.labels" . | nindent 8 }}
|
|
spec:
|
|
domain:
|
|
{{- $domainRes := include "virtual-machine.domainResources" . | fromJson -}}
|
|
{{- $fw := .Values.firmware | default dict }}
|
|
{{- with $domainRes.cpu }}
|
|
cpu: {{- . | toYaml | nindent 10 }}
|
|
{{- end }}
|
|
{{- with $domainRes.resources }}
|
|
resources: {{- . | toYaml | nindent 10 }}
|
|
{{- end }}
|
|
firmware:
|
|
uuid: {{ include "virtual-machine.stableUuid" . }}
|
|
{{- if eq (toString $fw.bootloader) "uefi" }}
|
|
bootloader:
|
|
efi:
|
|
secureBoot: {{ $fw.secureBoot | default false }}
|
|
persistent: {{ $fw.efiPersistent | default false }}
|
|
{{- else if eq (toString $fw.bootloader) "bios" }}
|
|
bootloader:
|
|
bios: {}
|
|
{{- end }}
|
|
{{- if and (eq (toString $fw.bootloader) "uefi") ($fw.secureBoot | default false) }}
|
|
features:
|
|
smm:
|
|
enabled: true
|
|
{{- end }}
|
|
devices:
|
|
{{- if .Values.gpus }}
|
|
gpus:
|
|
{{- range $i, $gpu := .Values.gpus }}
|
|
- name: gpu{{ add $i 1 }}
|
|
deviceName: {{ $gpu.name }}
|
|
{{- end }}
|
|
{{- end }}
|
|
disks:
|
|
{{- range $i, $disk := .Values.disks }}
|
|
- name: disk-{{ $disk.name }}
|
|
{{- $dv := lookup "cdi.kubevirt.io/v1beta1" "DataVolume" $.Release.Namespace (printf "vm-disk-%s" $disk.name) }}
|
|
{{- if $dv }}
|
|
{{- $isOptical := and (hasKey $dv.metadata.annotations "vm-disk.cozystack.io/optical") (eq (index $dv.metadata.annotations "vm-disk.cozystack.io/optical") "true") }}
|
|
{{- $deviceKey := ternary "cdrom" "disk" $isOptical }}
|
|
{{- if $disk.bus }}
|
|
{{ $deviceKey }}:
|
|
bus: {{ $disk.bus }}
|
|
{{- else }}
|
|
{{ $deviceKey }}: {}
|
|
{{- end }}
|
|
bootOrder: {{ add $i 1 }}
|
|
{{- else }}
|
|
{{- fail (printf "Specified disk not exists in cluster: %s" .name) }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- if or .Values.cloudInit .Values.sshKeys }}
|
|
- name: cloudinitdisk
|
|
disk: {}
|
|
{{- end }}
|
|
interfaces:
|
|
- name: default
|
|
bridge: {}
|
|
{{- range $i, $net := $networks }}
|
|
- name: {{ $net.name }}
|
|
bridge: {}
|
|
{{- end }}
|
|
machine:
|
|
type: ""
|
|
{{- with .Values.sshKeys }}
|
|
accessCredentials:
|
|
- sshPublicKey:
|
|
source:
|
|
secret:
|
|
secretName: {{ include "virtual-machine.fullname" $ }}-ssh-keys
|
|
propagationMethod:
|
|
# keys will be injected into metadata part of cloud-init disk
|
|
noCloud: {}
|
|
{{- end }}
|
|
terminationGracePeriodSeconds: 30
|
|
|
|
{{- include "virtual-machine.nodeAffinity" . | nindent 6 }}
|
|
|
|
volumes:
|
|
{{- range .Values.disks }}
|
|
- name: disk-{{ .name }}
|
|
dataVolume:
|
|
name: vm-disk-{{ .name }}
|
|
{{- end }}
|
|
{{- if or .Values.cloudInit .Values.sshKeys }}
|
|
- name: cloudinitdisk
|
|
cloudInitNoCloud:
|
|
secretRef:
|
|
name: {{ include "virtual-machine.fullname" . }}-cloud-init
|
|
{{- end }}
|
|
networks:
|
|
- name: default
|
|
pod: {}
|
|
{{- range $i, $net := $networks }}
|
|
- name: {{ $net.name }}
|
|
multus:
|
|
networkName: {{ $.Release.Namespace }}/{{ $net.name }}
|
|
{{- end }}
|