Commit Graph

280 Commits

Author SHA1 Message Date
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
David Cassany 3eec04eaca Small refactor to centralize registration config checks
Signed-off-by: David Cassany <dcassany@suse.com>
2023-09-12 16:21:07 +02:00
David Cassany 44335c76ba Ensure Elemental registration data includes the registration URL
Signed-off-by: David Cassany <dcassany@suse.com>
2023-09-12 16:21:07 +02:00
Andrea Mazzotti ffb9c010c4
Implement remote machines reset (#489) 2023-08-04 09:34:26 +02:00
David Cassany cf023acbec Remove custom default config-dir on installation media
Signed-off-by: David Cassany <dcassany@suse.com>
2023-08-02 18:17:04 +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
David Cassany 989851fa61 Do not make use of ServiceAccount.Secrets list
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>
2023-07-11 17:06:37 +02:00
Andrea Mazzotti 2b0df394f9
Fix error formatting 2023-07-05 15:49:29 +02:00
Andrea Mazzotti c8032ebb26
Handle MsgUpdate response on client side 2023-07-05 15:29:09 +02:00
Andrea Mazzotti b9a3755522
Remove unnecessary MsgUpdate payload. Rely on authentication data instead 2023-07-05 14:43:55 +02:00
Andrea Mazzotti b96e033bf3
Handle sendUpdate error 2023-07-05 13:57:01 +02:00
Andrea Mazzotti b102d9a6da
Do not terminate serveLoop on MsgUpdate 2023-07-05 13:52:33 +02:00
Andrea Mazzotti 7a92162046
- Check protocol version before sending MsgUpdate
- Use MsgUpdate to notify registration update only
2023-07-05 13:43:16 +02:00
Andrea Mazzotti 2e70a309f9
Prevent registration update if MachineInventory is not found 2023-07-04 17:00:11 +02:00
Francesco Giudici 918798a2a9 websocket/trivial: messages: annotate version of introduction
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-05-22 17:40:19 +02:00
Francesco Giudici 6b0e3798a3 register client: make linter happy
Reduce cyclomatic complexity of the `Register` function

----

Error: cyclomatic complexity 21 of func `Register` is high (> 20)
(gocyclo)

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-05-22 17:40:19 +02:00
Francesco Giudici ca9137efca register client: annotate auth method used for registration
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-05-22 17:40:19 +02:00
Francesco Giudici 006529e371 register client: rework getHostMacAddr()
Skip virtual interfaces and pick the MAC with the lowest hexadecimal
value.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-05-22 17:40:19 +02:00
Francesco Giudici eb4e7aaf0a register client: add 'mac' and 'sys-uuid' Plain Auth
Fixes #441

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-05-22 17:40:19 +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 ad73aa5266 operator: enable plain auth
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-05-22 17:40:19 +02:00
Francesco Giudici e436a41b36 operator: add plain auth
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-05-22 17:40:19 +02:00
Francesco Giudici 1dbb8cd5a5 elemental api: add fields to support plain authentication
Add MachineRegistration Elemental Registration Auth to allow
selection of the authentication method.
Add MachineInventory MachineHash key for authentication types different than
TPM (which has its own TPMHash key).

make generate
make build-manifests
2023-05-22 17:40:19 +02:00
David Cassany 8267808c14 Add tests for containerized base ISO and utilities
Signed-off-by: David Cassany <dcassany@suse.com>
2023-04-21 11:28:02 +02:00
David Cassany 980ba5c893 Pull iso as a container
Signed-off-by: David Cassany <dcassany@suse.com>
2023-04-21 11:28:02 +02:00
Francesco Giudici f603f30271 SeedImage extended API: drop debug log
That slipped in from older PRs... clean it.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-04-20 18:01:37 +02:00
Francesco Giudici a9853c639b SeedImage: extended api doesn't expect the iso name anymore
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-04-20 18:01:37 +02:00
Francesco Giudici e37cd67e57 Utils: generalize IsPodOwned func to IsObecjtOwned() and add tests
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-04-18 15:31:27 +02:00
Francesco Giudici c66160408e SeedImage: make the linter happy...
...and add a new helper in the util package to verify is a resource is
owned by an object (identified by its UID).

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-04-18 15:31:27 +02:00
David Cassany Viladomat f4f34ca948
Use config map in seedimage pod (#423)
* 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>
2023-04-14 18:51:21 +02:00
Francesco Giudici 15725b2f98 unit-tests: cover MAC and Used Memory in labels test
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-04-11 12:43:52 +02:00
Francesco Giudici 5264cc81bb unit-tests/trivial: move server.go test to the new server_test.go file
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-04-11 12:43:52 +02:00
David Cassany dd818d07de Prevent a nil pointer dereference panic error
Signed-off-by: David Cassany <dcassany@suse.com>
2023-03-29 15:39:17 +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 1106a79416 operator: allow seedimage download from the extended API
This way we serve the download from the cluster domain, with https and
using the same certificate.

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

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-03-17 13:29:46 +01:00
Francesco Giudici 1fb30f3d92 operator: return http 401 error on registration auth failure
https://github.com/rancher/elemental-operator/issues/384#issuecomment-1469664533

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-03-17 13:29:46 +01:00
Francesco Giudici 35b740d55f operator: report error on unrecognized auth websocket connections
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>
2023-03-17 13:29:46 +01:00
Francesco Giudici 1cce280a9b
operator: drop build-image api (#389)
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>
2023-03-16 15:18:52 +01:00
Francesco Giudici 62a16462b1
operator: use opensuse nginx to serve build-img ISO (#369)
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-02-27 21:22:53 +01:00
David Cassany 6ddca9f1f8 Use variadic arguments in klog instead of slices
Signed-off-by: David Cassany <dcassany@suse.com>
2023-02-24 12:21:26 +01:00
Francesco Giudici e1be30f1c6
operator: register the host IP in MachineInventory annotations (#350)
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>
2023-02-23 16:11:03 +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 29a0ee051d
operator: labels minor improvements (#363)
* 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>
2023-02-20 16:10:42 +00: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
Fredrik Lönnegren d0ca62d197 Move system-data labels to templating
Remove default MachineInventory labels taken from system (memory, cpu,
gpu, network and block devices).

Make these values available as templates on MachineRegistration instead
under '${System Data/...}', for example '${System Data/Memory/Total Physical
Bytes}'

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2023-02-14 14:30:31 +01:00
Francesco Giudici dd06ee13e7
operator: let build-image API GET to return the image URL (#351)
Add the URL of the built image to the returned data from the build-image
API.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-02-07 17:10:34 +00: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
Francesco Giudici 3cbf6b9ec2
operator: fix label name (#348)
By default we collect block device system data as labels. The label name
for the number of block devices found was missing the
elemental.cattle.io prefix: fix it.

Moreover, make the label keys for the number of Network Interfaces and
Block Devices consistent:
elemental.cattle.io/NetIfacesNumber
elemental.cattle.io/NetBlockDevicesNumber

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-02-06 16:55:18 +01:00
Francesco Giudici b489184ae5
operator: fix MachineInventory search during registration (#342)
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-01-24 18:44:26 +01:00
Francesco Giudici 92dc650973
operator: always use software UUID as default machine name (#340)
The default machine name is m-{UUID}.
The UUID is generated via software if SMBIOS data is disabled, otherwise
the SMBIOS {System Information/UUID} is used.
Since some hardware vendors don't properly fill the UUID SMBIOS data,
let always provide a machine name based on a software generated UUID, to
ensure name uniqueness by default.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-01-23 11:04:29 +01:00
Francesco Giudici ed7c107bb2
operator: add support to old register clients (#338)
The CloudConfig structure was a serialized interface map: if an old
client is detected, convert back to that legacy type.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-01-19 19:07:55 +01:00
Fredrik Lönnegren 2644a7a3e5 Lints
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2023-01-16 17:00:27 +01:00
Francesco Giudici 23e08e092f
register client: allow to register against lower version operators (#332)
Fixes #331

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-01-16 10:32:13 +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
Francesco Giudici fabe76daac
operator: expose build-image API (#315)
* operator: add multiple APIs support in the API server callback

- parse incoming request to identify the requested API
- move the registration management in a separate function
- add placeholder for the new build-image API

* operator: move generic API functions from register.go to server.go

We are introducing new APIs: let's keep in the register.go package
only those functions specific to the register API only.

This commit just moves some functions from register.go to server.go.
No changes in the code.

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

* operator: move getMachineRegistration() to server.go

Move getMachineRegistration() to server.go for usage from all
APIs. Moreover, let it take directly the token as parameter.

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

* operator: enforce API syntax during registration

We expext to receive a path of the form:
/elemental/{api}
enforce it (or return HTTP 404 - Not found).

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

* operator: introduce generic getValue() function

This is a generic function that could stay under server.go.
Move the specific function to retrieve the CACert under register.go
and leverage the newly introduced function.

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

* operator: rename register.go to api_registration.go

just to make code easier to navigate

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

* operator: add api_buildimage.go for build-image API functions

move there also the placeholder function for the build-image API

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

* operator: add registration cache to the server

We need it to store ephemeral build image data, like the seed image
and the status of the actual build job.
We could extend it in the future to have a full cache of the
MachineRegistration that the registration server should deal with.

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

* operator: build-image API scaffolding

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

* operator: add tests for build-image api

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

* operator: ensure user input from APIs is properly escaped

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

* operator: log failure to set read deadline on the websocket

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

* update Copyright year in modified files

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

* operator: add a small delay before reporting the build job failure

The build job is empty, and right now just reports failure (actual
implementation will be added in the future).
Since the API tests check the state just after starting the build and
expect to find its state updated to "Started", we need the build job to
wait a while before updating the build state to "Failed", otherwise the
tests may miss the Started state.

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

* operator: make code scanning tools happier

when user input is sanitized, use a different var to store the sanitized
value. This should made scanning tools job eisier and avoid false
positives.
On the bonus side, the code will be more readable, i.e., it will be
clear where we use the sanitized values.

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

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-01-11 11:57:42 +01:00
Itxaka 474c3e9757
Do not store cpu info if not available (#321)
Fixes https://github.com/rancher/elemental-operator/issues/320
2023-01-09 10:19:30 +00:00
David Cassany Viladomat ffe8927c49
Add default config-dir value (#313)
Signed-off-by: David Cassany <dcassany@suse.com>
2022-12-21 12:22:53 +01:00
David Cassany Viladomat 9ff0d6e439
Re-add config-dir install flag (#309)
Note that `config-dir` options for the install config got lost within the kubebuilder refactor. This is required to be able to pass custom hooks as part of the installation.

Signed-off-by: David Cassany <dcassany@suse.com>
2022-12-20 15:25:46 +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
Itxaka 4658997ab3
Properly sanitize extra system data (#307)
Fixes https://github.com/rancher/elemental-operator/issues/306
2022-12-20 08:34:32 +00:00
Itxaka 76d2bb3950
Derive TPM seed from system UUID (#297) 2022-12-16 14:41:55 +00:00
Itxaka 699c3108eb
[tpm] Set a random seed if emulated tpm seed is set to -1 (#282)
Signed-off-by: Itxaka <igarcia@suse.com>
2022-12-15 13:57:04 +01:00
Francesco Giudici 4e31fe2fe7
Kubebuilder: fix MachineRegistration search during registration (#280) (#293)
* operator: fix MachineSelector controller log

* operator: fix MachineRegistration search in registration
Fixes #292

Backport from the controller_runtime branch:
#280 

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-12-14 15:36:11 +00:00
Itxaka 7b8af5995f
Send full system data on registration (#276) 2022-12-14 16:23:15 +01:00
Alexander Demicev ebca28f734
Remove invalid conditions from objects (#284) 2022-12-12 14:14:50 +00:00
Alexander Demicev c4b8e2d596 Merge all main logic in one file (#270) 2022-12-12 12:15:22 +01:00
Francesco Giudici 358ddbc8fc [controller_runtime] add registration protocol version (#266)
Fixes: #265 

* registration: negotiate registration protocol

* operator: always update the MachineInventory for authenticated clients

* register: rename sendData to sendSMBIOSdata

* register: rework the Register() function

* operator: rework the registration protocol loop

* operator: no need to return the msgType from the registration loop

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-12-12 12:15:22 +01:00
Alexander Demicev b4649dd363 Kubebuilder: Remove unused code (#267)
* Remove unused code

* Run make vendor
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 d3cefe36eb Add a rate limiter to managedosversionchannel reconciler (#260)
This commit adds a rate limiter to the ManagedOSVersionChannel controller to prevent
stacking reconcile loops over the same resource in fast rates (doesn't make sense for a
ManagedOSVersionChannel). By default the controller runtime already includes an
equivalent rate limiter, but starts in the range of milliseconds, starting the exponential
rate limiter in the range of seconds is more than enough in this context.

In addition it drops the failures counter in the resource. This counter was supposed to
be used to limit the number attempts to sync in case of failure. This was a bad design,
status should not keep a counter like this as any change in status triggers a new
immediate reconcile loop, hence the counter was reaching the maximum as fast as the
controller runtime was executing reconcile loops without any rate limiter (rate limiter
applies only when there are no changes including status).

For now I think we can just live without the setting any maxium for failures. If we ever
need it I believe it should be coded and tracked within the controller itself, not in each
resource as this prevents the reconcile loop of being idempotent. Alternatively we could
prevent triggering the reconcile loop on status changes, however this prevents
reconciling if any third party (or user from the kubectl client) changes a resource status.

Fixes #257
Part of #240

Signed-off-by: David Cassany <dcassany@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
David Cassany Viladomat f3aba7f2ae Improve syncer (#252)
This commit adds few changes on the syncer logic:

* Makes use of ManagedOSVersionChannel status reason to track if there
  is an on going synchronization rather than polling for the existence of a synchronization pod or not.

* Adds a logic to stop trying to synchronize after 4 consecutive attempts.
  If it exceeds the maximum it just programs the next re-sync after the given sync
  interval instead of immediately retrying.

* Adds some logging and comments here and there.

Signed-off-by: David Cassany <dcassany@suse.com>
2022-12-12 12:15:22 +01:00
David Cassany Viladomat eeb07166c6 New syncer logic (#245)
* Implement syncer logic as part of the ManagedOSVersionChannel controller

  This commit adds the logic to synchronize managedosversionchannels
  within the already existing controller.

* make generate
* make build-manifests
* Update chart
* update e2e tests

Signed-off-by: David Cassany <dcassany@suse.com>
2022-12-12 12:15:22 +01:00
Alexander Demicev 0edac91853 Add remaining controllers (#232)
* Update vendor

* Run generation tasks

* Minor fixes in Makefile

* Remove old code

* Add remaning controllers

* Minor e2e tests improvements

* Switch osversionchannel syncer to controll runtime

* Minor fixes in controllers

* Fix unit tests
2022-12-12 12:15:22 +01:00
Alexander Demicev 5473f97262 Kubebuilder: Add machine inventory selector controller (#224)
* Add machine inventory selector controller

* Remove old machine inventory selector code
2022-12-12 12:15:22 +01:00
Alexander Demicev eca526f5ca Kubebuilder: Add machine inventory controller (#221)
* Add machine inventory controller

* Remove old code

* Add managed label to created secret
2022-12-12 12:15:22 +01:00
Alexander Demicev e1dc2202b6 Kubebuilder: Add machine registration controller (#206)
* Add new package to Dockerfile

* Update dependencies

* Add unit test helpers

* Add new machine registration controller

* Remove old machine registration controller

* Add rbac tag for secrets

* Fix container argument in chart

* Add labels to all created resources
2022-12-12 12:15:22 +01:00
Fredrik Lönnegren 5c8f6bf898
Change yaml-marshalling of node-labels file (#287)
The '+' is not a typo. Changing to use gopkg.in/yaml.v2 as it respects
yaml-tags on structs.

Example of valid file:

```yaml
node-label+:
- name=hostname
- elemental/label=test
```

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

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2022-12-09 09:36:19 +01:00
Fredrik Lönnegren 9e222dbcc4
Remove yaml typo (#286) 2022-12-06 15:01:04 +00:00
David Cassany Viladomat a13601fa00
Add helm labels and annotations to all crds (#281)
Signed-off-by: David Cassany <dcassany@suse.com>
2022-12-05 13:46:16 +00:00
Alexander Demicev 82ba9fe678
Set helm labels on CRDs (#277) 2022-12-02 14:55:09 +01:00
Itxaka 69a8c52282
Use custom names in upgrade objects (#254) 2022-11-21 14:35:21 +01:00
Itxaka e20440c681
Propagate inventory labels to node on bootstrap plan (#243)
Inventory labels are not propagated from the inventory into the node so
they are pretty useless for things like upgrades.

This patch fixes it by using the override yaml in the node k3s/rke2
configuration to append node labels obtained from the inventory

Signed-off-by: Itxaka <igarcia@suse.com>

Signed-off-by: Itxaka <igarcia@suse.com>
2022-11-11 13:49:38 +01:00
Itxaka 221af672d7
Add codeql + escape user input before processing (#237)
* Create codeql.yml

Signed-off-by: Itxaka <igarcia@suse.com>

* Escape user input before processing it

Signed-off-by: Itxaka <igarcia@suse.com>

Signed-off-by: Itxaka <igarcia@suse.com>
2022-11-09 09:39:27 +01:00
David Cassany Viladomat ee61cd3bab
Stop elemental-system-agent when the node is ready (#231)
Signed-off-by: David Cassany <dcassany@suse.com>
2022-10-26 18:10:05 +02:00
Francesco Giudici 0c64b49a1c operator: improve logging of the MachineRegistration controller
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-10-20 09:12:45 +02:00
Francesco Giudici 27b3359122 operator: move ServiceAccount creation to a separate func
The OnChange function of the MachineRegistration controller is becoming
too packed: move the ServiceAccount and associated Secret creation and
management in a separate function

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-10-20 09:12:45 +02:00
Francesco Giudici a33da016c3 operator: drop duplicated import
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-10-20 09:12:45 +02:00
Francesco Giudici 05800af134 operator: enforce ServiceAccount's Secret link
If the ServiceAccount for the newly created MachineRegistration
is already there, ensure it has a link to the newly created  Secret

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-10-20 09:12:45 +02:00
Francesco Giudici 3425236341 operator: create ServiceAccounts before their Secrets
A Secret referencing a missing ServiceAccount will be deleted.
While we create them one after the other, still the safest path is
to create the ServiceAccount first. Otherwise we may be exposed to
a race condition in which:
1. We create the Secret referencing an unexistent ServiceAccount
2. The Secret controller will detect a Secret referencing an unexistent
   ServiceAccount and will mark it for deletion
3. The ServiceAccount is created with the reference to the Secret
4. The Secret gets removed from the controller: the controller also
   updates the ServiceAccount removing the linked Secret

Fixes #197

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-10-20 09:12:45 +02:00
Francesco Giudici d466e048a7
operator: unit-tests: add coverage for unauthenticatedResponse() (#217)
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-10-20 08:55:42 +02:00
Francesco Giudici 937d35b527
Elemental Operator: manage empty config in MachineRegistrations (#213)
* operator: manage empty config in MachineRegistrations

We don't deal with empty Spec:Config in MachineRegistrations: in that
case we would end up with a nil Config structure, which we don't check
causing the operator to panic.

Just check and deal with empty (nil) MachineRegistration config.

Fixes #202

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

* operator:trivial: rename var machineRegistration to registration

In order to manage a MachineRegistration resource we instantiate a var named
'registration' in all the functions of the server package,  but in the
'unauthenticatedResponse' function.
Let's stay coherent: rename the variable.

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

* operator: tests: expand the data structure TestInitNewInventory

This has no functional change: just extend the configuration parameter
that can be set in the data structure used for the tests.
Make use of it in the following commit.

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

* operator: tests: check empty config in MachineRegistrations

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-10-18 14:52:36 +02:00
Michal Jura 98c9bff048
Label other objects created by elemental-operator (#216)
Label objects created by elemental-operator with
    "elemental.cattle.io/managed": "true"

It will used by rancher-backup operator to filter these object and
create proper backup from them.

Fixes https://github.com/rancher/elemental/issues/435

Signed-off-by: Michal Jura <mjura@suse.com>

Signed-off-by: Michal Jura <mjura@suse.com>
2022-10-18 14:30:00 +02:00
Michal Jura 3dea2f3f8e
Label secrets managed by elemental-operator (#212)
Mark secrets created and managed by elemental-operator.
It is needed for rancher-backup opeator to select them for backup.

Fixes https://github.com/rancher/elemental/issues/396

Signed-off-by: Michal Jura <mjura@suse.com>

Signed-off-by: Michal Jura <mjura@suse.com>
2022-10-17 07:22:54 +02:00
David Cassany Viladomat cdf406ef81
Allow custom config files for elemental-cli (#210)
* Allow custom config files for elemental-cli
* Update vendor folder

Signed-off-by: David Cassany <dcassany@suse.com>
2022-10-14 10:42:13 +02:00
Francesco Giudici 3a3b4e3c94
operator: drop duplicated import of elemental APIs (#199)
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-10-07 15:25:12 +02:00
Alexander Demicev 8375d083c1
Add reasons for conditions (#185) 2022-10-03 10:47:10 +02:00
Itxaka 72f9347a6b
lint: dont overshadow var (#172)
Signed-off-by: Itxaka <igarcia@suse.com>

Signed-off-by: Itxaka <igarcia@suse.com>
2022-09-26 08:58:23 +00:00
Francesco Giudici 0da0ac126f operator: log the creation of a new registration token
this allow to track the creation of MachineRegistration resources

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-09-23 15:29:07 +02:00
Francesco Giudici ea712b2c0a operator: explicitly add Secrets to registration ServiceAccounts
With Kubernetes 1.24, creation of ServiceAccounts no more triggers
the creation of an associated Secret resource automatically: we need
it for the ServiceAccount bound to the MachineRegistation resources.
Explicitly create it in any case.

Fixes #176

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-09-23 15:29:07 +02:00