in pkg/mgmapi/mgmapi.go [115:161]
func (mci *mgmClientImpl) connectToNodeId(connectstring string, desiredNodeId int) error {
var lastDNSError error
// The operator might be running from outside the K8s cluster in which case,
// it will not be possible to connect to desired mgmd in a single attempt.
// So, attempt connecting to the given connectstring, which probably is the
// load balancer URL and check the id of the connected node. If it is not the
// desired node id, retry.
for retries := 0; retries < 10; retries++ {
err := mci.connect(connectstring)
if err != nil {
if _, ok := err.(*net.DNSError); ok {
// Server not available yet. The pod is probably
// not up or the load balancer is not up. Retry.
klog.Error("Management server is not available yet")
lastDNSError = err
continue
}
// Some other error connecting to the server
klog.Errorf("Failed to connect to management server : %s", err)
return err
}
// Connected to an mgmd. Check if it is the desired one.
lastDNSError = nil
nodeId, err := mci.getConnectedMgmdNodeId()
if err != nil {
mci.Disconnect()
klog.Errorf("Failed to retrieve connected management server node id : %s", err)
return err
}
if nodeId == desiredNodeId {
// found the one
return nil
}
mci.Disconnect()
}
// Failed to connect to the right management node or
// due to the host not available
if lastDNSError == nil {
return errors.New("failed to connect to the desired nodeId")
}
return lastDNSError
}