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.
Random label templates are rendered only once
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:
|
Variable | Description | from |
---|---|---|
|
random UUID (e.g., fd95324a-c26b-4e28-8727-1dcec293a0ec) |
1.7.0 |
|
random hexadecimal string of the specified length (min 1, max 32) |
1.7.0 |
|
random integer (min 0, max MAXINT-1) |
1.7.0 |
Rendering Examples
|
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}"