* Label Templates: fix Random check
This commit fixes the panic occurring with a malformed Random
template label (${Random}).
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
* Label Templates: don't fail registration for a wrong label
A wrong Random label syntax causes an error that fails and stops
the registration process: don't stop the registration, just log the
error, skip the label and proceed.
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
---------
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
* Label Templates: render also annotations
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
* tests: move label templates tests to separate file
from api_registration_test.go to labeltmpl_test.go
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
* tests: re-use hostinfo variable
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
* tests: drop leftover printf()
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
* tests: add updateInventoryAnnotations() coverage
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
---------
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
* Label Templates: rework collection of 'System Data' info
Allow automatic conversion of data to map[string]interface{} (Template
Labels format) using reflection where all data can be useful.
Still do manual collection of data in the map[string]interface{} when
dropping of part of the data is needed.
Use the original hostinfo field names, drop spaces in the keys.
Import also the SMBIOS data from hostinfo, since are there (so also
without dmidecode tool some SMBIOS info will be available).
Keep support of old HARDWARE variable (to be deprecated sooner or
later).
* register/dumpdata: rework initial version adding more options
notably the "label" output format, which is now the default
* register: send both legacy and new Label Templates variables
we don't want to break possible setups using the older Label Templates
variables: send both.
* tests: check new hostinfo Label Templates format
---------
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
* operator: render 'Random' template lables once
Otherwise we would keep overwriting the template labels which have
Random variables, that are rendered each time differently.
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
* tests: check Random template labels overwrite rules
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
---------
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
* operator/register: merge network config retrieval with registration
use the same websocket connection to exchange all the data
* tests: fix tests
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
* operator: introduce support to IPAM assigned IP address
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
* Add nmstate support
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
---------
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
Co-authored-by: Francesco Giudici <francesco.giudici@suse.com>
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 <francesco.giudici@suse.com>
* Update system-upgrade-controller API
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
* Update Fleet API
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
* Sanitize dependencies
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
---------
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
sanitizeString() is only called from replaceStringData().
Move all the sanitizing code there.
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
Add new ${System Data/Runtime/Hostname} key to the registration data
sent from the elemental-register command.
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
This commit stops using the ServiceAccount.Secrets list, as noted my
k8s this should not be used to find SA's associated secrets and this
is no longer being automatically managed by k8s since v1.24.
Signed-off-by: David Cassany <dcassany@suse.com>
* Add client registration config utility
* Use a config-map for the seed-image pod
* Allow ConfigMaps manipulation in SeedImage RBAC
* Drop configmap-uid annotation
* go mod tidy
* Adapt tests
* Add createConfigMapObject tests
Signed-off-by: David Cassany <dcassany@suse.com>
We used to return the registration yaml in that case: makes no sense.
Just return the error.
Keep instead returning the registration yaml when using websocket with
no auth, also if we expect a plain HTTP GET to retrieve the registration
yaml.
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
We now have the SeedImage resource to start and track image building
tasks: drop the old build-image api.
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
This commit adds a new exchange between the registering client and the
operator: the registering client will pass some data that will be put in
the MachineInventory annotations.
This is meant to be a way to track those dynamic data from the host that
could be handy to have in the MachineInventory.
The only data passed in the current commit is the host address used to
register.
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
* operator: isolate hostinfo data
Since we already wrap the "ghw" library to collect system data in the
hostinfo package, let's move all the logic dealing with conversion from
raw data to labels there for better isolation.
* operator: add few more fields in System Data collection
In particular, NICs MAC address
---------
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>