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 <dimitris@karakasilis.me>
This commit is contained in:
Dimitris Karakasilis 2024-08-28 17:16:27 +03:00
parent 37bbaf32ce
commit 961e1ff9ae
No known key found for this signature in database
GPG Key ID: 286DCAFD2C97DDE3
3 changed files with 18 additions and 8 deletions

View File

@ -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"`
}

View File

@ -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) {

View File

@ -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"