-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
operator: rework label templating (#808)
Reworked the code to provide templating to MachineInventory labels and name. The template source data is the "System Information" (BIOS) and "System Data" (which we usually called 'HW Labels') data sent by the machines via the register client. This rework fixes some bugs and duplicated code and slightly changes the behavior in few cases. The behavioral changes address the following corner cases: * `.` is added to the allowed characters in label values (previously was substituted with `-`). * when the first character of a label value is an accepted one but not alphanumeric (i.e., `-` , `_` or `.`) we drop it (previously we prepended `m` to the label). * if the last character of a label value is not alphanumeric (i.e., `-` , `_` or `.`) we drop it (previously was not checked). note that for the MachineInventory name (which will also be the machine hostname after k8s provisioning) the allowed set of characters has not changed: it's the same of the label case but without the `_` (i.e., `-` or `.`). Regarding the MachineRegistration.spec.machineName: * if it is empty, a default `m-${UUID}` value is assigned to the MachineInventory.name (as previously) * if it contains a template value which doesn't exists (wrong template value or `nosmbios` option) the MachineInventory.name is assigned a default `m-${UUID}` name (new behavior). * if it is not empty, but after resolving the template values and sanitizing the string it gets empty, the name assignment process will error out failing the registration process. Commits: * operator: move label templating functions to separate file no code changes, just label templating functions moved to labeltmpl.go. * operator: add pkg/templater * operator: add few comments * operator: rework label templating Fixes #807 * tests: update api_registration_test.go * operator: move regexp to label templating file * operator: change template behavior in corner cases 1. '.' is added to the allowed characted in label values (previously was sobsituted with '-'). 2. when the first character of a label value is not alphanumeric ("-" or "_" or ".") we drop it (previously we prepended 'm'). 3. if the last characted of a label value is not alphanumeric ("-" or "_" or ".") we drop it (previously was not checked). * tests: improve coverage of label templating * make linter happy Signed-off-by: Francesco Giudici <[email protected]>
- Loading branch information
Showing
8 changed files
with
607 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.