Extract login into a method

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
Dimitris Karakasilis 2024-09-03 13:52:12 +03:00
parent 773b1e7d59
commit 2570a1848b
No known key found for this signature in database
GPG Key ID: 286DCAFD2C97DDE3
2 changed files with 27 additions and 19 deletions

View File

@ -164,6 +164,7 @@ var _ = Describe("Runtime Actions", func() {
config.Config = collector.Config{"upgrade": collector.Config{"recovery": true}}
spec, err = agentConfig.NewUpgradeSpec(config)
Expect(err).ShouldNot(HaveOccurred())
Expect(spec.Entry).To(Equal(constants.BootEntryRecovery))
Expect(spec.Recovery.Size).To(Equal(uint(100 + dummySourceSizeMb))) // We adding 100Mb on top
})
Describe(fmt.Sprintf("Booting from %s", constants.ActiveLabel), Label("active_label"), func() {

View File

@ -324,25 +324,7 @@ func NewUpgradeSpec(cfg *Config) (*v1.UpgradeSpec, error) {
}
}
// 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) {
entry = constants.BootEntryRecovery
}
}
}
entry := findEntryFromConfig(cfg)
spec := &v1.UpgradeSpec{
Entry: entry,
@ -1032,3 +1014,28 @@ func DetectPreConfiguredDevice(logger sdkTypes.KairosLogger) (string, error) {
return "", nil
}
// findEntryFromConfig checks the passed config for one of the following ways
// to set the upgrade entry.
// - One way 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".
func findEntryFromConfig(cfg *Config) string {
if _, ok := cfg.Config["upgrade"]; !ok {
return ""
}
// check value from --recovery and --boot-entry
if entryIface, ok := cfg.Config["upgrade"].(collector.Config)["entry"]; ok {
return entryIface.(string)
}
// check for "upgrade.recovery: true" in the kairos config
if _, ok := cfg.Config["upgrade"].(collector.Config)["recovery"]; ok {
if cfg.Config["upgrade"].(collector.Config)["recovery"].(bool) {
return constants.BootEntryRecovery
}
}
return ""
}