Random Template Variables​
Random template variables are built-in in the Elemental Operator.
They allow to include random Int
, Hex
or UUID
values in custom label templates.
The values are computed on the fly during the label template variables
rendering.
A label template containing a Random variable is rendered only if the MachineInventory of the registering host doesn't have a value for that label yet (a label with the same key is missing or its value is empty).
So, the three cases in which a label template with a Random variable is rendered are:
- the host is registering for the first time and the MachineInventory is created anew
- the label template has been added to the MachineRegistration after the host (re-)registered last time
- the MachineInventory label matching the label template (same label key) has been manually removed or its value has been cleared out
Variable | Description |
---|---|
${Random/UUID} | random UUID (e.g., fd95324a-c26b-4e28-8727-1dcec293a0ec) |
${Random/Hex/[1-32]} | random hexadecimal string of the specified lenght (min 1, max 32) |
${Random/Int/[MAXINT] | random integer (min 0, max MAXINT-1) |
template value | rendered value example |
---|---|
${Random/UUID} | fd95324a-c26b-4e28-8727-1dcec293a0ec |
${Random/Hex/12} | acd231f222b8 |
${Random/Int/10000} | 9432 |
The Random Template Variables can be handy for generating custom hostnames to be assigned to the registering host.
Since the hostname must be unique and is assigned through the
MachineRegistration spec.machineName
field, Random variables can be used
to ensure uniqueness of a group of host sharing the same custom prefix and/or suffix.
Check the HowTo/Customize hostname section for more information.
apiVersion: elemental.cattle.io/v1beta1
kind: MachineRegistration
metadata:
name: fire-nodes
namespace: fleet-default
spec:
machineName: "fire-node-${Random/Hex/12}"
config:
cloud-config:
users:
- name: root
passwd: root
elemental:
install:
reboot: true
device: /dev/sda
debug: true
machineInventoryLabels:
elemental.cattle.io/UUID: "${Random/UUID}"