mirror of
https://github.com/outbackdingo/cozystack.git
synced 2026-01-27 18:18:41 +00:00
Add a setting to VMs that allows users to trigger cloud-init full reconfiguration. (#767)
This will trigger cloud-init reinitialization, including ssh keys update and static network config refresh.
This commit is contained in:
@@ -53,6 +53,7 @@ virtctl ssh <user>@<vm>
|
||||
| `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. | `""` |
|
||||
|
||||
## U Series
|
||||
|
||||
|
||||
@@ -49,3 +49,23 @@ Selector labels
|
||||
app.kubernetes.io/name: {{ include "virtual-machine.name" . }}
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Generate a stable UUID for cloud-init re-initialization upon upgrade.
|
||||
*/}}
|
||||
{{- define "virtual-machine.stableUuid" -}}
|
||||
{{- $source := printf "%s-%s-%s" .Release.Namespace (include "virtual-machine.fullname" .) .Values.cloudInitSeed }}
|
||||
{{- $hash := sha256sum $source }}
|
||||
{{- $uuid := printf "%s-%s-4%s-9%s-%s" (substr 0 8 $hash) (substr 8 12 $hash) (substr 13 16 $hash) (substr 17 20 $hash) (substr 20 32 $hash) }}
|
||||
{{- if eq .Values.cloudInitSeed "" }}
|
||||
{{- /* Try to save previous uuid to not trigger full cloud-init again if user decided to remove the seed. */}}
|
||||
{{- $vmResource := lookup "kubevirt.io/v1" "VirtualMachine" .Release.Namespace (include "virtual-machine.fullname" .) -}}
|
||||
{{- if $vmResource }}
|
||||
{{- $existingUuid := $vmResource | dig "spec" "template" "spec" "domain" "firmware" "uuid" "" }}
|
||||
{{- if $existingUuid }}
|
||||
{{- $uuid = $existingUuid }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $uuid }}
|
||||
{{- end }}
|
||||
|
||||
@@ -68,6 +68,8 @@ spec:
|
||||
requests:
|
||||
memory: {{ .Values.resources.memory | quote }}
|
||||
{{- end }}
|
||||
firmware:
|
||||
uuid: {{ include "virtual-machine.stableUuid" . }}
|
||||
devices:
|
||||
{{- if .Values.gpus }}
|
||||
gpus:
|
||||
|
||||
@@ -199,6 +199,11 @@
|
||||
"type": "string",
|
||||
"description": "cloud-init user data config. See cloud-init documentation for more details.",
|
||||
"default": "#cloud-config\n"
|
||||
},
|
||||
"cloudInitSeed": {
|
||||
"type": "string",
|
||||
"description": "A seed string to generate an SMBIOS UUID for the VM.",
|
||||
"default": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,3 +57,12 @@ sshKeys: []
|
||||
##
|
||||
cloudInit: |
|
||||
#cloud-config
|
||||
|
||||
## @param cloudInitSeed A seed string to generate an SMBIOS UUID for the VM.
|
||||
cloudInitSeed: ""
|
||||
## Change it to any new value to force a full cloud-init reconfiguration. Change it when you want to apply
|
||||
## to an existing VM settings that are usually written only once, like new SSH keys or new network configuration.
|
||||
## An empty value does nothing (and the existing UUID is not reverted). Please note that changing this value
|
||||
## does not trigger a VM restart. You must perform the restart separately.
|
||||
## Example:
|
||||
## cloudInitSeed: "upd1"
|
||||
|
||||
@@ -51,6 +51,7 @@ virtctl ssh <user>@<vm>
|
||||
| `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. | `""` |
|
||||
|
||||
## U Series
|
||||
|
||||
|
||||
@@ -49,3 +49,23 @@ Selector labels
|
||||
app.kubernetes.io/name: {{ include "virtual-machine.name" . }}
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Generate a stable UUID for cloud-init re-initialization upon upgrade.
|
||||
*/}}
|
||||
{{- define "virtual-machine.stableUuid" -}}
|
||||
{{- $source := printf "%s-%s-%s" .Release.Namespace (include "virtual-machine.fullname" .) .Values.cloudInitSeed }}
|
||||
{{- $hash := sha256sum $source }}
|
||||
{{- $uuid := printf "%s-%s-4%s-9%s-%s" (substr 0 8 $hash) (substr 8 12 $hash) (substr 13 16 $hash) (substr 17 20 $hash) (substr 20 32 $hash) }}
|
||||
{{- if eq .Values.cloudInitSeed "" }}
|
||||
{{- /* Try to save previous uuid to not trigger full cloud-init again if user decided to remove the seed. */}}
|
||||
{{- $vmResource := lookup "kubevirt.io/v1" "VirtualMachine" .Release.Namespace (include "virtual-machine.fullname" .) -}}
|
||||
{{- if $vmResource }}
|
||||
{{- $existingUuid := $vmResource | dig "spec" "template" "spec" "domain" "firmware" "uuid" "" }}
|
||||
{{- if $existingUuid }}
|
||||
{{- $uuid = $existingUuid }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $uuid }}
|
||||
{{- end }}
|
||||
|
||||
@@ -40,6 +40,8 @@ spec:
|
||||
requests:
|
||||
memory: {{ .Values.resources.memory | quote }}
|
||||
{{- end }}
|
||||
firmware:
|
||||
uuid: {{ include "virtual-machine.stableUuid" . }}
|
||||
devices:
|
||||
{{- if .Values.gpus }}
|
||||
gpus:
|
||||
|
||||
@@ -180,6 +180,11 @@
|
||||
"type": "string",
|
||||
"description": "cloud-init user data config. See cloud-init documentation for more details.",
|
||||
"default": "#cloud-config\n"
|
||||
},
|
||||
"cloudInitSeed": {
|
||||
"type": "string",
|
||||
"description": "A seed string to generate an SMBIOS UUID for the VM.",
|
||||
"default": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,3 +55,12 @@ sshKeys: []
|
||||
##
|
||||
cloudInit: |
|
||||
#cloud-config
|
||||
|
||||
## @param cloudInitSeed A seed string to generate an SMBIOS UUID for the VM.
|
||||
cloudInitSeed: ""
|
||||
## Change it to any new value to force a full cloud-init reconfiguration. Change it when you want to apply
|
||||
## to an existing VM settings that are usually written only once, like new SSH keys or new network configuration.
|
||||
## An empty value does nothing (and the existing UUID is not reverted). Please note that changing this value
|
||||
## does not trigger a VM restart. You must perform the restart separately.
|
||||
## Example:
|
||||
## cloudInitSeed: "upd1"
|
||||
|
||||
Reference in New Issue
Block a user