Commit Graph

49 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 de3c37dfc6
RBAC: restrict SeedImage controller auth to fleet-default (#864)
* RBAC: restrict SeedImage controller auth to fleet-default

do not allow the seedimage-controller to operate on pods, services and
configmaps outside of the fleet-default namespace.

Fixes #457

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

* RBAC: move all rbac resources to rbac.yaml

Also have all of them collected and generated via kustomize

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

---------

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-10-07 09:23:50 +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
Fredrik Lönnegren 2bd467f301
Allow cross build of seed-image ISOs (#728)
* Allow cross build of seed-image ISOs

This commit makes use of the targetPlatform field on the seedImage spec
to allow building ISOs for different architectures.

It does this by spawning the initContainer using the seedImageBuilder
image and using the `elemental pull-image --platform=` command to
download the correct ISO and copies it to the attached volume.

One drawback of this approach is we don't get the caching of images in
the container runtime that we get when building natively.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-05-16 16:02:39 +02:00
Francesco Giudici 5f2b96c299
seedimage: clean-up service on image download deadline (#719)
* seedimage: clean-up service on image download deadline

We used to just clean-up the Pod carrying the built image when hitting
the cleanupAfterMinutes deadline.
There is no need to leave the Service around, clean that up too.

Fixes #704

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

* Update controllers/seedimage_controller.go

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

---------

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
Signed-off-by: Francesco Giudici <francesco.giudici@gmail.com>
Co-authored-by: Fredrik Lönnegren <fredrik.lonnegren@gmail.com>
2024-05-07 07:38:37 +00:00
Francesco Giudici a43c150c82
seedimage: use ClusterIP Services (#709)
When building an ISO, we create a Pod and a Service to expose the built
ISO when ready.
The link to the ISO is then exposed through the Elemental Operator
Deployment, that acts as an Ingress.
The Service we create to expose the Pod port is of type NodePort: this
is not needed,is just a leftover from the initial implementations, where
we usede to expose a "direct" link to the Pod.
No need to keep a NodePort service now, let's have a ClusterIP Service
type instead.

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

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2024-04-22 09:35:45 +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
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
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 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 3a118225c6 SeedImage builder arguments in wrong order
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-02-13 10:01:19 +01:00
Fredrik Lönnegren eac1747f33 Update seedimage build-disk command
The --unprivileged flag was removed and --system was added.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-02-02 13:46:46 +01:00
Fredrik Lönnegren 06f9d2cad8
Update copyright year (2024)
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-01-05 11:04:56 +01:00
Fredrik Lönnegren 468ae4de45 Change raw SeedImage deploy-command
Use the service included in elemental instead of directly triggering
elemental-register.

This will make sure all needed dependencies are started before
registering the system.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-01-05 11:00:28 +01:00
Fredrik Lönnegren ba56f153aa Add TargetPlatform to SeedImageSpec
TargetPlatform is used when building raw disk-images for other
platforms. An example being building rpi images on a cluster running on
x86_64 hardware.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2023-12-21 13:10:38 +01:00
Fredrik Lönnegren c546933825
Build raw disk images in SeedImage (#557)
* feat: Add Type field to SeedImageSpec

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

* feat: Add raw disk build generation to SeedImage

If SeedImageSpec.Type is set to 'raw' we now try to run elemental
build-disk to generate the disk image.

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

* Add elemental-toolkit to seedimage-builder

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

* feat: Update yip to v1.4.5

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

* feat: Reset yaml

Add yip cloud-config for raw disk-image that will extract the
elemental-register configuration to /oem/registration/config.yaml and
Start the elemental-register-install.service in the post-reset hook.

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

* feat: Use new toolkit param deploy-command

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

---------

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2023-11-20 17:28:09 +01:00
Fredrik Lönnegren caa63f883c Keep old output-name
When a seedimage resource is reconciled the output-name should stay the
same since it's mounted into a pod and the pod will not pick up changes
automatically.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2023-10-26 12:30:11 +02:00
Fredrik Lönnegren b998a98ffb
Bring your own SeedImage builder (#542)
* Bring your own SeedImage builder

This commit adds functionality to define which build-image to use for a
SeedImage. If no build-image is provided the default one is used.

The BuildContainer only takes Name, Image, ImagePullPolicy, Args and
Command in order to limit what the user is able to do.

The user-defined build container will also mount a ConfigMap with
environment variables for device, base-image, registration-url and
ISO output-name.

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

* feat: Add Size to SeedImageSpec

Size is used to calculate ephemeral resource requests when building the
seed-image.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2023-10-25 13:54:34 +00: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 24a5fdd972 Recreate service account token secret if missing
This commit checks on each reconcile loop if the service
account token secret is missing despite being on ready
state.

In addition it also adds optimistic locking for patch calls. The
motivations is to prevent concurrent controllers to modify
outdated data.

Signed-off-by: David Cassany <dcassany@suse.com>
2023-07-24 09:46:26 +02:00
Francesco Giudici 4f3b2c59da
operator: copy cloud-config file not its link (#468)
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-06-20 15:28:36 +02:00
Francesco Giudici 25cb8fb3de SeedImage: manage updates of builder Pod under deletion
If the Pod get scheduled to be deleted but the status is not updated
before the Pod reconcile loop, we may end up updating the status to
SeedImageReady to true as we found the Pod still running.
This commit adds a check if the Pod is marked for deletion: if so, let's
wait.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-05-26 15:54:10 +02:00
Francesco Giudici e9094174be SeedImage: add ResourcesNotCreatedYet Ready condition
Track when the SeedImage child resources are not created (yet).

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-05-26 15:54:10 +02:00
Francesco Giudici 19d94a8088 SeedImage: reset download URL on Pod deletion
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-05-26 15:54:10 +02:00
Francesco Giudici c7d4910176 SeedImage: allow the controller full control on configmaps
This is needed to update the configmap associated with the builder pod,
which contains registration and cloud-init data for the ISO.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-05-26 15:54:10 +02:00
Francesco Giudici d53eb7ccbb SeedImage: isolate all the config map logic in a separate function
Move the checks of the config map containing the registration data in
the createConfigMapObject() function (renamed to
reconcileConfigMapObject().
Moreover, while there, check the data included in the config map: if it
is no more up-to-date, rebuild the config map.

Fixes #456

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-05-26 15:54:10 +02:00
Francesco Giudici e330dc7718 SeedImage: on retriggerBuild delete owned SeedImage resources
Delete immediately the builder pod and the associated service, just
after resetting the conditions.

Fixes #452

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-05-26 15:54:10 +02:00
Francesco Giudici 7b16cc8bb5 SeedImage: drop redundant set of retriggerBuild
Early in the reconcile group there is a check on the retriggerBuild field:
in case it is true, conditions are reset and retriggerBuild is immediatly set
to false.
Drop the following sets / checks as they are redundant.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-05-26 15:54:10 +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 48e2ca22ce SeedImage: inject MachineRegistration and date in the built iso name
Previously, the built iso name was a static 'elemental.iso'.
Now, the referenced MachineRegistration and the time in RFC3339 format
are part of the built iso name.

elemental-{MachineRegistration Name}-{RFC3339 date}.iso

es: elemental-myreg-2023-04-19T13:48:50.52Z.iso

Moreover, take advantage of the new httpfy functionality and pass it the
full name of the generated iso file to be served independently of the
URL in the request.

Drop also the static "elemental.iso" from the generated download URL.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-04-20 18:01:37 +02:00
Francesco Giudici 56f14ec493 SeedImage: pass whole SeedImage reference to fillBuildImagePod
This allows to reduce the number of passed parameters and so increase
code readability.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-04-20 18:01:37 +02:00
Francesco Giudici 98c5692306 SeedImage: add more seedimage_controller tests
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-04-18 15:31:27 +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
Francesco Giudici 4ad11be834 SeedImage: controller logic for the pod cleanup/retrigger
Fixes: #397

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-04-18 15:31:27 +02:00
Francesco Giudici a865050894 SeedImage: add image timeout and retrigger fields
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 6b1522e4c9 SeedImage: retrieve MachineRegistration just once
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-04-14 09:45:40 +02:00
Francesco Giudici 08bc407577 SeedImage: set OwnerReferences
Set it owned by the MachineRegistration referenced in the Spec.

Fixes #420

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-04-14 09:45:40 +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
Francesco Giudici d50a14de55 SeedImage: busybox base64 decodes with -d only
The busybox version of base64 (which we use in our newer Seed Image
builder image) just takes the '-d' for decoding ('--decode' errors out).

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-03-28 10:07:35 +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 04e27f62a7
SeedImage: fix registration yaml name (#394)
Otherwise auto-install would not work:
----
rancher-7934:/system/oem # cat 99_elemental-register.yaml
name: "Elemental operator bootstrap"
stages:
  network.after:
    # run only if on live cd and there is a config file
    - if: '[ -f /run/cos/live_mode ] && [ -f
      /run/initramfs/live/livecd-cloud-config.yaml ]'
      commands:
        - systemd-cat -t elemental elemental-register --debug
	  /run/initramfs/live/

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-03-18 16:41:38 +01:00
Francesco Giudici 5c88eb144c SeedImage: move sync status with running pod to new func
This improves code readability... and makes linter happy :-)
There is also a slight change: when the build pod is in an unexpected
Phase (Success or Unknown) we don't recreate the pod anymore.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-03-17 13:29:46 +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 f78bf520f8 SeedImage: check conditions and return early when needed
No need to re-set the conditions at each reconcile loop when all has
been already done and is ready.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2023-03-15 09:40:29 +01:00
David Cassany 337354078b Stop using finalizers if not extrictly needed
Signed-off-by: David Cassany <dcassany@suse.com>
2023-03-14 15:48:49 +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