Commit Graph

430 Commits

Author SHA1 Message Date
Francesco Giudici fda53de0e2
Kubebuilder: fix MachineRegistration search during registration (#280)
* operator: fix MachineSelector controller log

* operator: fix MachineRegistration search in registration

Fixes #279

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-12-02 16:13:34 +01:00
Francesco Giudici 5fc15fa0d6
operator: don't try to patch an empty MachineInventory (#274)
just skip and update the status to show we are waiting for the
inventory.

Fixes #273

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-12-01 19:04:12 +01:00
Alexander Demicev 087bdbd14f
Backport minor fixes (#271) 2022-12-01 18:42:52 +01:00
Alexander Demicev 9c212ea32a
Merge all main logic in one file (#270) 2022-12-01 14:59:11 +01:00
David Cassany Viladomat ff661e086f
Change the helm chart oci reference to be aligned with other elemental images (#268) (#269)
Signed-off-by: David Cassany <dcassany@suse.com>
(cherry picked from commit 242f3cc3ef)
2022-11-30 12:27:09 +01:00
Francesco Giudici 8c1e1df563
[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-11-29 18:08:15 +01:00
Alexander Demicev 8283d03496
Kubebuilder: Remove unused code (#267)
* Remove unused code

* Run make vendor
2022-11-29 12:29:55 +01:00
Francesco Giudici 5df274078b
[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-11-28 17:34:47 +01:00
Michal Jura 7b2bebb68e
Refactor ManagedOsImage e2e tests (#263)
Fix: https://github.com/rancher/elemental-operator/issues/240

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

Signed-off-by: Michal Jura <mjura@suse.com>
2022-11-23 13:51:10 +01:00
David Cassany Viladomat 5757f2d82f
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-11-22 15:40:15 +01:00
Michal Jura 26f70f371a
Refactor MachineRegistration e2e tests (#253)
Fixes rancher#240

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

Signed-off-by: Michal Jura <mjura@suse.com>
2022-11-21 16:05:11 +01:00
David Cassany Viladomat c18f66d8b8
Drop requeuer, not needed anymore (#255)
* Drop requeuer, not needed anymore
* Improve logging

Signed-off-by: David Cassany <dcassany@suse.com>
2022-11-21 12:37:14 +01:00
David Cassany Viladomat 5b68534515
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-11-18 14:33:12 +01:00
David Cassany Viladomat ed268ce451
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-11-16 18:38:23 +01:00
Alexander Demicev 87857f47cb
Fix make verify (#248) 2022-11-15 12:06:48 +01:00
Francesco Giudici 7b3a13dd7a
controller: add Secret name reference to the ServiceAccount (#247)
Otherwise we will have no Secrets in the ServiceAccount for kubernetes
clusters >= 1.24

Fixes: #246

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-11-15 11:04:45 +01:00
Alexander Demicev aee446d309
Kubebuilder: Add "verify" workflow (#244)
* Add new verify tasks

* Fix go mod
2022-11-11 14:37:03 +01:00
Alexander Demicev db7d0dd68e
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-11-10 11:26:34 +01:00
Alexander Demicev d553a0883d Kubebuilder: Add machine inventory selector controller (#224)
* Add machine inventory selector controller

* Remove old machine inventory selector code
2022-10-27 12:30:03 +02:00
Alexander Demicev c81f50ba93 Kubebuilder: Add remaining API types (#225)
* Add remaining API types

* Run generate tasks
2022-10-27 12:29:27 +02:00
Alexander Demicev 3d5da19c60 Kubebuilder: Add machine inventory controller (#221)
* Add machine inventory controller

* Remove old code

* Add managed label to created secret
2022-10-27 12:29:24 +02:00
Alexander Demicev 0fde15069d 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-10-27 12:28:55 +02:00
Alexander Demicev 286e163838 Kubebuilder: Run new code and generate RBAC (#203)
* Add new command for running kubebuilder based code

* Add make task for generating RBAC from code

* Add new directory to makefile
2022-10-27 12:27:35 +02:00
Alexander Demicev 03988e1ef8 Kubebuilder: Add make tasks for different tools (#194)
* Add tools binaries to Makefile

* Run make generate

* Update github workflows

* Impove path to tools
2022-10-27 12:27:27 +02:00
Alexander Demicev 13101d3acf Add kubebuilder API definitions (#184) 2022-10-27 12:25:53 +02: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
Itxaka e394356498
Fix docker and gorelease jobs (#230) 2022-10-25 16:17:52 +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 3387971d8d
coverity: make patch status informational (#219)
...so, it should not block the merging.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-10-20 08:45:20 +02:00
Itxaka 4dc57ca988
tests: Add k8s 1.24 and default to rancher 2.6.9 (#220) 2022-10-19 17:22:32 +02:00
Itxaka 2e2b5a2034
tests: use latest url for rancher charts (#218) 2022-10-19 15:57:51 +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
David Cassany Viladomat 7ea38a7df1
Only read yaml files included in the given directories (#215)
Signed-off-by: David Cassany <dcassany@suse.com>

Signed-off-by: David Cassany <dcassany@suse.com>
2022-10-18 10:27:18 +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
Alexander Demicev 9c1d506fa9
Collect operator logs after running tests (#204) 2022-10-11 17:26:10 +02:00
Michal Jura fc1810baf7
Audit and update elemental-operator RBAC ClusterRole (#196)
It seems that elemental-operator RBAC ClusterRole was too wide.
This change is simplifying it and removing unneeded privileges.

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

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

Signed-off-by: Michal Jura <mjura@suse.com>
2022-10-11 14:12:42 +02:00
Alexander Demicev 61749bd8c6
Add config for e2e tests (#201)
* Add e2e test config

* Switch to using test config

* Update vendor

* Fix lint issues

* Change rancher namespace variable name

* Put do nothing test back
2022-10-11 13:03:01 +02:00
David Cassany Viladomat 0cbf036390
Add OBS workflow to update elemental-operator package (#200)
Signed-off-by: David Cassany <dcassany@suse.com>

Signed-off-by: David Cassany <dcassany@suse.com>
2022-10-10 09:26:27 +02:00
David Cassany Viladomat 1af1d0709e
Add vendor for obs integration (#198)
These changes are required to facilitate OBS code updates and builds by simply triggering OBS services. This allows updating code and rebuild in OBS based on github events such as on tag, on merge, on push...

Signed-off-by: David Cassany <dcassany@suse.com>
2022-10-07 14:23:11 +00:00
Itxaka 0253a89df6
release: enhance release pipeline (#195)
- publish only binaries instead of a tar.gz of the binaries bundle
 - create SBOM as part of the gorelease pipeline
 - use github changelog for the release
 - sign ALL the things. Binaries, checksum, and even the SBOM
 - release also the cert+sig of the generated artifacts

Signed-off-by: Itxaka <igarcia@suse.com>
2022-10-07 15:26:46 +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
Itxaka 270236168b
Disable CGO under arm for register binaries + restore SBOM (#193) 2022-10-04 15:43:09 +02:00
Itxaka 4816d7b41e
Revert "Add sbom to releases and attach to containers" (#191) 2022-10-04 09:32:50 +02:00