mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-07 03:50:22 +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
|
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
|
// Deploy active image
|
||||||
systemMeta, err := e.DeployImage(&i.spec.Active, true)
|
systemMeta, err := e.DeployImage(&i.spec.Active, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -23,70 +23,71 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
GrubConf = "/etc/cos/grub.cfg"
|
GrubConf = "/etc/cos/grub.cfg"
|
||||||
GrubOEMEnv = "grub_oem_env"
|
GrubOEMEnv = "grub_oem_env"
|
||||||
GrubDefEntry = "Kairos"
|
GrubDefEntry = "Kairos"
|
||||||
DefaultTty = "tty1"
|
DefaultTty = "tty1"
|
||||||
BiosPartName = "bios"
|
BiosPartName = "bios"
|
||||||
EfiLabel = "COS_GRUB"
|
EfiLabel = "COS_GRUB"
|
||||||
EfiPartName = "efi"
|
EfiPartName = "efi"
|
||||||
ActiveLabel = "COS_ACTIVE"
|
ActiveLabel = "COS_ACTIVE"
|
||||||
PassiveLabel = "COS_PASSIVE"
|
PassiveLabel = "COS_PASSIVE"
|
||||||
SystemLabel = "COS_SYSTEM"
|
SystemLabel = "COS_SYSTEM"
|
||||||
RecoveryLabel = "COS_RECOVERY"
|
RecoveryLabel = "COS_RECOVERY"
|
||||||
RecoveryPartName = "recovery"
|
RecoveryPartName = "recovery"
|
||||||
StateLabel = "COS_STATE"
|
StateLabel = "COS_STATE"
|
||||||
StatePartName = "state"
|
StatePartName = "state"
|
||||||
InstallStateFile = "state.yaml"
|
InstallStateFile = "state.yaml"
|
||||||
PersistentLabel = "COS_PERSISTENT"
|
PersistentLabel = "COS_PERSISTENT"
|
||||||
PersistentPartName = "persistent"
|
PersistentPartName = "persistent"
|
||||||
OEMLabel = "COS_OEM"
|
OEMLabel = "COS_OEM"
|
||||||
OEMPartName = "oem"
|
OEMPartName = "oem"
|
||||||
MountBinary = "/usr/bin/mount"
|
MountBinary = "/usr/bin/mount"
|
||||||
EfiDevice = "/sys/firmware/efi"
|
EfiDevice = "/sys/firmware/efi"
|
||||||
LinuxFs = "ext4"
|
LinuxFs = "ext4"
|
||||||
LinuxImgFs = "ext2"
|
LinuxImgFs = "ext2"
|
||||||
SquashFs = "squashfs"
|
SquashFs = "squashfs"
|
||||||
EfiFs = "vfat"
|
EfiFs = "vfat"
|
||||||
EfiSize = uint(64)
|
EfiSize = uint(64)
|
||||||
OEMSize = uint(64)
|
OEMSize = uint(64)
|
||||||
PersistentSize = uint(0)
|
PersistentSize = uint(0)
|
||||||
BiosSize = uint(1)
|
BiosSize = uint(1)
|
||||||
ImgSize = uint(3072)
|
ImgSize = uint(3072)
|
||||||
HTTPTimeout = 60
|
HTTPTimeout = 60
|
||||||
LiveDir = "/run/initramfs/live"
|
LiveDir = "/run/initramfs/live"
|
||||||
RecoveryDir = "/run/cos/recovery"
|
RecoveryDir = "/run/cos/recovery"
|
||||||
StateDir = "/run/cos/state"
|
StateDir = "/run/cos/state"
|
||||||
OEMDir = "/run/cos/oem"
|
OEMDir = "/run/cos/oem"
|
||||||
PersistentDir = "/run/cos/persistent"
|
PersistentDir = "/run/cos/persistent"
|
||||||
ActiveDir = "/run/cos/active"
|
ActiveDir = "/run/cos/active"
|
||||||
TransitionDir = "/run/cos/transition"
|
TransitionDir = "/run/cos/transition"
|
||||||
EfiDir = "/run/cos/efi"
|
EfiDir = "/run/cos/efi"
|
||||||
RecoverySquashFile = "recovery.squashfs"
|
RecoverySquashFile = "recovery.squashfs"
|
||||||
IsoRootFile = "rootfs.squashfs"
|
IsoRootFile = "rootfs.squashfs"
|
||||||
ActiveImgFile = "active.img"
|
ActiveImgFile = "active.img"
|
||||||
PassiveImgFile = "passive.img"
|
PassiveImgFile = "passive.img"
|
||||||
RecoveryImgFile = "recovery.img"
|
RecoveryImgFile = "recovery.img"
|
||||||
IsoBaseTree = "/run/rootfsbase"
|
IsoBaseTree = "/run/rootfsbase"
|
||||||
AfterInstallChrootHook = "after-install-chroot"
|
AfterInstallChrootHook = "after-install-chroot"
|
||||||
AfterInstallHook = "after-install"
|
AfterInstallHook = "after-install"
|
||||||
BeforeInstallHook = "before-install"
|
BeforeInstallHook = "before-install"
|
||||||
AfterResetChrootHook = "after-reset-chroot"
|
AfterResetChrootHook = "after-reset-chroot"
|
||||||
AfterResetHook = "after-reset"
|
AfterResetHook = "after-reset"
|
||||||
BeforeResetHook = "before-reset"
|
BeforeResetHook = "before-reset"
|
||||||
AfterUpgradeChrootHook = "after-upgrade-chroot"
|
AfterUpgradeChrootHook = "after-upgrade-chroot"
|
||||||
AfterUpgradeHook = "after-upgrade"
|
AfterUpgradeHook = "after-upgrade"
|
||||||
BeforeUpgradeHook = "before-upgrade"
|
BeforeUpgradeHook = "before-upgrade"
|
||||||
TransitionImgFile = "transition.img"
|
TransitionImgFile = "transition.img"
|
||||||
RunningStateDir = "/run/initramfs/cos-state" // TODO: converge this constant with StateDir/RecoveryDir in dracut module from cos-toolkit
|
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
|
RunningRecoveryStateDir = "/run/initramfs/isoscan" // TODO: converge this constant with StateDir/RecoveryDir in dracut module from cos-toolkit
|
||||||
ActiveImgName = "active"
|
FailInstallationFileSentinel = "/run/cos/fail_installation"
|
||||||
PassiveImgName = "passive"
|
ActiveImgName = "active"
|
||||||
RecoveryImgName = "recovery"
|
PassiveImgName = "passive"
|
||||||
StateResetImgName = "statereset"
|
RecoveryImgName = "recovery"
|
||||||
GPT = "gpt"
|
StateResetImgName = "statereset"
|
||||||
UsrLocalPath = "/usr/local"
|
GPT = "gpt"
|
||||||
OEMPath = "/oem"
|
UsrLocalPath = "/usr/local"
|
||||||
|
OEMPath = "/oem"
|
||||||
|
|
||||||
// SELinux targeted policy paths
|
// SELinux targeted policy paths
|
||||||
SELinuxTargetedPath = "/etc/selinux/targeted"
|
SELinuxTargetedPath = "/etc/selinux/targeted"
|
||||||
|
@@ -84,6 +84,11 @@ func (i *InstallAction) Run() (err error) {
|
|||||||
return err
|
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?
|
// Store cloud-config in TPM or copy it to COS_OEM?
|
||||||
// Copy cloud-init if any
|
// Copy cloud-init if any
|
||||||
err = e.CopyCloudConfig(i.spec.CloudInit)
|
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()
|
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