Skip to content

Commit 5dd0c13

Browse files
milan-zededaeriknordmark
authored andcommitted
Config items: honour persisted config & support run-time change
This commit addresses two issues/limitations related to global config items: 1. nodeagent and zedagent do not support runtime changes of global config items. They only apply the very first received instance of `ConfigItemValueMap` and ignore any subsequent changes. This for example means, that changing `timer.reboot.no.network` for an already onboarded and running device has no effect - the change is ignored. To support run-time change of config items is as simple as changing a single if condition inside the handler for `ConfigItemValueMap` subscription. 2. Few months ago the upgradeconverter was improved to support override of config items via the config partition. However, these changes no longer take into account potentially persisted config from a previous run. Currently, if config items are not overridden via config partition (`/config/GlobalConfig/global.json` does not exist), the updateconverter will immediately apply default values. This commits makes changes to check for persisted config items before restoring to defaults. Signed-off-by: Milan Lenco <[email protected]>
1 parent 5900edd commit 5dd0c13

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

pkg/pillar/cmd/nodeagent/nodeagent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func handleGlobalConfigImpl(ctxArg interface{}, key string,
412412
var gcp *types.ConfigItemValueMap
413413
debug, gcp = agentlog.HandleGlobalConfig(log, ctxPtr.subGlobalConfig, agentName,
414414
debugOverride, ctxPtr.agentBaseContext.Logger)
415-
if gcp != nil && !ctxPtr.GCInitialized {
415+
if gcp != nil {
416416
ctxPtr.globalConfig = gcp
417417
ctxPtr.GCInitialized = true
418418
}

pkg/pillar/cmd/upgradeconverter/applydefaultconfigitem.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,28 @@ func importFromConfigPartition(ctxPtr *ucContext) error {
7272

7373
persistStatusFile := ctxPtr.newConfigItemValueMapFile()
7474
globalConfigExists := fileExists(importGlobalConfigFile)
75+
persistedConfigExists := fileExists(persistStatusFile)
7576

7677
if globalConfigExists {
78+
log.Noticef("Importing config items from %s", importGlobalConfigFile)
7779
globalConfigPtr, err = parseFile(importGlobalConfigFile)
7880
if err != nil {
7981
log.Errorf("Error parsing configuration from file: %s, %s", importGlobalConfigFile, err)
8082
return err
8183
}
84+
} else if persistedConfigExists {
85+
log.Noticef("Reusing persisted config items from the previous run")
86+
globalConfigPtr, err = parseFile(persistStatusFile)
87+
if err != nil {
88+
log.Errorf("Error parsing configuration from file: %s, %s", persistStatusFile, err)
89+
return err
90+
}
8291
} else {
8392
log.Noticef("No existing ConfigItemValueMap; creating new %s",
8493
persistStatusFile)
8594
globalConfigPtr = types.NewConfigItemValueMap()
8695
}
96+
8797
keyData, keyDataValid := readAuthorizedKeys(baseAuthorizedKeysFile)
8898
if len(keyData) != 0 {
8999
log.Functionf("Found the key data in %s", baseAuthorizedKeysFile)
@@ -110,7 +120,7 @@ func importFromConfigPartition(ctxPtr *ucContext) error {
110120
os.Remove(importGlobalConfigFile)
111121
log.Functionf("Deleted %s file from /config/", importGlobalConfigFile)
112122
}
113-
log.Tracef("upgradeconverter.applyDefaultConfigItem done")
123+
log.Tracef("upgradeconverter.importFromConfigPartition done")
114124
return nil
115125
}
116126

pkg/pillar/cmd/zedagent/zedagent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,7 @@ func handleGlobalConfigImpl(ctxArg interface{}, key string,
18821882
var gcp *types.ConfigItemValueMap
18831883
debug, gcp = agentlog.HandleGlobalConfig(log, ctx.subGlobalConfig, agentName,
18841884
debugOverride, logger)
1885-
if gcp != nil && !ctx.GCInitialized {
1885+
if gcp != nil {
18861886
ctx.globalConfig = *gcp
18871887
ctx.GCInitialized = true
18881888
ctx.gcpMaintenanceMode = gcp.GlobalValueTriState(types.MaintenanceMode)

0 commit comments

Comments
 (0)