Skip to content

Commit 86596c4

Browse files
committed
handleconfig: deprecate 'timer.use.config.checkpoint' usage
The default behaviour is to fetch saved config if its modification time does not exceed some stale config time (timer.use.config.checkpoint). This leads to the following problem observed by the customer: 1. EVE node and an app are up running. 2. Connection to the controller is lost for time > timer.use.config.checkpoint, so that last saved config modification time has not been updated. 3. Node is rebooted, connection to the controller is still missing. 4. Config is being fetched from a file, but modification time has not been updated for a while, thus config is rejected and applications do not show up. Although the default setting for the timer is 7 days, it is not enough for the node which constantly has problems with the internet and which up-time is minimum, so it is not uncommon to have a last saved config with the modification time dated several weeks from now. This is not safe and having outdated config (basically this is always the case, because there is always a time gap between actual config on controller and config on EVE) is better, than to have no config at all. This patch deprecates the 'timer.use.config.checkpoint' and config is being always read from the file regardless of the modification time. Kudos to Siddharth and Daniel for debugging this. Signed-off-by: Roman Penyaev <[email protected]>
1 parent 87a8fc8 commit 86596c4

File tree

8 files changed

+14
-33
lines changed

8 files changed

+14
-33
lines changed

pkg/pillar/cmd/zedagent/handleProfile.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ func parseLocalProfile(localProfileBytes []byte) (*profile.LocalProfile, error)
9797
// read saved local profile in case of particular reboot reason
9898
func readSavedLocalProfile(getconfigCtx *getconfigContext) (*profile.LocalProfile, error) {
9999
localProfileMessage, ts, err := readSavedConfig(
100-
getconfigCtx.zedagentCtx.globalConfig.GlobalValueInt(types.StaleConfigTime),
101-
filepath.Join(checkpointDirname, savedLocalProfileFile), false)
100+
filepath.Join(checkpointDirname, savedLocalProfileFile))
102101
if err != nil {
103102
return nil, fmt.Errorf("readSavedLocalProfile: %v", err)
104103
}

