Browse Source

client infrastructure to support updates

Matthew R. Kasun 3 years ago
parent
commit
ab9f0f05e0
2 changed files with 35 additions and 0 deletions
  1. 34 0
      netclient/functions/clientconfig.go
  2. 1 0
      netclient/functions/daemon.go

+ 34 - 0
netclient/functions/clientconfig.go

@@ -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
+}

+ 1 - 0
netclient/functions/daemon.go

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