Don't loop forever if subnet not found for the node
@@ -393,7 +393,6 @@ func (oc *OvsController) DeleteNode(nodeName string) error {
func (oc *OvsController) StartNode(mtu uint) error {
err := oc.initSelfSubnet()
if err != nil {
- log.Errorf("Failed to get subnet for this host: %v", err)
return err
}
@@ -537,18 +536,28 @@ func (oc *OvsController) watchVnids(ready chan<- bool, start <-chan string) {
}
func (oc *OvsController) initSelfSubnet() error {
- // get subnet for self
- for {
- sub, err := oc.subnetRegistry.GetSubnet(oc.hostName)
+ // timeout: 10 secs
+ retries := 20
+ retryInterval := 500 * time.Millisecond
+
+ var err error
+ var subnet *api.Subnet
+ // Try every retryInterval and bail-out if it exceeds max retries
+ for i := 0; i < retries; i++ {
+ // Get subnet for current node
+ subnet, err = oc.subnetRegistry.GetSubnet(oc.hostName)
+ if err == nil {
+ break
+ }
+ log.Warningf("Could not find an allocated subnet for node: %s, Waiting...", oc.hostName)
+ time.Sleep(retryInterval)
+ }
if err != nil {
- log.Errorf("Could not find an allocated subnet for node %s: %s. Waiting...", oc.hostName, err)
- time.Sleep(2 * time.Second)
- continue
+ return fmt.Errorf("Failed to get subnet for this host: %s, error: %v", oc.hostName, err)
}
- oc.localSubnet = sub
+ oc.localSubnet = subnet
return nil
}
-}
func (oc *OvsController) watchNodes(ready chan<- bool, start <-chan string) {
stop := make(chan bool)
