mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-04 02:24:42 +00:00
feat(installation): allow to abort installation if sentinel file is present
Signed-off-by: mudler <mudler@localai.io>
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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"
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user