pkg/pillar/cmd/zedagent/handleconfig.go

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,7 @@ func getLatestConfig(getconfigCtx *getconfigContext, url string,
540540
ctx.bootReason)
541541
} else {
542542
config, ts, err := readSavedProtoMessageConfig(
543-
zedcloudCtx, url,
544-
ctx.globalConfig.GlobalValueInt(types.StaleConfigTime),
545-
checkpointDirname+"/lastconfig", false)
543+
zedcloudCtx, url, checkpointDirname+"/lastconfig")
546544
if err != nil {
547545
log.Errorf("getconfig: %v", err)
548546
return invalidConfig
@@ -709,8 +707,8 @@ func existsSavedConfig(filename string) bool {
709707
// If the file exists then read the config, and return is modify time
710708
// Ignore if older than StaleConfigTime seconds
711709
func readSavedProtoMessageConfig(zedcloudCtx *zedcloud.ZedCloudContext, URL string,
712-
staleConfigTime uint32, filename string, force bool) (*zconfig.EdgeDevConfig, time.Time, error) {
713-
contents, ts, err := readSavedConfig(staleConfigTime, filename, force)
710+
filename string) (*zconfig.EdgeDevConfig, time.Time, error) {
711+
contents, ts, err := readSavedConfig(filename)
714712
if err != nil {
715713
log.Errorln("readSavedProtoMessageConfig", err)
716714
return nil, ts, err
@@ -733,24 +731,10 @@ func readSavedProtoMessageConfig(zedcloudCtx *zedcloud.ZedCloudContext, URL stri
733731
}
734732

735733
// If the file exists then read the config content from it, and return its modify time.
736-
// Ignore if older than staleTime seconds.
737-
func readSavedConfig(staleTime uint32,
738-
filename string, force bool) ([]byte, time.Time, error) {
734+
func readSavedConfig(filename string) ([]byte, time.Time, error) {
739735
info, err := os.Stat(filename)
740736
if err != nil {
741-
if os.IsNotExist(err) && !force {
742-
return nil, time.Time{}, nil
743-
} else {
744-
return nil, time.Time{}, err
745-
}
746-
}
747-
age := time.Since(info.ModTime())
748-
staleLimit := time.Second * time.Duration(staleTime)
749-
if !force && age > staleLimit {
750-
errStr := fmt.Sprintf("saved config too old: age %v limit %d\n",
751-
age, staleLimit)
752-
log.Errorln(errStr)
753-
return nil, info.ModTime(), nil
737+
return nil, time.Time{}, err
754738
}
755739
contents, err := ioutil.ReadFile(filename)
756740
if err != nil {

pkg/pillar/cmd/zedagent/localinfo.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,7 @@ func findAppInstance(
457457
func readSavedLocalCommands(ctx *getconfigContext) (*types.LocalCommands, error) {
458458
commands := &types.LocalCommands{}
459459
contents, ts, err := readSavedConfig(
460-
ctx.zedagentCtx.globalConfig.GlobalValueInt(types.StaleConfigTime),
461-
filepath.Join(checkpointDirname, savedLocalCommandsFile), false)
460+
filepath.Join(checkpointDirname, savedLocalCommandsFile))
462461
if err != nil {
463462
return commands, err
464463
}

pkg/pillar/cmd/zedagent/radiosilence.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ func getRadioConfig(ctx *getconfigContext, radioStatus *profile.RadioStatus) *pr
228228
// read saved radio config in case of a reboot
229229
func readSavedRadioConfig(ctx *getconfigContext) (*profile.RadioConfig, error) {
230230
radioConfigBytes, ts, err := readSavedConfig(
231-
ctx.zedagentCtx.globalConfig.GlobalValueInt(types.StaleConfigTime),
232-
filepath.Join(checkpointDirname, savedRadioConfigFile), false)
231+
filepath.Join(checkpointDirname, savedRadioConfigFile))
233232
if err != nil {
234233
return nil, fmt.Errorf("readSavedRadioConfig: %v", err)
235234
}

pkg/pillar/cmd/zedagent/validate.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ import (
1010
zconfig "github.com/lf-edge/eve/api/go/config"
1111
)
1212

13-
func readValidateConfig(staleConfigTime uint32,
14-
validateFile string) (bool, *zconfig.EdgeDevConfig) {
13+
func readValidateConfig(validateFile string) (bool, *zconfig.EdgeDevConfig) {
1514
config, _, err := readSavedProtoMessageConfig(zedcloudCtx, "https://",
16-
staleConfigTime, validateFile, true)
15+
validateFile)
1716
if err != nil {
1817
fmt.Printf("getconfig: %v\n", err)
1918
return false, nil

pkg/pillar/cmd/zedagent/zedagent.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@ func Run(ps *pubsub.PubSub, loggerArg *logrus.Logger, logArg *base.LogObject, ar
257257
return 1
258258
}
259259
if parse != "" {
260-
res, config := readValidateConfig(
261-
types.DefaultConfigItemValueMap().GlobalValueInt(types.StaleConfigTime), parse)
260+
res, config := readValidateConfig(parse)
262261
if !res {
263262
fmt.Printf("Failed to parse %s\n", parse)
264263
return 1

pkg/pillar/types/global.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ const (
167167
// MintimeUpdateSuccess global setting key
168168
MintimeUpdateSuccess GlobalSettingKey = "timer.test.baseimage.update"
169169
// StaleConfigTime global setting key
170+
// DEPRECATED! Saved config never expires!
170171
StaleConfigTime GlobalSettingKey = "timer.use.config.checkpoint"
171172
// VdiskGCTime global setting key
172173
VdiskGCTime GlobalSettingKey = "timer.gc.vdisk"
@@ -789,6 +790,7 @@ func NewConfigItemSpecMap() ConfigItemSpecMap {
789790
configItemSpecMap.AddIntItem(ResetIfCloudGoneTime, 7*24*3600, 120, 0xFFFFFFFF)
790791
configItemSpecMap.AddIntItem(FallbackIfCloudGoneTime, 300, 60, 0xFFFFFFFF)
791792
configItemSpecMap.AddIntItem(MintimeUpdateSuccess, 600, 30, HourInSec)
793+
// DEPRECATED
792794
configItemSpecMap.AddIntItem(StaleConfigTime, 7*24*3600, 0, 0xFFFFFFFF)
793795
configItemSpecMap.AddIntItem(VdiskGCTime, 3600, 60, 0xFFFFFFFF)
794796
configItemSpecMap.AddIntItem(DeferContentDelete, 0, 0, 24*3600)

pkg/pillar/types/globalconfigold.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ var globalConfigDefaults = OldGlobalConfig{
107107
UsbAccess: true, // Controller likely to default to false
108108
SshAccess: true, // Controller likely to default to false
109109
SshAuthorizedKeys: "",
110-
StaleConfigTime: 600, // Use stale config for up to 10 minutes
110+
StaleConfigTime: 600, // DEPRECATED!
111111
DownloadGCTime: 600, // 10 minutes
112112
VdiskGCTime: 3600, // 1 hour
113113
DownloadRetryTime: 600, // 10 minutes

0 commit comments

Comments
 (0)