kairos-io / kairos

:penguin: The immutable Linux meta-distribution for edge Kubernetes.
https://kairos.io
Apache License 2.0
1.09k stars 96 forks source link

:sparkles: Improve yip logging #797

Open mauromorales opened 1 year ago

mauromorales commented 1 year ago

Is your feature request related to a problem? Please describe.

The logs from elemental cli journalctl -t elemental can be a bit hard to consume. For example, the following stage inside /system/oem/04_installer.yaml

    boot:
     - if: |
           [ "$(kairos-agent state get boot)" == "livecd_boot" ] && [ -f "/sbin/openrc" ]
       commands:
       - rc-service kairos-webui start
     - if: |
           [ "$(kairos-agent state get boot)" == "livecd_boot" ] && [ -d "/usr/share/systemd" ]
       commands:
       - systemctl start kairos-webui

Can produce the following output:

Applying 'Start installer on tty1' for stage 'boot'. Total stages: 2
Error 'Skipping stage (if statement didn't passed)' in stage name: Start installer on tty1 stage: boot
Error 'Skipping stage (if statement didn't passed)' in stage name: Start installer on tty1 stage: boot

Which doesn't tell me if, this is an issue and requires that I go into the yaml file to get an idea of which are those "if statements that did not pass"

Describe the solution you'd like

First of all, I'd expect those 2 stages considered as only 1 since it is not a different stage, it's just a different implementation depending on the init system in use.

Then I'd expect some logic like the following:

  1. If the result of $(kairos-agent state get boot)" == "livecd_boot" is false, I'd expect to get only an info log, not an error one, saying something along the lines of "State is not livecd_boot, skipping"
  2. If the state is livecd_boot and one of the two branches runs, then I'd expect to see nothing or an info log expressing that it was successful (only once)
  3. If the state is live_cd_boot and none of the branches run, then I'd expect to see an error log expressing that it was not successful (only once)

Describe alternatives you've considered

Additional context

Itxaka commented 1 year ago

FYI, IIRC this comes from yip directly mudler/yip rather than elemental-cli. And if I further remember correctly, for yip there is no difference between the IF check failing or the IF check being wrong. Elemental just provides the logger to the yip runner, so changes should go into yip instead.