From 991c7e1943600c106819f205c2db56ccd2b1dba3 Mon Sep 17 00:00:00 2001 From: Denis Seleznev Date: Thu, 10 Apr 2025 10:07:40 +0200 Subject: [PATCH] Handle empty cloudInit. Add a no-op user-data when sshKeys are specified. Signed-off-by: Denis Seleznev --- packages/apps/virtual-machine/README.md | 35 +++++++++---------- .../apps/virtual-machine/templates/vm.yaml | 7 ++++ .../apps/virtual-machine/values.schema.json | 4 +-- packages/apps/virtual-machine/values.yaml | 5 ++- packages/apps/vm-instance/README.md | 31 ++++++++-------- packages/apps/vm-instance/templates/vm.yaml | 11 ++++-- packages/apps/vm-instance/values.schema.json | 4 +-- packages/apps/vm-instance/values.yaml | 5 ++- 8 files changed, 56 insertions(+), 46 deletions(-) diff --git a/packages/apps/virtual-machine/README.md b/packages/apps/virtual-machine/README.md index 14593edc..bb33570b 100644 --- a/packages/apps/virtual-machine/README.md +++ b/packages/apps/virtual-machine/README.md @@ -36,24 +36,23 @@ virtctl ssh @ ### Common parameters -| Name | Description | Value | -| ------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------- | -| `external` | Enable external access from outside the cluster | `false` | -| `externalMethod` | specify method to passthrough the traffic to the virtual machine. Allowed values: `WholeIP` and `PortList` | `WholeIP` | -| `externalPorts` | Specify ports to forward from outside the cluster | `[]` | -| `running` | Determines if the virtual machine should be running | `true` | -| `instanceType` | Virtual Machine instance type | `u1.medium` | -| `instanceProfile` | Virtual Machine prefferences profile | `ubuntu` | -| `systemDisk.image` | The base image for the virtual machine. Allowed values: `ubuntu`, `cirros`, `alpine`, `fedora` and `talos` | `ubuntu` | -| `systemDisk.storage` | The size of the disk allocated for the virtual machine | `5Gi` | -| `systemDisk.storageClass` | StorageClass used to store the data | `replicated` | -| `gpus` | List of GPUs to attach | `[]` | -| `resources.cpu` | The number of CPU cores allocated to the virtual machine | `""` | -| `resources.memory` | The amount of memory allocated to the virtual machine | `""` | -| `sshKeys` | List of SSH public keys for authentication. Can be a single key or a list of keys. | `[]` | -| `cloudInit` | cloud-init user data config. See cloud-init documentation for more details. | `#cloud-config -` | -| `cloudInitSeed` | A seed string to generate an SMBIOS UUID for the VM. | `""` | +| Name | Description | Value | +| ------------------------- | ---------------------------------------------------------------------------------------------------------- | ------------ | +| `external` | Enable external access from outside the cluster | `false` | +| `externalMethod` | specify method to passthrough the traffic to the virtual machine. Allowed values: `WholeIP` and `PortList` | `WholeIP` | +| `externalPorts` | Specify ports to forward from outside the cluster | `[]` | +| `running` | Determines if the virtual machine should be running | `true` | +| `instanceType` | Virtual Machine instance type | `u1.medium` | +| `instanceProfile` | Virtual Machine preferences profile | `ubuntu` | +| `systemDisk.image` | The base image for the virtual machine. Allowed values: `ubuntu`, `cirros`, `alpine`, `fedora` and `talos` | `ubuntu` | +| `systemDisk.storage` | The size of the disk allocated for the virtual machine | `5Gi` | +| `systemDisk.storageClass` | StorageClass used to store the data | `replicated` | +| `gpus` | List of GPUs to attach | `[]` | +| `resources.cpu` | The number of CPU cores allocated to the virtual machine | `""` | +| `resources.memory` | The amount of memory allocated to the virtual machine | `""` | +| `sshKeys` | List of SSH public keys for authentication. Can be a single key or a list of keys. | `[]` | +| `cloudInit` | cloud-init user data config. See cloud-init documentation for more details. | `""` | +| `cloudInitSeed` | A seed string to generate an SMBIOS UUID for the VM. | `""` | ## U Series diff --git a/packages/apps/virtual-machine/templates/vm.yaml b/packages/apps/virtual-machine/templates/vm.yaml index 3681abd8..67f192e7 100644 --- a/packages/apps/virtual-machine/templates/vm.yaml +++ b/packages/apps/virtual-machine/templates/vm.yaml @@ -98,6 +98,7 @@ spec: secret: secretName: {{ include "virtual-machine.fullname" $ }}-ssh-keys propagationMethod: + # keys will be injected into metadata part of cloud-init disk noCloud: {} {{- end }} terminationGracePeriodSeconds: 30 @@ -108,8 +109,14 @@ spec: {{- if or .Values.sshKeys .Values.cloudInit }} - name: cloudinitdisk cloudInitNoCloud: + {{- if .Values.cloudInit }} secretRef: name: {{ include "virtual-machine.fullname" . }}-cloud-init + {{- else }} + userData: | + #cloud-config + final_message: Cloud-init user-data was left blank intentionally. + {{- end }} {{- end }} networks: - name: default diff --git a/packages/apps/virtual-machine/values.schema.json b/packages/apps/virtual-machine/values.schema.json index b94e5f6a..861d4da4 100644 --- a/packages/apps/virtual-machine/values.schema.json +++ b/packages/apps/virtual-machine/values.schema.json @@ -88,7 +88,7 @@ }, "instanceProfile": { "type": "string", - "description": "Virtual Machine prefferences profile", + "description": "Virtual Machine preferences profile", "default": "ubuntu", "optional": true, "enum": [ @@ -198,7 +198,7 @@ "cloudInit": { "type": "string", "description": "cloud-init user data config. See cloud-init documentation for more details.", - "default": "#cloud-config\n" + "default": "" }, "cloudInitSeed": { "type": "string", diff --git a/packages/apps/virtual-machine/values.yaml b/packages/apps/virtual-machine/values.yaml index 78b845db..6cccbad1 100644 --- a/packages/apps/virtual-machine/values.yaml +++ b/packages/apps/virtual-machine/values.yaml @@ -12,7 +12,7 @@ externalPorts: running: true ## @param instanceType Virtual Machine instance type -## @param instanceProfile Virtual Machine prefferences profile +## @param instanceProfile Virtual Machine preferences profile ## instanceType: "u1.medium" instanceProfile: ubuntu @@ -55,8 +55,7 @@ sshKeys: [] ## password: ubuntu ## chpasswd: { expire: False } ## -cloudInit: | - #cloud-config +cloudInit: "" ## @param cloudInitSeed A seed string to generate an SMBIOS UUID for the VM. cloudInitSeed: "" diff --git a/packages/apps/vm-instance/README.md b/packages/apps/vm-instance/README.md index 031bec7c..273c1f15 100644 --- a/packages/apps/vm-instance/README.md +++ b/packages/apps/vm-instance/README.md @@ -36,22 +36,21 @@ virtctl ssh @ ### Common parameters -| Name | Description | Value | -| ------------------ | ---------------------------------------------------------------------------------------------------------- | ---------------- | -| `external` | Enable external access from outside the cluster | `false` | -| `externalMethod` | specify method to passthrough the traffic to the virtual machine. Allowed values: `WholeIP` and `PortList` | `WholeIP` | -| `externalPorts` | Specify ports to forward from outside the cluster | `[]` | -| `running` | Determines if the virtual machine should be running | `true` | -| `instanceType` | Virtual Machine instance type | `u1.medium` | -| `instanceProfile` | Virtual Machine prefferences profile | `ubuntu` | -| `disks` | List of disks to attach | `[]` | -| `gpus` | List of GPUs to attach | `[]` | -| `resources.cpu` | The number of CPU cores allocated to the virtual machine | `""` | -| `resources.memory` | The amount of memory allocated to the virtual machine | `""` | -| `sshKeys` | List of SSH public keys for authentication. Can be a single key or a list of keys. | `[]` | -| `cloudInit` | cloud-init user data config. See cloud-init documentation for more details. | `#cloud-config -` | -| `cloudInitSeed` | A seed string to generate an SMBIOS UUID for the VM. | `""` | +| Name | Description | Value | +| ------------------ | ---------------------------------------------------------------------------------------------------------- | ----------- | +| `external` | Enable external access from outside the cluster | `false` | +| `externalMethod` | specify method to passthrough the traffic to the virtual machine. Allowed values: `WholeIP` and `PortList` | `WholeIP` | +| `externalPorts` | Specify ports to forward from outside the cluster | `[]` | +| `running` | Determines if the virtual machine should be running | `true` | +| `instanceType` | Virtual Machine instance type | `u1.medium` | +| `instanceProfile` | Virtual Machine preferences profile | `ubuntu` | +| `disks` | List of disks to attach | `[]` | +| `gpus` | List of GPUs to attach | `[]` | +| `resources.cpu` | The number of CPU cores allocated to the virtual machine | `""` | +| `resources.memory` | The amount of memory allocated to the virtual machine | `""` | +| `sshKeys` | List of SSH public keys for authentication. Can be a single key or a list of keys. | `[]` | +| `cloudInit` | cloud-init user data config. See cloud-init documentation for more details. | `""` | +| `cloudInitSeed` | A seed string to generate an SMBIOS UUID for the VM. | `""` | ## U Series diff --git a/packages/apps/vm-instance/templates/vm.yaml b/packages/apps/vm-instance/templates/vm.yaml index 30e8cd18..4a8ed2a4 100644 --- a/packages/apps/vm-instance/templates/vm.yaml +++ b/packages/apps/vm-instance/templates/vm.yaml @@ -1,8 +1,8 @@ {{- if and .Values.instanceType (not (lookup "instancetype.kubevirt.io/v1beta1" "VirtualMachineClusterInstancetype" "" .Values.instanceType)) }} -{{- fail (printf "Specified instancetype not exists in cluster: %s" .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 profile not exists in cluster: %s" .Values.instanceProfile) }} +{{- fail (printf "Specified instanceProfile does not exist in the cluster: %s" .Values.instanceProfile) }} {{- end }} apiVersion: kubevirt.io/v1 @@ -83,6 +83,7 @@ spec: secret: secretName: {{ include "virtual-machine.fullname" $ }}-ssh-keys propagationMethod: + # keys will be injected into metadata part of cloud-init disk noCloud: {} {{- end }} terminationGracePeriodSeconds: 30 @@ -95,8 +96,14 @@ spec: {{- if or .Values.sshKeys .Values.cloudInit }} - name: cloudinitdisk cloudInitNoCloud: + {{- if .Values.cloudInit }} secretRef: name: {{ include "virtual-machine.fullname" . }}-cloud-init + {{- else }} + userData: | + #cloud-config + final_message: Cloud-init user-data was left blank intentionally. + {{- end }} {{- end }} networks: - name: default diff --git a/packages/apps/vm-instance/values.schema.json b/packages/apps/vm-instance/values.schema.json index 1edfaa66..f4dd2076 100644 --- a/packages/apps/vm-instance/values.schema.json +++ b/packages/apps/vm-instance/values.schema.json @@ -88,7 +88,7 @@ }, "instanceProfile": { "type": "string", - "description": "Virtual Machine prefferences profile", + "description": "Virtual Machine preferences profile", "default": "ubuntu", "optional": true, "enum": [ @@ -179,7 +179,7 @@ "cloudInit": { "type": "string", "description": "cloud-init user data config. See cloud-init documentation for more details.", - "default": "#cloud-config\n" + "default": "" }, "cloudInitSeed": { "type": "string", diff --git a/packages/apps/vm-instance/values.yaml b/packages/apps/vm-instance/values.yaml index 26edf59c..eb68ced2 100644 --- a/packages/apps/vm-instance/values.yaml +++ b/packages/apps/vm-instance/values.yaml @@ -12,7 +12,7 @@ externalPorts: running: true ## @param instanceType Virtual Machine instance type -## @param instanceProfile Virtual Machine prefferences profile +## @param instanceProfile Virtual Machine preferences profile ## instanceType: "u1.medium" instanceProfile: ubuntu @@ -53,8 +53,7 @@ sshKeys: [] ## password: ubuntu ## chpasswd: { expire: False } ## -cloudInit: | - #cloud-config +cloudInit: "" ## @param cloudInitSeed A seed string to generate an SMBIOS UUID for the VM. cloudInitSeed: ""