Try to fix hooks (#718)

* fix hooks


---------

Signed-off-by: Itxaka <itxaka@kairos.io>
This commit is contained in:
Itxaka
2025-03-24 16:05:39 +01:00
committed by GitHub
parent 06aa2ce4e4
commit db703db5e5
12 changed files with 217 additions and 210 deletions

View File

@@ -270,7 +270,7 @@ func (i InstallAction) Run() (err error) {
return err
}
err = hook.Run(*i.cfg, i.spec, hook.EncryptionHooks...)
err = hook.Run(*i.cfg, i.spec, hook.PostInstall...)
if err != nil {
return err
}
@@ -307,5 +307,5 @@ func (i InstallAction) Run() (err error) {
_ = utils.RunStage(i.cfg, "kairos-install.after")
_ = events.RunHookScript("/usr/bin/kairos-agent.install.after.hook") //nolint:errcheck
return hook.Run(*i.cfg, i.spec, hook.AfterInstall...)
return hook.Run(*i.cfg, i.spec, hook.FinishInstall...)
}

View File

@@ -399,7 +399,7 @@ func NewUpgradeSpec(cfg *Config) (*v1.UpgradeSpec, error) {
}
if spec.Active.Source.IsDocker() {
cfg.Logger.Infof("Checking if OCI image %s exists", spec.Active.Source.Value())
cfg.Logger.Infof("Checking if OCI image %s exists", spec.Active.Source.Value())
_, err := crane.Manifest(spec.Active.Source.Value())
if err != nil {
if strings.Contains(err.Error(), "MANIFEST_UNKNOWN") {

View File

@@ -199,7 +199,7 @@ func (i *InstallAction) Run() (err error) {
i.cfg.Logger.Warnf("selecting active boot entry: %s", err.Error())
}
err = hook.Run(*i.cfg, i.spec, hook.UKIEncryptionHooks...)
err = hook.Run(*i.cfg, i.spec, hook.PostInstall...)
if err != nil {
i.cfg.Logger.Errorf("running uki encryption hooks: %s", err.Error())
return err
@@ -223,7 +223,7 @@ func (i *InstallAction) Run() (err error) {
i.cfg.Logger.Errorf("running kairos-uki-install.after hook script: %s", err.Error())
}
return hook.Run(*i.cfg, i.spec, hook.AfterUkiInstall...)
return hook.Run(*i.cfg, i.spec, hook.FinishUKIInstall...)
}
func (i *InstallAction) SkipEntry(path string, conf map[string]string) (err error) {

View File

@@ -2,7 +2,6 @@ package uki
import (
"fmt"
"github.com/kairos-io/kairos-agent/v2/pkg/action"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/constants"
@@ -35,14 +34,12 @@ func (r *ResetAction) Run() (err error) {
cleanup := utils.NewCleanStack()
defer func() { err = cleanup.Cleanup(err) }()
// Unmount partitions if any is already mounted before formatting
err = e.UnmountPartitions(r.spec.Partitions.PartitionsByMountPoint(true))
if err != nil {
r.cfg.Logger.Errorf("unmounting partitions: %s", err.Error())
return err
}
// At this point, both partitions are unlocked but they might not be mounted, like persistent
// And the /dev/disk/by-label are not pointing to the proper ones
// We need to manually trigger udev to make sure the symlinks are correct
_, err = utils.SH("udevadm trigger --type=all || udevadm trigger")
_, err = utils.SH("udevadm settle")
// Reformat persistent partition
if r.spec.FormatPersistent {
persistent := r.spec.Partitions.Persistent
if persistent != nil {
@@ -58,11 +55,20 @@ func (r *ResetAction) Run() (err error) {
if r.spec.FormatOEM {
oem := r.spec.Partitions.OEM
if oem != nil {
err = e.UnmountPartition(oem)
if err != nil {
return err
}
err = e.FormatPartition(oem)
if err != nil {
r.cfg.Logger.Errorf("formatting OEM partition: %s", err.Error())
return err
}
// Mount it back, as oem is mounted during recovery, keep everything as is
err = e.MountPartition(oem)
if err != nil {
return err
}
}
}
@@ -101,14 +107,6 @@ func (r *ResetAction) Run() (err error) {
return err
}
if mnt, err := elementalUtils.IsMounted(r.cfg, r.spec.Partitions.OEM); !mnt && err == nil {
err = e.MountPartition(r.spec.Partitions.OEM)
if err != nil {
r.cfg.Logger.Errorf("mounting oem partition: %s", err.Error())
return err
}
}
err = Hook(r.cfg, constants.AfterResetHook)
if err != nil {
r.cfg.Logger.Errorf("running after install hook: %s", err.Error())