After migration 36 copies subnets to networks, both fields are populated. The fail guard would break Helm reconciliation. Instead, networks simply takes priority via the existing default fallback. Also handle missing VMInstance CRD gracefully in migration 36. Assisted-By: Claude AI Signed-off-by: Kirill Ilin <stitch14@yandex.ru>
129 lines
4.7 KiB
YAML
129 lines
4.7 KiB
YAML
{{- if and .Values.instanceType (not (lookup "instancetype.kubevirt.io/v1beta1" "VirtualMachineClusterInstancetype" "" .Values.instanceType)) }}
|
|
{{- fail (printf "Specified instanceType does not exist in the cluster: %s" .Values.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 }}
|
|
{{- 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 .Values.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"
|
|
{{- $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 }}
|
|
labels:
|
|
{{- include "virtual-machine.labels" . | nindent 8 }}
|
|
spec:
|
|
domain:
|
|
{{- $domainRes := include "virtual-machine.domainResources" . | fromJson -}}
|
|
{{- with $domainRes.cpu }}
|
|
cpu: {{- . | toYaml | nindent 10 }}
|
|
{{- end }}
|
|
{{- with $domainRes.resources }}
|
|
resources: {{- . | toYaml | nindent 10 }}
|
|
{{- end }}
|
|
firmware:
|
|
uuid: {{ include "virtual-machine.stableUuid" . }}
|
|
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 }}
|
|
{{- if and (hasKey $dv.metadata.annotations "vm-disk.cozystack.io/optical") (eq (index $dv.metadata.annotations "vm-disk.cozystack.io/optical") "true") }}
|
|
cdrom:
|
|
{{- else }}
|
|
disk:
|
|
{{- end }}
|
|
{{- with $disk.bus }}
|
|
bus: {{ . }}
|
|
{{- 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 }}
|