Track active/passive boot for upgrade workflow (#133)

* Track active/passive boot for upgrade workflow

Track what are we booting from during upgrade in order to not backup
active into passive if we are booting from passive.

If we are booting from active or recovery the workflow keeps as it was,
backup active into passive, and then move the transition image into
active.

Signed-off-by: Itxaka <itxaka@kairos.io>
This commit is contained in:
Itxaka
2023-09-01 15:19:28 +02:00
committed by GitHub
parent ca4cf5059d
commit 442973526e
4 changed files with 52 additions and 9 deletions

View File

@@ -18,15 +18,16 @@ package action
import (
"fmt"
agentConfig "github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/utils/fs"
"path/filepath"
"time"
agentConfig "github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/constants"
"github.com/kairos-io/kairos-agent/v2/pkg/elemental"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
"github.com/kairos-io/kairos-agent/v2/pkg/utils"
"github.com/kairos-io/kairos-agent/v2/pkg/utils/fs"
"github.com/kairos-io/kairos-sdk/state"
)
// UpgradeAction represents the struct that will run the upgrade from start to finish
@@ -121,6 +122,16 @@ func (u *UpgradeAction) Run() (err error) {
var upgradeImg v1.Image
var finalImageFile string
// Track where we booted from to have a different workflow
// Booted from active: backup active into passive, upgrade active
// Booted from passive: Upgrade active, leave passive as is
var bootedFrom state.Boot
bootedFrom, err = state.DetectBootWithVFS(u.config.Fs)
if err != nil {
u.config.Logger.Warnf("error detecting boot: %s", err)
}
cleanup := utils.NewCleanStack()
defer func() { err = cleanup.Cleanup(err) }()
@@ -230,9 +241,10 @@ func (u *UpgradeAction) Run() (err error) {
return err
}
// If not upgrading recovery, backup active into passive
if !u.spec.RecoveryUpgrade {
//TODO this step could be part of elemental package
// If not upgrading recovery and booting from non passive, backup active into passive
// We dont want to overwrite passive if we are booting from passive as it could mean that active is broken and we would
// be overriding a working passive with a broken/unknown active
if u.spec.RecoveryUpgrade == false && bootedFrom != state.Passive {
// backup current active.img to passive.img before overwriting the active.img
u.Info("Backing up current active image")
source := filepath.Join(u.spec.Partitions.State.MountPoint, "cOS", constants.ActiveImgFile)