From f1f9d89d47c543c92f129bdbbda45e344e843b63 Mon Sep 17 00:00:00 2001 From: "Michael N. Lipp" Date: Sat, 10 Jun 2023 15:26:54 +0200 Subject: [PATCH] Helm chart for testing. --- .../helm-test/.helmignore | 23 ++++ .../helm-test/Chart.yaml | 7 ++ .../helm-test/README.md | 4 + .../helm-test/templates/_helpers.tpl | 0 .../helm-test/templates/etcConfig.yaml | 115 ++++++++++++++++++ .../helm-test/templates/pod.yml | 60 +++++++++ .../helm-test/templates/pv.yaml | 28 +++++ .../helm-test/templates/pvc.yaml | 17 +++ .../helm-test/values.yaml | 28 +++++ 9 files changed, 282 insertions(+) create mode 100644 org.jdrupes.vmoperator.runner.qemu/helm-test/.helmignore create mode 100644 org.jdrupes.vmoperator.runner.qemu/helm-test/Chart.yaml create mode 100644 org.jdrupes.vmoperator.runner.qemu/helm-test/README.md create mode 100644 org.jdrupes.vmoperator.runner.qemu/helm-test/templates/_helpers.tpl create mode 100644 org.jdrupes.vmoperator.runner.qemu/helm-test/templates/etcConfig.yaml create mode 100644 org.jdrupes.vmoperator.runner.qemu/helm-test/templates/pod.yml create mode 100644 org.jdrupes.vmoperator.runner.qemu/helm-test/templates/pv.yaml create mode 100644 org.jdrupes.vmoperator.runner.qemu/helm-test/templates/pvc.yaml create mode 100644 org.jdrupes.vmoperator.runner.qemu/helm-test/values.yaml diff --git a/org.jdrupes.vmoperator.runner.qemu/helm-test/.helmignore b/org.jdrupes.vmoperator.runner.qemu/helm-test/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/org.jdrupes.vmoperator.runner.qemu/helm-test/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/org.jdrupes.vmoperator.runner.qemu/helm-test/Chart.yaml b/org.jdrupes.vmoperator.runner.qemu/helm-test/Chart.yaml new file mode 100644 index 0000000..fe44901 --- /dev/null +++ b/org.jdrupes.vmoperator.runner.qemu/helm-test/Chart.yaml @@ -0,0 +1,7 @@ +apiVersion: v2 +name: vmrunner-qemu-test +description: Create a vmrunner controlled qemu VM (from fixed resources) +type: application + +# This is the chart version. +version: "1.0.0" diff --git a/org.jdrupes.vmoperator.runner.qemu/helm-test/README.md b/org.jdrupes.vmoperator.runner.qemu/helm-test/README.md new file mode 100644 index 0000000..1e6b687 --- /dev/null +++ b/org.jdrupes.vmoperator.runner.qemu/helm-test/README.md @@ -0,0 +1,4 @@ +# Helm chart for deploying VM + +Used for testing the runner. Generates the requires Kubernetes objects +using helm. diff --git a/org.jdrupes.vmoperator.runner.qemu/helm-test/templates/_helpers.tpl b/org.jdrupes.vmoperator.runner.qemu/helm-test/templates/_helpers.tpl new file mode 100644 index 0000000..e69de29 diff --git a/org.jdrupes.vmoperator.runner.qemu/helm-test/templates/etcConfig.yaml b/org.jdrupes.vmoperator.runner.qemu/helm-test/templates/etcConfig.yaml new file mode 100644 index 0000000..2c2ef06 --- /dev/null +++ b/org.jdrupes.vmoperator.runner.qemu/helm-test/templates/etcConfig.yaml @@ -0,0 +1,115 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: {{ .Release.Namespace }} + name: {{ .Release.Name }} +data: + config.yaml: | + "/Runner": + # The directory used to store data files. Defaults to (depending on + # values available): + # * $XDG_DATA_HOME/vmrunner/${vm.name} + # * $HOME/.local/share/vmrunner/${vm.name} + # * ./${vm.name} + "dataDir": "/var/local/vm-data" + + # The directory used to store runtime files. Defaults to (depending on + # values available): + # * $XDG_RUNTIME_DIR/vmrunner/${vm.name} + # * /tmp/${USER}/vmrunner/${vm.name} + # * /tmp/vmrunner/${vm.name} + # "runtimeDir": "$XDG_RUNTIME_DIR/vmrunner/${vm.name}" + + # The template to use. Resolved relative to /usr/share/vmrunner/templates. + # "template": "Standard-VM-latest.ftl.yaml" + + # The template is copied to the data diretory when the VM starts for + # the first time. Subsequent starts use the copy unless this option is set. + "updateTemplate": true + + # Define the VM (required) + "vm": + # The VM's name (required) + "name": "{{ .Release.Name }}" + + # The machine's uuid. If none is specified, a uuid is generated + # and stored in the data directory. If the uuid is important + # (e.g. because licenses depend on it) it is recommaned to specify + # it here explicitly or to carefully backup the data directory. + {{- if hasKey .Values.vm "machineUuid" }} + "uuid": "{{ .Values.vm.machineUuid }}" + {{- end }} + + # Whether to provide a software TPM (defaults to false) + "useTpm": {{ .Values.vm.useTpm }} + + # How to boot (see https://github.com/mnlipp/VM-Operator/blob/main/org.jdrupes.vmoperator.runner.qemu/resources/org/jdrupes/vmoperator/runner/qemu/defaults.yaml): + # * bios + # * uefi[-4m] + # * secure[-4m] + "firmware": "{{ .Values.vm.firmware }}" + + # When terminating, a graceful powerdown is attempted. If it + # doesn't succeed within the given timeout (seconds) SIGTERM + # is sent to Qemu. + "powerdownTimeout": "{{ .Values.vm.powerdownTimeout }}" + + # RAM settings + "maximumRam": "{{ .Values.vm.maximumMemory }}" + # "currentRam": "1G" + + # CPU settings + "cpuModel": "{{ .Values.vm.cpuModel }}" + # Setting maximumCpus to 1 omits the "-smp" options. The defaults (0) + # cause the corresponding property to be omitted from the "-smp" option. + # If currentCpus is greater than maximumCpus, the latter is adjusted. + "maximumCpus": {{ .Values.vm.maximumCpus }} + "currentCpus": {{ .Values.vm.currentCpus }} + # "cpuSockets": 0 + # "diesPerSocket": 0 + # "coresPerSocket": 0 + # "threadsPerCore": 0 + # "accelertor": "kvm" + + # RTC settings. + "rtcBase": "{{ .Values.vm.rtcBase }}" + # "rtcClock": "rt" + + # Network settings + # Supported types are "tap" and "user" (for debugging). Type "user" + # supports only the property "net". + # "network": + # - "type": "tap" + # "bridge": "br0" + # "device": "virtio-net" + # "mac": (undefined) + "network": + {{- range $index, $network := .Values.vm.networks }} + {{- if hasKey $network "bridge" }} + - "type": "tap" + {{- if hasKey $network.bridge "name" }} + "bridge": "{{ $network.bridge.name }}" + {{- end }} + {{- if hasKey $network.bridge "mac" }} + "mac": "{{ $network.bridge.mac }}" + {{- end }} + {{- end }} + {{- end }} + + # There are no default drives. The supported types are "ide-cd" + # and "raw". All types support a "bootindex" property. + # Type "raw" can have a property "file" (if backed by a file on + # the host) or a property "device" (if backed by a device). + # "drives": + # - "type": "ide-cd" + # "bootindex": (undefined) + # "file": (undefined) + "drives": + {{- range $index, $disk := .Values.vm.disks }} + - "type": "raw" + "device": "/dev/disk-{{ $index }}" + {{- end }} + + "spice": + "port": {{ .Values.vm.spicePort }} + # "usbRedirects": 2 diff --git a/org.jdrupes.vmoperator.runner.qemu/helm-test/templates/pod.yml b/org.jdrupes.vmoperator.runner.qemu/helm-test/templates/pod.yml new file mode 100644 index 0000000..9fbff9a --- /dev/null +++ b/org.jdrupes.vmoperator.runner.qemu/helm-test/templates/pod.yml @@ -0,0 +1,60 @@ +kind: Pod +apiVersion: v1 +metadata: + namespace: {{ .Release.Namespace }} + name: {{ .Release.Name }} + labels: + app: qemu-vm + vm: {{ .Release.Name }} +spec: + containers: + - name: {{ .Release.Name }} + image: {{ .Values.image.repository }}/{{ .Values.image.path }}:{{ .Values.image.version }} + resources: {} + imagePullPolicy: {{ .Values.image.pullPolicy }} + volumeMounts: + # Not needed because pod is priviledged: + # - mountPath: /dev/kvm + # name: dev-kvm + # - mountPath: /dev/net/tun + # name: dev-tun + # - mountPath: /sys/fs/cgroup + # name: cgroup + - mountPath: /etc/opt/vmrunner + name: config + - mountPath: /var/local/vm-data + name: vm-data + volumeDevices: + {{- range $index, $disk := .Values.vm.disks }} + - devicePath: /dev/disk-{{ $index }} + name: disk-{{ $index }} + {{- end }} + securityContext: + privileged: true + volumes: + # Not needed because pod is priviledged: + # - name: dev-kvm + # hostPath: + # path: /dev/kvm + # type: CharDevice + # - hostPath: + # path: /dev/net/tun + # type: CharDevice + # name: dev-tun + # - name: cgroup + # hostPath: + # path: /sys/fs/cgroup + - name: config + configMap: + name: {{ $.Release.Name }} + - name: vm-data + hostPath: + path: /var/local/vmrunner/{{ .Release.Name }} + {{- range $index, $disk := .Values.vm.disks }} + - name: disk-{{ $index }} + persistentVolumeClaim: + claimName: {{ $.Release.Name }}-pvc-{{ $index }} + {{- end }} + hostNetwork: true + terminationGracePeriodSeconds: 60 + restartPolicy: Never diff --git a/org.jdrupes.vmoperator.runner.qemu/helm-test/templates/pv.yaml b/org.jdrupes.vmoperator.runner.qemu/helm-test/templates/pv.yaml new file mode 100644 index 0000000..093d3dc --- /dev/null +++ b/org.jdrupes.vmoperator.runner.qemu/helm-test/templates/pv.yaml @@ -0,0 +1,28 @@ +{{- range $index, $disk := .Values.vm.disks }} +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: {{ $.Release.Name }}-pv-{{ $index }} +spec: + capacity: + storage: {{ .size }} + volumeMode: Block + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Retain + storageClassName: "" + claimRef: + name: {{ $.Release.Name }}-pvc-{{ $index }} + namespace: {{ $.Release.Namespace }} + local: + path: {{ .device }} + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - {{ required "Valid .Values.vm.host entry required" $.Values.vm.host }} +{{- end }} \ No newline at end of file diff --git a/org.jdrupes.vmoperator.runner.qemu/helm-test/templates/pvc.yaml b/org.jdrupes.vmoperator.runner.qemu/helm-test/templates/pvc.yaml new file mode 100644 index 0000000..e91da99 --- /dev/null +++ b/org.jdrupes.vmoperator.runner.qemu/helm-test/templates/pvc.yaml @@ -0,0 +1,17 @@ +{{- range $index, $disk := .Values.vm.disks }} +--- +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + namespace: {{ $.Release.Namespace }} + name: {{ $.Release.Name }}-pvc-{{ $index }} +spec: + accessModes: + - ReadWriteOnce + storageClassName: "" + volumeMode: Block + resources: + requests: + storage: {{ .size }} +{{- end }} + diff --git a/org.jdrupes.vmoperator.runner.qemu/helm-test/values.yaml b/org.jdrupes.vmoperator.runner.qemu/helm-test/values.yaml new file mode 100644 index 0000000..45dfeec --- /dev/null +++ b/org.jdrupes.vmoperator.runner.qemu/helm-test/values.yaml @@ -0,0 +1,28 @@ +# Default values for vmrunner helm test. + +image: + repository: docker-registry.domain.com + path: vmoperator/org.jdrupes.vmoperator.runner.qemu + version: latest + pullPolicy: IfNotPresent + +vm: + # machineUuid: "No default" + # host: "No default" + useTpm: false + firmware: "uefi" + cpuModel: "host" + maximumCpus: 4 + currentCpus: 2 + maximumMemory: "1G" + # currentMemory: "Optional" + rtcBase: "utc" + spicePort: 5901 + disks: + - device: /dev/vg/lv + size: 40Gi + networks: + - bridge: {} + # name: br0 + # mac: "Optional" + powerdownTimeout: 60 \ No newline at end of file