mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-06-03 01:44:53 +00:00
Extract login into a method
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
parent
773b1e7d59
commit
2570a1848b
@ -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() {
|
||||
|
@ -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 ""
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user