apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachine
metadata:
  name: {{ include "virtual-machine.fullname" . }}
  labels:
    {{- include "virtual-machine.labels" . | nindent 4 }}
spec:
  running: true
  dataVolumeTemplates:
  - metadata:
      name: {{ include "virtual-machine.fullname" . }}
    spec:
      pvc:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: {{ .Values.disk | quote }}
        storageClassName: replicated
      source:
        http:
          {{- if eq .Values.image "cirros" }}
          url: https://download.cirros-cloud.net/0.6.2/cirros-0.6.2-x86_64-disk.img
          {{- else if eq .Values.image "ubuntu" }}
          url: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img
          {{- else if eq .Values.image "fedora" }}
          url: https://mirror.karneval.cz/pub/linux/fedora/linux/releases/39/Cloud/x86_64/images/Fedora-Cloud-Base-39-1.5.x86_64.qcow2
          {{- else if eq .Values.image "alpine" }}
          url: https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-virt-3.19.1-x86_64.iso
          {{- end }}

  template:
    metadata:
      annotations:
        kubevirt.io/allow-pod-bridge-network-live-migration: "true"
      labels:
        {{- include "virtual-machine.labels" . | nindent 8 }}
    spec:
      domain:
        cpu:
          cores: {{ .Values.resources.cpu }}
        devices:
          disks:
          - disk:
              bus: scsi
            name: systemdisk
          - disk:
              bus: virtio
            name: cloudinitdisk
        machine:
          type: ""
        resources:
          requests:
            memory: {{ .Values.resources.memory | quote }}
      terminationGracePeriodSeconds: 30
      volumes:
      - dataVolume:
          name: {{ include "virtual-machine.fullname" . }}
        name: systemdisk
      - cloudInitNoCloud:
          userData: |-
            #cloud-config
            password: {{ .Values.password }}
            chpasswd: { expire: False }
        name: cloudinitdisk
