Commit Graph

103 Commits

Author SHA1 Message Date
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 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 9e42b1990a
register: add 'version' and 'dumpdata' subcommands (#835)
'dumpdata' allows to inspect host data from the running host as they are
collected during the registration phase: those are the data made
available in the Elemental Label Templates feature.
This subcommand was developed while working at #834 and since could be
handy for debugging and even for users (elemental sysadmins) adding it
to the elemental-register binary.

'version' is the very first step in moving the elemental-register flags
to command, as requested by #832.

Related to issues: #832, #834

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-09-06 10:37:04 +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
Francesco Giudici 2858dad900
error strings should not be capitalized (ST1005) (#814)
moreover, dump the inner error

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-08-09 15:43:52 +02: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
Andrea Mazzotti b18ff86465
Add managedosversion finalizer (#775)
* Implement ManagedOSVersion controller and finalizer

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

* Remove unused ManagedOSVersion Status

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

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
Co-authored-by: Francesco Giudici <francesco.giudici@gmail.com>
2024-06-25 17:24:53 +02:00
Andrea Mazzotti 561859382c
Use dynamic system agent applied dir (#763)
* Use dynamic system agent applied dir

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

* Use dynamic RKE2 data-dir

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

---------

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-06-24 09:29:26 +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 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
Fredrik Lönnegren 7c4804e323 New name is elemental-rootfs
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-03-14 15:55:45 +01:00
Andrea Mazzotti 6d7b1f57b0
Use /run/elemental and elemental- services (#675)
Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-03-14 10:49:24 +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 b4f8eb6f66
Print system architecture (#603)
* Add architecture in operator initial log message

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-01-30 12:14:53 +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
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
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 e12cc65644 register: add no-toolkit unit tests 2023-09-20 10:35:22 +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
Steven fa8c90ce47 register: add no-toolkit option
Currently the sytem-agent-config is only generated as part of the cloudInitConfigs
when installing, but when registering a pre-installed host it is useful to have
the option to generate the system-agent-config without any OS install.

After discussion it has been suggested to enable this via a --no-toolkit flag
which can optionally be specified for pre-installed hosts, in this mode we will
only write out the system-agent config files.
2023-09-20 10:35:22 +02:00
Andrea Mazzotti ffb9c010c4
Implement remote machines reset (#489) 2023-08-04 09:34:26 +02:00
Andrea Mazzotti 25abcdc57b
Improve re-registration (#479)
- Added full registration config and statefile path parameters on elemental-register
- Remove support for multiple configuration files
- Added (hardcoded) timer to skip registration updates for 24 hours
- Store emulated TPM seed for future registration updates
- Exit with error code in case of failures (systemd will manage restarts)
- Use virtual filesystem where possible
2023-07-18 15:09:21 +02:00
Andrea Mazzotti 3fde9313e8
Handle mkdir error 2023-07-07 10:41:31 +02:00
Andrea Mazzotti 3dc409b504
Create registration config directory if not exist 2023-07-07 10:40:30 +02:00
Andrea Mazzotti 2bbe653570
Persist registration state 2023-07-07 10:25:40 +02:00
Andrea Mazzotti d509be8ca3
Omit confusing debug message 2023-07-07 09:23:01 +02:00
Andrea Mazzotti c8032ebb26
Handle MsgUpdate response on client side 2023-07-05 15:29:09 +02:00
Andrea Mazzotti 2e70a309f9
Prevent registration update if MachineInventory is not found 2023-07-04 17:00:11 +02:00
Andrea Mazzotti a0cbda285d
Do not retry registration when on installed system and using randomized TPM seed 2023-06-30 14:43:57 +02:00
Andrea Mazzotti 82ffc474f3
Do not retry registration when not on live system 2023-06-30 14:17:17 +02:00
Andrea Mazzotti 910fa45100
Check for live registration config when no arguments passed 2023-06-30 11:58:49 +02:00
Francesco Giudici d8feec7be4 register client: set TPM as default authentication method
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-05-22 17:40:19 +02:00
Francesco Giudici 7ce551c2a5 SeedImage: set build image PullPolicy from the operator chart
Fixes #406

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-04-11 12:55:51 +02:00
David Cassany 71ac99f7b6 Enble cache for MachineInventorySelector resources
Signed-off-by: David Cassany <dcassany@suse.com>
2023-03-28 13:04:03 +02:00
Francesco Giudici b291e276bb SeedImage: pass the build image from the operator chart
Also, change the default image to the one build with Docker.seedimage.

The expected image should have the following binaries available:
- xorriso
- curl
- base64

The image should also have as the default entrypoint an http server
starting on port 80 serving files from the working dir.

Related to:
https://github.com/rancher/elemental-operator/issues/374

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-03-28 10:07:35 +02:00
Fredrik Lönnegren 04747a6b6a
Add cloud-config support to seedImage (#399)
* Add cloud-init support to seedImage

This commit adds a field to the SeedImage Spec for a cloud-config that
will be included in the built ISO.

If the cloud-config field is not set an empty file will be added to the
ISOs iso-config dir.

The reconciliation will take place in case the cloud-config is changed
and the base64 encoded value is used in an annotation in order to see if
the value has changed.

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

* Linting

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

* Add seedImage unit-tests

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

---------

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2023-03-23 09:36:36 +01:00
Francesco Giudici 3f0e357b85
operator: add SeedImage CRD (#377)
* operator: add SeedImage CRD and controller

* SeedImage: add Ready condition to track resource status

* SeedImage: add Pod and Service creation in the reconcile loop

* SeedImage: manage Pod lifecycle and set the download URL

* SeedImage: allow the pod to fail if something goes wrong

* SeedImage: add SeedImageReady condition

* SeedImage: improve status condition updates

* SeedImage: add controller tests

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-03-10 18:11:10 +01:00
David Cassany dace08292c Prevent MachineInventorySelector from being cached
Signed-off-by: David Cassany <dcassany@suse.com>
2023-03-10 14:54:28 +01:00
Fredrik Lönnegren fe8f53f2d2 Unify logging
Use klog for all logging and remove logrus.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2023-02-22 18:43:48 +01:00
Francesco Giudici 53f66f9d59
build-image API: add build job with single pod lifecycle (#362)
* operator: build-image API POD lifecycle management
Only one POD at a time allowed (for now).

* elemental-operator: improve build-image logging

* operator: add build-image Service

* operator: build-image API: delete Pod and Service on failure

* operator: add functions to manage registration cache

* operator: finalize build-image API Pod lifecycle

* operator: fix build-image API tests

* operator: ensure clean-up of build-image pods

* operator: add Services creation/deletion to Elemental ClusterRole

* operator: build-image: set download URL when job is completed

* operator: build-image: retry build job Pod creation if needed

* operator: build-image: in case of job Failure leave the Pod there

* operator: build-image: increase the time for job completion

* operator: make Code scanning happy

* operator: build-image: use NodePort Service

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-02-20 11:08:07 +01:00
Francesco Giudici 46512dffc7
register client: isolate TPM auth code (#346)
* register client: aggregate args to the Register function

Since we basically pass almost all the Registration struct parameters
one by one, let's pass a reference to the structure directly.

* register client: introduce authClient interface

The register client code is tightly coupled with TPM attestation.
While this is not a problem right now as we just support authentication
through TPM, it may be good to better separate TPM attestation from the
registration process itself for two reasons:
- better code readibility
- support of alternative authentication methods

Note that on the operator side (register "server") the code is already
structured to allow alternative authentication methods.
This commit introduces an interface with the required authentication
methods: the TPM related code in now completely isolated in the interface
implementation.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-02-07 17:46:32 +01:00
Fredrik Lönnegren b9d1c82976
Copyright date-range 2022 - 2023 (#327)
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2023-01-13 10:30:48 +01:00
Fredrik Lönnegren f3c45601c2 Change tar-file layout in elemental-support
Replace `/tmp/` with `elemental-support-`

Example:

```shell
$ tar tf m-d815bd22-6380-4fd6-a85f-120f9
elemental-support-120771762
elemental-support-120771762/NetworkManager.log
elemental-support-120771762/apps-describe.log
elemental-support-120771762/apps-resource.log
elemental-support-120771762/cattle-fleet-system-fleet-agent-d56d4c7b5-9px68-logs.log
elemental-support-120771762/cattle-system-cattle-cluster-agent-59b7cc4768-jb886-logs.log
elemental-support-120771762/cattle-system-system-upgrade-controller-7f9f559b4f-9vl6h-logs.log
elemental-support-120771762/cos-immutable-rootfs.log
elemental-support-120771762/cos-setup-boot.log
...
```

Fixes #205

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2022-12-21 14:28:43 +01:00
Fredrik Lönnegren 2003655b5d
Return registration errors to client (#301)
* Return registration errors to client

Introduces two new message-types (MsgError and MsgConfig).

MsgError is sent when an error is encountered during the registration
process.

MsgConfig is used to send the elemental configuration to the client,
before this was just a raw message with no type so we need to check in
the server if the client supports the message, otherwise fallback to the
raw message.

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

* Change registration error message

unknown -> unexpected

Co-authored-by: Francesco Giudici <francesco.giudici@gmail.com>
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@gmail.com>

* Remove InventoryServer receiver argument

From writeError method

Co-authored-by: Francesco Giudici <francesco.giudici@gmail.com>
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2022-12-20 13:57:16 +01:00
Francesco Giudici 3965dd346f
operator: add back debug logs for logrus (registration) (#299)
With kubebuilder we moved to sigs.k8s.io/controller-runtime logs.
Still, the registration part of the operator uses logrus for logging.

The operator debug config just enables verbose logging on the newer
controller-runtime logs: allow to enable verbose logging on registration
too.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-12-15 17:07:07 +01:00
Alexander Demicev c4b8e2d596 Merge all main logic in one file (#270) 2022-12-12 12:15:22 +01:00
Francesco Giudici e60da05e35 [controller_runtime] operator/registration: switch to Kubebuilder client (#256)
* operator/registration: switch to Kubebuilder client

Fixes #239

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

* operator/registration: adapt tests to Kubebuilder client

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

* unit-tests: vendor controller-runtime fake client

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

* operator: add yaml annotations for correct marshalling

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

* operator/RBAC: add "get" verb to ServiceAccount resources

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

* operator: generate rbac

make generate-manifests
make build-rbac

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

* Add elementalcli package

Create a separate package to deal with elemental-cli installation.
This brings the elemental-cli functions declared in the config package
to a new package that just parses a map[string]interface argument.

This is a step to enable usage of the elemental-cli functions with the
new elementalv1.Config.Elemental.Install type.

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

* register: switch to Kubebuilder api

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

* register: add mapstructure annotations for correct marshalling

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

* register: reduce complexity of the run function

Make linter happy:
"cyclomatic complexity 16 of func `run` is high (> 15) (gocyclo)"

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

* register: drop io/ioutil in favor of os package

io/ioutil is deprecated

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

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-12-12 12:15:22 +01:00
David Cassany Viladomat 173ebae8e1 Drop requeuer, not needed anymore (#255)
* Drop requeuer, not needed anymore
* Improve logging

Signed-off-by: David Cassany <dcassany@suse.com>
2022-12-12 12:15:22 +01:00