mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 16:57:51 +08:00
Merge pull request #1629 from gravitl/bugfix_0.16.2_zombies
re-enable zombie processing
This commit is contained in:
@@ -335,7 +335,7 @@ func CreateNode(node *models.Node) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// CheckZombies(node)
|
||||
CheckZombies(node)
|
||||
|
||||
nodebytes, err := json.Marshal(&node)
|
||||
if err != nil {
|
||||
|
@@ -31,6 +31,7 @@ func CheckZombies(newnode *models.Node) {
|
||||
}
|
||||
for _, node := range nodes {
|
||||
if node.MacAddress == newnode.MacAddress {
|
||||
logger.Log(0, "adding ", node.ID, " to zombie list")
|
||||
newZombie <- node.ID
|
||||
}
|
||||
}
|
||||
@@ -38,6 +39,8 @@ func CheckZombies(newnode *models.Node) {
|
||||
|
||||
// ManageZombies - goroutine which adds/removes/deletes nodes from the zombie node quarantine list
|
||||
func ManageZombies(ctx context.Context) {
|
||||
logger.Log(2, "Zombie management started")
|
||||
InitializeZombies()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@@ -60,11 +63,14 @@ func ManageZombies(ctx context.Context) {
|
||||
logger.Log(3, "no zombies found")
|
||||
}
|
||||
case <-time.After(time.Second * ZOMBIE_TIMEOUT):
|
||||
logger.Log(0, "checking for zombie nodes")
|
||||
if len(zombies) > 0 {
|
||||
for i := len(zombies) - 1; i >= 0; i-- {
|
||||
node, err := GetNodeByID(zombies[i])
|
||||
if err != nil {
|
||||
logger.Log(1, "error retrieving zombie node", zombies[i], err.Error())
|
||||
logger.Log(1, "deleting ", node.Name, " from zombie list")
|
||||
zombies = append(zombies[:i], zombies[i+1:]...)
|
||||
continue
|
||||
}
|
||||
if time.Since(time.Unix(node.LastCheckIn, 0)) > time.Minute*ZOMBIE_DELETE_TIME {
|
||||
@@ -82,7 +88,7 @@ func ManageZombies(ctx context.Context) {
|
||||
}
|
||||
|
||||
// InitializeZombies - populates the zombie quarantine list (should be called from initialization)
|
||||
func InitalizeZombies() {
|
||||
func InitializeZombies() {
|
||||
nodes, err := GetAllNodes()
|
||||
if err != nil {
|
||||
logger.Log(1, "failed to retrieve nodes", err.Error())
|
||||
@@ -101,8 +107,10 @@ func InitalizeZombies() {
|
||||
if node.MacAddress == othernode.MacAddress {
|
||||
if node.LastCheckIn > othernode.LastCheckIn {
|
||||
zombies = append(zombies, othernode.ID)
|
||||
logger.Log(1, "adding ", othernode.Name, " with ID ", othernode.ID, " to zombie list")
|
||||
} else {
|
||||
zombies = append(zombies, node.ID)
|
||||
logger.Log(1, "adding ", node.Name, " with ID ", node.ID, " to zombie list")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user