Commit Graph

280 Commits

Author SHA1 Message Date
Francesco Giudici 317de1e25a
Label Templates: improve Random family processing (#914)
* 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>
2025-06-13 14:21:28 +02:00
Francesco Giudici 97db17d73b
make linter happy - update copyright dates (#899)
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2025-01-31 15:33:47 +01:00
Francesco Giudici 5e14e968ee
Label Templates: add IP addresses to the Network variables (#885)
* util: add network util functions

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* Label Templates: add IPAddress to the Network vars

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* util/net: rework to allow mocking system ip address retrieval

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* util/net: return all the available network addresses

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* Label Templates: add IPAddresses.{num} to the Network vars

track all available network addresses

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* make generate-mocks

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* tests: add util/net coverage

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* error strings should not be capitalized

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

---------

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-11-26 09:17:00 +01:00
Andrea Mazzotti 6372ec6706
Only reset network if a network configurator is used (#874)
* Only reset network if a network configurator is used

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-10-22 14:56:33 +02:00
Andrea Mazzotti cf1a2d6400
Do not include Config to MachineRegistration as pointer (#870)
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-10-17 08:09:41 +02:00
Andrea Mazzotti ab193eca6f
Add support for agent-tls-mode Rancher setting (#863)
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-10-07 13:11:26 +02:00
Andrea Mazzotti 08f6cda748
Build e2e chart locally (#852)
* Build e2e chart locally

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Add mockgen to build tools

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Add missing GINKGO tool

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Reduce e2e tests concurrency

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Make test more verbose

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Bump system-upgrade-controller version

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Raise timeout

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Print error

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Add plan crd

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Adjust timeout

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Do not deploy operator twice

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Restore vendored helper

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Do not attempt to delete pods multiple times

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Remove debug println

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Disable e2e workflow

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Update ele-testhelpers library

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

---------

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-10-01 12:54:40 +00:00
Andrea Mazzotti 3df501da73
Allow configuration of max snapshots during install (#851)
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-09-25 13:31:29 +02:00
Francesco Giudici 60808bfe11
Label Templates: render also machineInventoryAnnotations (#848)
* 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>
2024-09-20 11:21:46 +02:00
Francesco Giudici c9223009e6
label templates: drop spaces from Storage variables (#847)
was a leftover from label templates rework

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-09-20 08:17:37 +02:00
Francesco Giudici 723d7c3eb1
Label Templates: rework collection of 'hostinfo' data and collected variables (#843)
* 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>
2024-09-13 08:45:45 +02:00
Francesco Giudici 122109f7d9
Random template labels - avoid override (#830)
* 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>
2024-08-28 09:13:46 +02:00
Andrea Mazzotti 0899ba2953
Add SeedImage.status.checksumURL (#827)
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-08-22 12:23:20 +02:00
Andrea Mazzotti b7f70897f0
Fix flaky network test (#825)
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-08-21 09:20:46 +00:00
Andrea Mazzotti 3de0fc7a47
Use after-install && after-reset stages to initialize system (#822)
* Use after-install && after-reset stages to initialize system

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Use dynamic CLOUD_INIT_PATHS

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

* Use IPAM driven network config on Recovery

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>

---------

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-08-20 13:39:45 +02:00
Andrea Mazzotti d857bda0cc
Implement Network Configurators (nmc, nmstate, nmconnections) (#819)
* Implement Network Configurators (nmc, nmstate, nmconnections)

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-08-13 17:35:54 +02:00
Francesco Giudici d8bcf7408a
operator: add built-in 'Random' label templates (#821)
introduce built-in random templates:
* ${Random/UUID}
* ${Random/Hex/[0-32]}
* ${Random/Int/[MAXINT]}

examples:
${Random/UUID} --> e512d5ca-a765-42f2-82b7-264f37ffb329 ${Random/Hex/12} --> e512d5caa765
${Random/Int/1000} --> 199

Fixes #802

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-08-13 13:00:59 +02:00
Francesco Giudici e4c75194c2
networking: use the main registration websocket channel for network data (#820)
* 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>
2024-08-12 10:10:01 +00:00
Andrea Mazzotti 342bba265c
IPAM to nmstate network config (#793)
* 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>
2024-08-09 10:32:19 +02:00
Francesco Giudici 36468aba42
register: always register when called (#813)
Remove the static check to re-register only after 24 hours.
The re-registration will then happen every time the elemental-register
client is called.
This static timer was introduced to limit as much as possible the
communication form the host to Rancher and save communication bandwidth
for remote clients.
Anyway, this makes not much sense as long as the elemental-system-agent
is running, which will in any case keep connecting to Rancher.
The call to the elemental-register binary is performed on official
Elemental SLE Micro images every 30 minutes and at each boot.

Fixes https://github.com/rancher/elemental-operator/issues/811

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-08-08 10:10:25 +02:00
Francesco Giudici 6681ea5f6d
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 <francesco.giudici@suse.com>
2024-08-05 16:05:39 +02:00
Andrea Mazzotti c90990371c
Use YAML content for Elemental Agent config (#765)
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-06-19 15:49:19 +02:00
Andrea Mazzotti 9c8550fdfb
Allow yip configs (#751)
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-06-17 10:25:17 +02:00
Andrea Mazzotti bc2f5cfc81
Let elemental-register digest system hardware data (#748)
* Let elemental-register digest system hardware data (SystemData V2)

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-06-04 14:03:06 +02:00
Francesco Giudici 3379c85c40
register: don't send new Disks and Controllers data (#741)
The newer versions of jaypipes/ghw include a new type of Disk and
Controller in the Blocks section.

We use the library json serialization functionality: the deserialization
function of the older version of the library (0.9.0) would error out
when trying to decode serialized data of newer versions if they include
the new "virtual" drive or the new "loop" controller.
For now, just remove those devices.
Proper fix will be to better deal with this kind of errors avoiding
tearing down the registration process.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-05-28 17:23:07 +02:00
Francesco Giudici f5d9c70b96 unit-tests: minor cleanups
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-04-03 09:02:10 +02:00
Francesco Giudici dae5f91224 unit-test: add register tests
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-04-03 09:02:10 +02:00
Francesco Giudici 695904cd96 unit-tests: add coverage for seedimage API
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-04-03 09:02:10 +02:00
Francesco Giudici 070b538af8
elemental-operator registration cleanups (#689)
* registration: fix typo
* registration: drop support to elemental-register < v0.5.0

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-03-21 17:49:05 +01:00
Andrea Mazzotti 0839780db8
Sanitize elemental-operator dependencies (#690)
* 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>
2024-03-20 15:46:51 +01:00
Andrea Mazzotti ea7e8118db
Add extension to seedimage url (#682)
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-03-15 15:21:26 +01:00
Francesco Giudici e510406fba registration: allow dots in machineInventory names
fixes #677

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-03-15 10:40:40 +01:00
Francesco Giudici 803cbf5206 registration: decouple replacing data-labels from sanitizing strings
no functional changes

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-03-15 10:40:40 +01:00
Francesco Giudici a896b79d9e registration: move sanitize code in sanitizeString()
sanitizeString() is only called from replaceStringData().
Move all the sanitizing code there.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-03-15 10:40:40 +01:00
David Cassany Viladomat 483877487a
Make snapshotter configurable (#651)
* Make snapshotter configurable

This commit adds the snapshotter type as a new parameter in
installation struct, defaults to btrfs. This is passed as
an environment variable to the elemental client call. Any
client previous to v2 will simply ignore this flag.

* Make loopdevice an explicit default

Signed-off-by: David Cassany <dcassany@suse.com>
2024-03-06 15:59:47 +00:00
Francesco Giudici 8e810e394c
elemental-register: collect OS data for MachineInventories annotations (#642)
* register: add OS info in the MachineInventory annotations
* register: add the register version in the MachineInventory annotations
* golang static checks ST1005

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-02-23 08:12:36 +00:00
Fredrik Lönnegren 7878dd43af Use rancher/yip v1.4.10
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-02-15 11:43:14 +01:00
Fredrik Lönnegren 1f447e5e17 Make linter happy
Revive linter added a new default rule for unused-parameters, update the
code to match.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-02-12 09:52:35 +01:00
Andrea Mazzotti e523a25bd1
Fix inversed reset options (#604)
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-01-30 17:19:36 +01:00
Fredrik Lönnegren 0a4fe2e71e Add hostname to system-data
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>
2024-01-12 09:41:39 +01:00
Fredrik Lönnegren da0776b710 Update copyright year (2024)
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-01-05 13:14:27 +01:00
Fredrik Lönnegren 74649a5ae2 Add disable-boot-entry flag to reset command
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2023-12-15 15:14:00 +01:00
David Cassany 4f00fe4ad0 Always pull channel image on channel sync
Signed-off-by: David Cassany <dcassany@suse.com>
2023-12-11 19:15:23 +01:00
Fredrik Lönnegren 4b5e46cfd7 Add warning if both device and device-selector set
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2023-11-27 14:47:53 +01:00
Fredrik Lönnegren 20ce1e02a0
Fix device-selector logic (#571)
disk.Name only contains name, not path (eg sda not /dev/sda).

This commit fixes the logic so users can specify either the name or path
and elemental will install to the correct device.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2023-11-24 13:29:44 +01:00
Fredrik Lönnegren 8cf8b03e29
Implement picking dynamic installation device (#561)
* Add DeviceSelector types

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

* Implement device-selector

This commit adds the implementation for picking the installation device
during registration based on a deviceSelector in the
MachineRegistration.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

---------

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2023-11-21 08:44:42 +01:00
Loic Devulder 961b0c502f Disable local plan for elemental-system-agent
As local plan is not used, only remote.

Signed-off-by: Loic Devulder <ldevulder@suse.com>
2023-10-09 09:14:45 +02:00
David Cassany 502d832a6c Add some improvements
Signed-off-by: David Cassany <dcassany@suse.com>
2023-10-03 14:47:12 +02:00
David Cassany 8393423c8a Run all syncers in a pod
This commit moves the synchronization logic to allways happen in a Pod,
regardless being a Custom or JSON syncer. This allows having a simpler Pod
lifecycle management as part of the channel controller logic.

In addition, syncer pod logs are read on succeeded state instate of
running state to simplify Pod lifecycle management.

As a result channel updates trigger a new channel synchronization
without having to wait for the next scheduled sync.

Signed-off-by: David Cassany <dcassany@suse.com>
2023-10-03 14:47:12 +02:00
Steven a393a1387c register: add os.unmanaged inventory annotation
When hosts are registered with the --no-toolkit option no OS management
is possible, so we set a new os.unmanaged annotation to reflect this
and skip any attempt to reset if this is found.
2023-09-20 10:35:22 +02:00