feat(installation): allow to abort installation if sentinel file is present

Signed-off-by: mudler <mudler@localai.io>
This commit is contained in:
mudler
2024-08-21 09:25:10 +02:00
parent f3601ef61d
commit 75ff3cbdd4
4 changed files with 87 additions and 64 deletions

View File

@@ -189,6 +189,11 @@ func (i InstallAction) Run() (err error) {
return err
}
// Check if we should fail the installation by checking the sentinel file FailInstallationFileSentinel
if toFail, err := utils.CheckFailedInstallation(cnst.FailInstallationFileSentinel); toFail {
return err
}
// Deploy active image
systemMeta, err := e.DeployImage(&i.spec.Active, true)
if err != nil {

View File

@@ -80,6 +80,7 @@ const (
TransitionImgFile = "transition.img"
RunningStateDir = "/run/initramfs/cos-state" // TODO: converge this constant with StateDir/RecoveryDir in dracut module from cos-toolkit
RunningRecoveryStateDir = "/run/initramfs/isoscan" // TODO: converge this constant with StateDir/RecoveryDir in dracut module from cos-toolkit
FailInstallationFileSentinel = "/run/cos/fail_installation"
ActiveImgName = "active"
PassiveImgName = "passive"
RecoveryImgName = "recovery"

View File

@@ -84,6 +84,11 @@ func (i *InstallAction) Run() (err error) {
return err
}
// Check if we should fail the installation by checking the sentinel file FailInstallationFileSentinel
if toFail, err := utils.CheckFailedInstallation(constants.FailInstallationFileSentinel); toFail {
return err
}
// Store cloud-config in TPM or copy it to COS_OEM?
// Copy cloud-init if any
err = e.CopyCloudConfig(i.spec.CloudInit)

View File

@@ -609,3 +609,15 @@ func SystemdBootConfWriter(fs v1.FS, filePath string, conf map[string]string) er
return writer.Flush()
}
// CheckFailedInstallation checks if the state file if present, and if it is, it will return true and the error with the file content indicating why we should abort the installation
func CheckFailedInstallation(stateFile string) (bool, error) {
if _, err := os.Stat(stateFile); err == nil {
content, err := os.ReadFile(stateFile)
if err != nil {
return true, err
}
return true, fmt.Errorf("Installation failed: %s", string(content))
}
return false, nil
}