[fix] CloudInit (#1019)

If ssh key provided - deploy
If cloudinit provided - deploy
If ssh key and cloudinit provided - deploy both
If none provided - init empty to avoid issues w/
network

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Refactor**
- Improved handling of SSH keys and cloud-init data in the Virtual
Machine setup, clearly distinguishing cases when SSH keys, cloud-init,
or both are provided.
  - Enhanced template readability with added spacing for better clarity.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
klinch0
2025-06-05 15:53:08 +03:00
committed by GitHub

View File

@@ -13,6 +13,7 @@ metadata:
{{- include "virtual-machine.labels" . | nindent 4 }}
spec:
running: {{ .Values.running | default "true" }}
{{- with .Values.instanceType }}
instancetype:
kind: VirtualMachineClusterInstancetype
@@ -23,6 +24,7 @@ spec:
kind: VirtualMachineClusterPreference
name: {{ . }}
{{- end }}
dataVolumeTemplates:
- metadata:
name: {{ include "virtual-machine.fullname" . }}
@@ -77,21 +79,25 @@ spec:
deviceName: {{ $gpu.name }}
{{- end }}
{{- end }}
disks:
- disk:
bus: scsi
name: systemdisk
{{- if or .Values.sshKeys .Values.cloudInit }}
{{- if .Values.sshKeys }}
- disk:
bus: virtio
name: cloudinitdisk
{{- end }}
interfaces:
- name: default
bridge: {}
machine:
type: ""
{{- with .Values.sshKeys }}
{{- if .Values.sshKeys }}
accessCredentials:
- sshPublicKey:
source:
@@ -101,23 +107,37 @@ spec:
# keys will be injected into metadata part of cloud-init disk
noCloud: {}
{{- end }}
terminationGracePeriodSeconds: 30
volumes:
- name: systemdisk
dataVolume:
name: {{ include "virtual-machine.fullname" . }}
{{- if or .Values.sshKeys .Values.cloudInit }}
- name: cloudinitdisk
cloudInitNoCloud:
{{- if .Values.cloudInit }}
secretRef:
name: {{ include "virtual-machine.fullname" . }}-cloud-init
- name: systemdisk
dataVolume:
name: {{ include "virtual-machine.fullname" . }}
{{- if and .Values.sshKeys .Values.cloudInit }}
- name: cloudinitdisk
cloudInitNoCloud:
secretRef:
name: {{ include "virtual-machine.fullname" . }}-cloud-init
{{- else if .Values.sshKeys }}
- name: cloudinitdisk
cloudInitNoCloud:
userData: |
{{ printf "%s" "#cloud-config" }}
ssh_authorized_keys:
{{- range .Values.sshKeys }}
- {{ . }}
{{- end }}
chpasswd:
expire: false
{{- else }}
userData: |
#cloud-config
final_message: Cloud-init user-data was left blank intentionally.
- name: cloudinitdisk
cloudInitNoCloud:
userData: |
{{ printf "%s" "#cloud-config" }}
{{- end }}
{{- end }}
networks:
- name: default
pod: {}