Skip to content

Commit

Permalink
Merge pull request #404 from song-jiang/song-f2c
Browse files Browse the repository at this point in the history
Handle removing node for migration controller
  • Loading branch information
song-jiang committed Sep 6, 2019
2 parents 125bd8b + e45a3a3 commit 8705dbf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/controllers/flannelmigration/k8s_resources.go
Expand Up @@ -592,3 +592,14 @@ func (n k8snode) waitForNodeLabelDisappear(k8sClientset *kubernetes.Clientset, k
return false, nil
})
}

// Return true if a node does not exist in the cluster.
func (n k8snode) CheckNotExists(k8sClientset *kubernetes.Clientset) (bool, error) {
nodeName := string(n)
_, err := k8sClientset.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{})
if apierrs.IsNotFound(err) {
return true, nil
}

return false, err
}
10 changes: 10 additions & 0 deletions pkg/controllers/flannelmigration/network_migrator.go
Expand Up @@ -243,6 +243,16 @@ func (m *networkMigrator) MigrateNodes(nodes []*v1.Node) error {

err = m.setupCalicoNetworkForNode(node)
if err != nil {
// Error migrating a node. However, if the node has been removed before migration controller started,
// just log and continue on to next node.
n := k8snode(node.Name)
notFound, checkErr := n.CheckNotExists(m.k8sClientset)
if checkErr != nil {
log.WithError(checkErr).Errorf("Check existence of %s failed.", node.Name)
} else if notFound {
log.Infof("Node %s has been removed, continue on to next node...", node.Name)
continue
}
return err
}
}
Expand Down

0 comments on commit 8705dbf

Please sign in to comment.