mirror of
https://github.com/gravitl/netmaker.git
synced 2026-03-08 00:27:22 +08:00
added upgrade func list
This commit is contained in:
parent
ab9f0f05e0
commit
6d125eb2fa
4 changed files with 65 additions and 10 deletions
|
|
@ -3,32 +3,40 @@ package functions
|
|||
import (
|
||||
"github.com/gravitl/netmaker/logger"
|
||||
"github.com/gravitl/netmaker/netclient/config"
|
||||
"github.com/gravitl/netmaker/netclient/functions/upgrades"
|
||||
"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
|
||||
}
|
||||
defer upgrades.ReleaseUpgrades()
|
||||
|
||||
networks, _ := ncutils.GetSystemNetworks()
|
||||
if len(networks) == 0 {
|
||||
return
|
||||
}
|
||||
logger.Log(0, "updating netclient...")
|
||||
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)
|
||||
configChanged := false
|
||||
for _, u := range upgrades.Upgrades {
|
||||
if cfg.Node.Version == u.RequiredVersion {
|
||||
upgrades.UpgradeFunction(u.OP)(&cfg)
|
||||
cfg.Node.Version = u.NewVersion
|
||||
configChanged = true
|
||||
}
|
||||
}
|
||||
//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())
|
||||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
//reset so future calls will return immediately
|
||||
updateRequired = false
|
||||
logger.Log(0, "finished updates")
|
||||
}
|
||||
|
|
|
|||
13
netclient/functions/upgrades/types.go
Normal file
13
netclient/functions/upgrades/types.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package upgrades
|
||||
|
||||
import "github.com/gravitl/netmaker/netclient/config"
|
||||
|
||||
// UpgradeFunction - logic for upgrade
|
||||
type UpgradeFunction func(*config.ClientConfig)
|
||||
|
||||
// UpgradeInfo - struct for holding upgrade info
|
||||
type UpgradeInfo struct {
|
||||
RequiredVersion string
|
||||
NewVersion string
|
||||
OP UpgradeFunction
|
||||
}
|
||||
20
netclient/functions/upgrades/upgrades.go
Normal file
20
netclient/functions/upgrades/upgrades.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package upgrades
|
||||
|
||||
func init() {
|
||||
addUpgrades([]UpgradeInfo{
|
||||
upgrade0145,
|
||||
})
|
||||
}
|
||||
|
||||
// Upgrades - holds all upgrade funcs
|
||||
var Upgrades = []UpgradeInfo{}
|
||||
|
||||
// addUpgrades - Adds upgrades to make to client
|
||||
func addUpgrades(upgrades []UpgradeInfo) {
|
||||
Upgrades = append(Upgrades, upgrades...)
|
||||
}
|
||||
|
||||
// ReleaseUpgrades - releases upgrade funcs from memory
|
||||
func ReleaseUpgrades() {
|
||||
Upgrades = nil
|
||||
}
|
||||
14
netclient/functions/upgrades/v0-14-5.go
Normal file
14
netclient/functions/upgrades/v0-14-5.go
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package upgrades
|
||||
|
||||
import "github.com/gravitl/netmaker/netclient/config"
|
||||
|
||||
var upgrade0145 = UpgradeInfo{
|
||||
RequiredVersion: "0.14.4",
|
||||
NewVersion: "0.14.5",
|
||||
OP: update0145,
|
||||
}
|
||||
|
||||
func update0145(cfg *config.ClientConfig) {
|
||||
// do stuff for 14.4 -> 14.5
|
||||
// No-op
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue