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

@@ -1,48 +1,54 @@
package hook
import (
"fmt"
config "github.com/kairos-io/kairos-agent/v2/pkg/config"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
"github.com/kairos-io/kairos-sdk/utils"
"strings"
)
type Interface interface {
Run(c config.Config, spec v1.Spec) error
}
var AfterInstall = []Interface{
&GrubOptions{}, // Set custom GRUB options
&BundlePostInstall{},
&CustomMounts{},
&CopyLogs{},
// FinishInstall is a list of hooks that run when the install process is finished completely.
// Its mean for options that are not related to the install process itself
var FinishInstall = []Interface{
&GrubOptions{}, // Set custom GRUB options in OEM partition
&Lifecycle{}, // Handles poweroff/reboot by config options
}
// FinishReset is a list of hooks that run when the reset process is finished completely.
var FinishReset = []Interface{
&CopyLogs{}, // Try to copy the reset logs to the persistent partition
&Lifecycle{}, // Handles poweroff/reboot by config options
}
var AfterReset = []Interface{
&CopyLogs{},
&Lifecycle{},
}
var AfterUpgrade = []Interface{
&Lifecycle{},
// FinishUpgrade is a list of hooks that run when the upgrade process is finished completely.
var FinishUpgrade = []Interface{
&Lifecycle{}, // Handles poweroff/reboot by config options
}
// FirstBoot is a list of hooks that run on the first boot of the node.
var FirstBoot = []Interface{
&BundleFirstBoot{},
&GrubPostInstallOptions{},
}
// AfterUkiInstall sets which Hooks to run after uki runs the install action
var AfterUkiInstall = []Interface{
&SysExtPostInstall{},
&Lifecycle{},
// FinishUKIInstall is a list of hooks that run when the install process is finished completely.
// Its mean for options that are not related to the install process itself
var FinishUKIInstall = []Interface{
&SysExtPostInstall{}, // Installs sysexts into the EFI partition
&Lifecycle{}, // Handles poweroff/reboot by config options
}
var UKIEncryptionHooks = []Interface{
&KcryptUKI{},
}
var EncryptionHooks = []Interface{
&Kcrypt{},
// PostInstall is a list of hooks that run after the install process has run.
// Runs things that need to be done before we run other post install stages like
// encrypting partitions, copying the install logs or installing bundles
// Most of this options are optional so they are not run by default unless specified int he config
var PostInstall = []Interface{
&Finish{},
}
func Run(c config.Config, spec v1.Spec, hooks ...Interface) error {
@@ -53,3 +59,18 @@ func Run(c config.Config, spec v1.Spec, hooks ...Interface) error {
}
return nil
}
// lockPartitions will try to close all the partitions that are unencrypted.
func lockPartitions(c config.Config) {
for _, p := range c.Install.Encrypt {
_, _ = utils.SH("udevadm trigger --type=all || udevadm trigger")
c.Logger.Debugf("Closing unencrypted /dev/disk/by-label/%s", p)
out, err := utils.SH(fmt.Sprintf("cryptsetup close /dev/disk/by-label/%s", p))
// There is a known error with cryptsetup that it can't close the device because of a semaphore
// doesnt seem to affect anything as the device is closed as expected so we ignore it if it matches the
// output of the error
if err != nil && !strings.Contains(out, "incorrect semaphore state") {
c.Logger.Debugf("could not close /dev/disk/by-label/%s: %s", p, out)
}
}
}