merge fix

This commit is contained in:
0xdcarns 2022-07-07 13:40:07 -04:00
commit 7cc66870e2
2 changed files with 52 additions and 11 deletions

View file

@ -1,6 +1,9 @@
package functions
import (
"strconv"
"strings"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/netclient/config"
"github.com/gravitl/netmaker/netclient/functions/upgrades"
@ -16,12 +19,16 @@ func UpdateClientConfig() {
if len(networks) == 0 {
return
}
logger.Log(0, "updating netclient...")
logger.Log(0, "checking for netclient updates...")
for _, network := range networks {
cfg := config.ClientConfig{}
cfg.Network = network
cfg.ReadConfig()
//update any new fields
major, minor, _ := Version(cfg.Node.Version)
if major == 0 && minor < 14 {
logger.Log(0, "schema of network", cfg.Network, "is out of date and cannot be updated\n Correct behaviour of netclient cannot be guaranteed")
continue
}
configChanged := false
for _, u := range upgrades.Upgrades {
if ncutils.StringSliceContains(u.RequiredVersions, cfg.Node.Version) {
@ -31,13 +38,37 @@ func UpdateClientConfig() {
configChanged = true
}
}
//insert update logic here
if configChanged {
logger.Log(0, "updating clientConfig for network", cfg.Network)
if err := config.Write(&cfg, cfg.Network); err != nil {
logger.Log(0, "failed to update clientConfig for ", cfg.Network, err.Error())
//save and publish
if err := PublishNodeUpdate(&cfg); err != nil {
logger.Log(0, "error publishing node update during schema change", err.Error())
}
}
}
logger.Log(0, "finished updates")
}
// Version - parse version string into component parts
// version string must be semantic version of form 1.2.3 or v1.2.3
// otherwise 0, 0, 0 will be returned.
func Version(version string) (int, int, int) {
var major, minor, patch int
var errMajor, errMinor, errPatch error
parts := strings.Split(version, ".")
//ensure semantic version
if len(parts) < 3 {
return major, minor, patch
}
if strings.Contains(parts[0], "v") {
majors := strings.Split(parts[0], "v")
major, errMajor = strconv.Atoi(majors[1])
} else {
major, errMajor = strconv.Atoi(parts[0])
}
minor, errMinor = strconv.Atoi(parts[1])
patch, errPatch = strconv.Atoi(parts[2])
if errMajor != nil || errMinor != nil || errPatch != nil {
return 0, 0, 0
}
return major, minor, patch
}

View file

@ -1,14 +1,24 @@
package upgrades
import "github.com/gravitl/netmaker/netclient/config"
import (
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/netclient/config"
)
var upgrade0145 = UpgradeInfo{
RequiredVersions: []string{"0.14.1", "0.14.2", "0.14.3", "0.14.4"},
NewVersion: "0.14.5",
OP: update0145,
RequiredVersions: []string{
"v0.14.0",
"v0.14.1",
"v0.14.2",
"v0.14.3",
"v0.14.4",
},
NewVersion: "v0.14.5",
OP: update0145,
}
func update0145(cfg *config.ClientConfig) {
// do stuff for 14.4 -> 14.5
// do stuff for 14.X -> 14.5
// No-op
logger.Log(0, "updating schema for 0.14.5")
}