client infrastructure to support updates

This commit is contained in:
Matthew R. Kasun
2022-06-30 09:22:23 -04:00
committed by 0xdcarns
parent ef82ac4af5
commit ab9f0f05e0
2 changed files with 35 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
package functions
import (
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/netclient/config"
"github.com/gravitl/netmaker/netclient/ncutils"
)
var updateRequired = false
// UpdateClientConfig - function is called on daemon start to update clientConfig if required
// Usage : set update required to true and and update logic to function
func UpdateClientConfig() {
if !updateRequired {
return
}
networks, _ := ncutils.GetSystemNetworks()
if len(networks) == 0 {
return
}
for _, network := range networks {
cfg := config.ClientConfig{}
cfg.Network = network
cfg.ReadConfig()
//update any new fields
logger.Log(0, "updating clientConfig for network", cfg.Network)
//insert update logic here
if err := config.Write(&cfg, cfg.Network); err != nil {
logger.Log(0, "failed to update clientConfig for ", cfg.Network, err.Error())
}
}
//reset so future calls will return immediately
updateRequired = false
}

View File

@@ -42,6 +42,7 @@ type cachedMessage struct {
// Daemon runs netclient daemon from command line // Daemon runs netclient daemon from command line
func Daemon() error { func Daemon() error {
UpdateClientConfig()
serverSet := make(map[string]bool) serverSet := make(map[string]bool)
// == initial pull of all networks == // == initial pull of all networks ==
networks, _ := ncutils.GetSystemNetworks() networks, _ := ncutils.GetSystemNetworks()