mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-25 21:43:58 +00:00
Implement uki "kairos-agent upgrade --recovery"
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
@@ -69,7 +69,7 @@ func Upgrade(
|
|||||||
bus.Manager.Initialize()
|
bus.Manager.Initialize()
|
||||||
|
|
||||||
if internalutils.UkiBootMode() == internalutils.UkiHDD {
|
if internalutils.UkiBootMode() == internalutils.UkiHDD {
|
||||||
return upgradeUki(source, dirs, strictValidations)
|
return upgradeUki(source, dirs, strictValidations, upgradeRecovery)
|
||||||
} else {
|
} else {
|
||||||
return upgrade(source, force, strictValidations, dirs, preReleases, upgradeRecovery)
|
return upgrade(source, force, strictValidations, dirs, preReleases, upgradeRecovery)
|
||||||
}
|
}
|
||||||
@@ -201,8 +201,8 @@ func getReleasesFromProvider(includePrereleases bool) ([]string, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func upgradeUki(source string, dirs []string, strictValidations bool) error {
|
func upgradeUki(source string, dirs []string, strictValidations, upgradeRecovery bool) error {
|
||||||
cliConf, err := generateUpgradeConfForCLIArgs(source, false)
|
cliConf, err := generateUpgradeConfForCLIArgs(source, upgradeRecovery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -217,7 +217,7 @@ func upgradeUki(source string, dirs []string, strictValidations bool) error {
|
|||||||
utils.SetEnv(c.Env)
|
utils.SetEnv(c.Env)
|
||||||
|
|
||||||
// Load the upgrade Config from the system
|
// Load the upgrade Config from the system
|
||||||
upgradeSpec, err := config.ReadUkiUpgradeFromConfig(c)
|
upgradeSpec, err := config.ReadUkiUpgradeSpecFromConfig(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -706,8 +706,8 @@ func NewUkiUpgradeSpec(cfg *Config) (*v1.UpgradeUkiSpec, error) {
|
|||||||
return spec, err
|
return spec, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadUkiUpgradeFromConfig will return a proper v1.UpgradeUkiSpec based on an agent Config
|
// ReadUkiUpgradeSpecFromConfig will return a proper v1.UpgradeUkiSpec based on an agent Config
|
||||||
func ReadUkiUpgradeFromConfig(c *Config) (*v1.UpgradeUkiSpec, error) {
|
func ReadUkiUpgradeSpecFromConfig(c *Config) (*v1.UpgradeUkiSpec, error) {
|
||||||
sp, err := ReadSpecFromCloudConfig(c, "upgrade-uki")
|
sp, err := ReadSpecFromCloudConfig(c, "upgrade-uki")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &v1.UpgradeUkiSpec{}, err
|
return &v1.UpgradeUkiSpec{}, err
|
||||||
|
@@ -527,10 +527,11 @@ func (i *InstallUkiSpec) GetPartitions() ElementalPartitions { return i.Partitio
|
|||||||
func (i *InstallUkiSpec) GetExtraPartitions() PartitionList { return i.ExtraPartitions }
|
func (i *InstallUkiSpec) GetExtraPartitions() PartitionList { return i.ExtraPartitions }
|
||||||
|
|
||||||
type UpgradeUkiSpec struct {
|
type UpgradeUkiSpec struct {
|
||||||
Active Image `yaml:"system,omitempty" mapstructure:"system"`
|
RecoveryUpgrade bool `yaml:"recovery,omitempty" mapstructure:"recovery"`
|
||||||
Reboot bool `yaml:"reboot,omitempty" mapstructure:"reboot"`
|
Active Image `yaml:"system,omitempty" mapstructure:"system"`
|
||||||
PowerOff bool `yaml:"poweroff,omitempty" mapstructure:"poweroff"`
|
Reboot bool `yaml:"reboot,omitempty" mapstructure:"reboot"`
|
||||||
EfiPartition *Partition `yaml:"efi-partition,omitempty" mapstructure:"efi-partition"`
|
PowerOff bool `yaml:"poweroff,omitempty" mapstructure:"poweroff"`
|
||||||
|
EfiPartition *Partition `yaml:"efi-partition,omitempty" mapstructure:"efi-partition"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *UpgradeUkiSpec) Sanitize() error {
|
func (i *UpgradeUkiSpec) Sanitize() error {
|
||||||
|
@@ -2,6 +2,7 @@ package uki
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/kairos-io/kairos-agent/v2/pkg/config"
|
"github.com/kairos-io/kairos-agent/v2/pkg/config"
|
||||||
@@ -42,6 +43,13 @@ func (i *UpgradeAction) Run() (err error) {
|
|||||||
// If we decide to first copy and then rotate, we need ~4 times the size of
|
// If we decide to first copy and then rotate, we need ~4 times the size of
|
||||||
// the artifact set [TBD]
|
// the artifact set [TBD]
|
||||||
|
|
||||||
|
// When upgrading recovery, we don't want to replace loader.conf or any other
|
||||||
|
// files, thus we take a simpler approach and only install the new efi file
|
||||||
|
// and the relevant conf
|
||||||
|
if i.spec.RecoveryUpgrade {
|
||||||
|
return i.installRecovery(i.cfg.Logger)
|
||||||
|
}
|
||||||
|
|
||||||
// Dump artifact to efi dir
|
// Dump artifact to efi dir
|
||||||
_, err = e.DumpSource(constants.UkiEfiDir, i.spec.Active.Source)
|
_, err = e.DumpSource(constants.UkiEfiDir, i.spec.Active.Source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -74,3 +82,37 @@ func (i *UpgradeAction) Run() (err error) {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// installRecovery replaces the "recovery" role efi and conf files with
|
||||||
|
// the UnassignedArtifactRole efi and loader files from dir
|
||||||
|
func (i *UpgradeAction) installRecovery(logger v1.Logger) error {
|
||||||
|
tmpDir, err := os.MkdirTemp("", "")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("creating a tmp dir: %w", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
|
// Dump artifact to tmp dir
|
||||||
|
e := elemental.NewElemental(i.cfg)
|
||||||
|
_, err = e.DumpSource(tmpDir, i.spec.Active.Source)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = copyFile(
|
||||||
|
filepath.Join(tmpDir, "EFI", "kairos", UnassignedArtifactRole+".efi"),
|
||||||
|
filepath.Join(constants.UkiEfiDir, "EFI", "kairos", "recovery.efi"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
targetConfPath := filepath.Join(constants.UkiEfiDir, "loader", "entries", "recovery.conf")
|
||||||
|
err = copyFile(
|
||||||
|
filepath.Join(tmpDir, "loader", "entries", UnassignedArtifactRole+".conf"),
|
||||||
|
targetConfPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return replaceRoleInKey(targetConfPath, "efi", UnassignedArtifactRole, "recovery", logger)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user