From 961e1ff9aea18a2726685225602647cdd0e09c32 Mon Sep 17 00:00:00 2001 From: Dimitris Karakasilis Date: Wed, 28 Aug 2024 17:16:27 +0300 Subject: [PATCH] Respect every way to set the upgrade entry there are 3 ways: - cli arg: --recovery - cli arg: --boot-entry - config setting: upgrade.recovery: true We only checked the config setting Signed-off-by: Dimitris Karakasilis --- internal/agent/upgrade.go | 10 ++++++---- pkg/config/spec.go | 11 +++++++++-- pkg/elemental/elemental.go | 5 +++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/internal/agent/upgrade.go b/internal/agent/upgrade.go index c9ef518..bd071d2 100644 --- a/internal/agent/upgrade.go +++ b/internal/agent/upgrade.go @@ -146,8 +146,8 @@ func generateUpgradeConfForCLIArgs(source, upgradeEntry string) (string, error) // have access to that yet, we just set both uri values which shouldn't matter // anyway, the right one will be used later in the process. if source != "" { - upgradeConfig.Upgrade.RecoverySystem.URI = source - upgradeConfig.Upgrade.System.URI = source + upgradeConfig.Install.RecoverySystem.URI = source + upgradeConfig.Install.System.URI = source } d, err := json.Marshal(upgradeConfig) @@ -238,12 +238,14 @@ func upgradeUki(source string, dirs []string, upgradeEntry string, strictValidat // ExtraConfigUpgrade is the struct that holds the upgrade options that come from flags and events type ExtraConfigUpgrade struct { Upgrade struct { - Entry string `json:"entry,omitempty"` + Entry string `json:"entry,omitempty"` + } `json:"upgrade,omitempty"` + Install struct { RecoverySystem struct { URI string `json:"uri,omitempty"` } `json:"recovery-system,omitempty"` System struct { URI string `json:"uri,omitempty"` } `json:"system,omitempty"` - } `json:"upgrade,omitempty"` + } `json:"install,omitempty"` } diff --git a/pkg/config/spec.go b/pkg/config/spec.go index 1cbe6b8..a3cf04f 100644 --- a/pkg/config/spec.go +++ b/pkg/config/spec.go @@ -334,11 +334,18 @@ func NewUpgradeSpec(cfg *Config) (*v1.UpgradeSpec, error) { } } - // Deep look to see if upgrade.recovery == true in the config - // if yes, we set the upgrade spec "Entry" to "recovery" + // One way to set the entry is to use the cli arg "--recovery" + // which makes config.upgrade.entry be "recovery" + // Another way is by setting the cli arg "boot-entry" which set it to the + // specified value. + // Lastly, user can set "upgrade.recovery: true" in the kairos config, which + // should result in entry being "recovery". entry := "" _, ok := cfg.Config["upgrade"] if ok { + // check value from --recovery and --boot-entry + entry, _ = cfg.Config["upgrade"].(collector.Config)["entry"].(string) + // check for "upgrade.recovery: true" in the kairos config _, ok = cfg.Config["upgrade"].(collector.Config)["recovery"] if ok { if cfg.Config["upgrade"].(collector.Config)["recovery"].(bool) { diff --git a/pkg/elemental/elemental.go b/pkg/elemental/elemental.go index a4cd2dc..5e49c59 100644 --- a/pkg/elemental/elemental.go +++ b/pkg/elemental/elemental.go @@ -19,11 +19,12 @@ package elemental import ( "errors" "fmt" - v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1" - "github.com/kairos-io/kairos-agent/v2/pkg/utils/fs" "path/filepath" "strings" + v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1" + fsutils "github.com/kairos-io/kairos-agent/v2/pkg/utils/fs" + agentConfig "github.com/kairos-io/kairos-agent/v2/pkg/config" cnst "github.com/kairos-io/kairos-agent/v2/pkg/constants" "github.com/kairos-io/kairos-agent/v2/pkg/partitioner"