This is a creation in Article, where the information may have evolved or changed.
Cluster.validatePendingEngine
Is the code that is actually used to connect Docker engine
:
Validatependingengine connects to the Engine,func (c *cluster) Validatependingengine (engine *cluster. Engine) bool {//Attempt a connection to the engine. Since This is slow, and don ' t get a hold//of the The lock yet. If err: = engine. Connect (C.tlsconfig); Err! = Nil {log. Withfields (log. fields{"ADDR": Engine. ADDR}). DEBUGF ("Failed to validate pending node:%s", err) return false}//The following is critical and fast. Grab a lock. C.lock () defer c.unlock ()//only validate engines from Pendingengines list if _, exists: = C.pendingengines[engi Ne. ADDR];!exists {return false}//Make sure the engine ID is unique. If old, exists: = C.engines[engine.id]; exists {if old. Addr! = engine. Addr {log. Errorf ("ID duplicated. %s shared by%s and%s ', Engine.id, old. ADDR, engine. ADDR)//Keep this engine in Pendingengines table and show its error. If it ' s ID duplication from VM clone, user see this MEssage and can fix it. If the engine is a rebooted and get new IP from DHCP, previous address'll be removed//from discovery after a while. In both cases, retry may fix the problem. Engine. Handleidconflict (old. ADDR)} else {log. DEBUGF ("Node%q (name:%q) with address%q is already registered", Engine.id, engine. Name, engine. ADDR) engine. Disconnect ()//Remove it from pendingengines table Delete (C.pendingengines, engine. ADDR)} return False}//Engine validated, move from Pendingengines table to engines table Delete ( C.pendingengines, engine. ADDR)//Set engine state to healthy, and start refresh loop engine. Validationcomplete () c.engines[engine.id] = engine Log.infof ("registered engine%s at%s", engine. Name, engine. ADDR) return True}
Cluster.validatePendingEngine
Always in Operation Cluster.pendingEngines
Engine
, if the connection is Docker engine
successful, it will be Engine
moved to Cluster.engines
this map
.