Sfoglia il codice sorgente

libnetwork: Sandbox.resolveName: rename vars for clarity

- use `nameOrAlias` for the name (or alias) to resolve
- use `lookupAlias` to indicate what the intent is; this function
  is either looking up aliases or "regular" names. Ideally we would
  split the function, but let's keep that for a future exercise.
- name the `ipv6Miss` output variable. The "ipv6 miss" logic is rather
  confusing, and should probably be revisited, but let's start with
  giving the variable a name to make it more apparent what it is.
- use `nw` for networks, which is the more common local name

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 1 anno fa
parent
commit
9249b34be8
1 ha cambiato i file con 8 aggiunte e 12 eliminazioni
  1. 8 12
      libnetwork/sandbox.go

+ 8 - 12
libnetwork/sandbox.go

@@ -488,25 +488,23 @@ func (sb *Sandbox) ResolveName(name string, ipType int) ([]net.IP, bool) {
 	return nil, false
 }
 
-func (sb *Sandbox) resolveName(req string, networkName string, epList []*Endpoint, alias bool, ipType int) ([]net.IP, bool) {
-	var ipv6Miss bool
-
+func (sb *Sandbox) resolveName(nameOrAlias string, networkName string, epList []*Endpoint, lookupAlias bool, ipType int) (_ []net.IP, ipv6Miss bool) {
 	for _, ep := range epList {
-		name := req
-		n := ep.getNetwork()
+		name := nameOrAlias
+		nw := ep.getNetwork()
 
-		if networkName != "" && networkName != n.Name() {
+		if networkName != "" && networkName != nw.Name() {
 			continue
 		}
 
-		if alias {
+		if lookupAlias {
 			if ep.aliases == nil {
 				continue
 			}
 
 			var ok bool
 			ep.mu.Lock()
-			name, ok = ep.aliases[req]
+			name, ok = ep.aliases[nameOrAlias]
 			ep.mu.Unlock()
 			if !ok {
 				continue
@@ -515,19 +513,17 @@ func (sb *Sandbox) resolveName(req string, networkName string, epList []*Endpoin
 			// If it is a regular lookup and if the requested name is an alias
 			// don't perform a svc lookup for this endpoint.
 			ep.mu.Lock()
-			if _, ok := ep.aliases[req]; ok {
+			if _, ok := ep.aliases[nameOrAlias]; ok {
 				ep.mu.Unlock()
 				continue
 			}
 			ep.mu.Unlock()
 		}
 
-		ip, miss := n.ResolveName(name, ipType)
-
+		ip, miss := nw.ResolveName(name, ipType)
 		if ip != nil {
 			return ip, false
 		}
-
 		if miss {
 			ipv6Miss = miss
 		}