rename some variables that shadowed imports or package types

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-07-03 23:49:57 +02:00
parent 9f4acceb6a
commit 8ea78b34ab
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 43 additions and 43 deletions

View file

@ -121,20 +121,20 @@ func (n *networkRouter) getNetwork(ctx context.Context, w http.ResponseWriter, r
if scope != "" {
filter.Add("scope", scope)
}
nw, _ := n.backend.GetNetworks(filter, types.NetworkListConfig{Detailed: true, Verbose: verbose})
for _, network := range nw {
if network.ID == term {
return httputils.WriteJSON(w, http.StatusOK, network)
networks, _ := n.backend.GetNetworks(filter, types.NetworkListConfig{Detailed: true, Verbose: verbose})
for _, nw := range networks {
if nw.ID == term {
return httputils.WriteJSON(w, http.StatusOK, nw)
}
if network.Name == term {
if nw.Name == term {
// No need to check the ID collision here as we are still in
// local scope and the network ID is unique in this scope.
listByFullName[network.ID] = network
listByFullName[nw.ID] = nw
}
if strings.HasPrefix(network.ID, term) {
if strings.HasPrefix(nw.ID, term) {
// No need to check the ID collision here as we are still in
// local scope and the network ID is unique in this scope.
listByPartialID[network.ID] = network
listByPartialID[nw.ID] = nw
}
}
@ -156,25 +156,25 @@ func (n *networkRouter) getNetwork(ctx context.Context, w http.ResponseWriter, r
}
}
nr, _ := n.cluster.GetNetworks(filter)
for _, network := range nr {
if network.ID == term {
return httputils.WriteJSON(w, http.StatusOK, network)
networks, _ = n.cluster.GetNetworks(filter)
for _, nw := range networks {
if nw.ID == term {
return httputils.WriteJSON(w, http.StatusOK, nw)
}
if network.Name == term {
if nw.Name == term {
// Check the ID collision as we are in swarm scope here, and
// the map (of the listByFullName) may have already had a
// network with the same ID (from local scope previously)
if _, ok := listByFullName[network.ID]; !ok {
listByFullName[network.ID] = network
if _, ok := listByFullName[nw.ID]; !ok {
listByFullName[nw.ID] = nw
}
}
if strings.HasPrefix(network.ID, term) {
if strings.HasPrefix(nw.ID, term) {
// Check the ID collision as we are in swarm scope here, and
// the map (of the listByPartialID) may have already had a
// network with the same ID (from local scope previously)
if _, ok := listByPartialID[network.ID]; !ok {
listByPartialID[network.ID] = network
if _, ok := listByPartialID[nw.ID]; !ok {
listByPartialID[nw.ID] = nw
}
}
}
@ -326,42 +326,42 @@ func (n *networkRouter) findUniqueNetwork(term string) (types.NetworkResource, e
listByPartialID := map[string]types.NetworkResource{}
filter := filters.NewArgs(filters.Arg("idOrName", term))
nw, _ := n.backend.GetNetworks(filter, types.NetworkListConfig{Detailed: true})
for _, network := range nw {
if network.ID == term {
return network, nil
networks, _ := n.backend.GetNetworks(filter, types.NetworkListConfig{Detailed: true})
for _, nw := range networks {
if nw.ID == term {
return nw, nil
}
if network.Name == term && !network.Ingress {
if nw.Name == term && !nw.Ingress {
// No need to check the ID collision here as we are still in
// local scope and the network ID is unique in this scope.
listByFullName[network.ID] = network
listByFullName[nw.ID] = nw
}
if strings.HasPrefix(network.ID, term) {
if strings.HasPrefix(nw.ID, term) {
// No need to check the ID collision here as we are still in
// local scope and the network ID is unique in this scope.
listByPartialID[network.ID] = network
listByPartialID[nw.ID] = nw
}
}
nr, _ := n.cluster.GetNetworks(filter)
for _, network := range nr {
if network.ID == term {
return network, nil
networks, _ = n.cluster.GetNetworks(filter)
for _, nw := range networks {
if nw.ID == term {
return nw, nil
}
if network.Name == term {
if nw.Name == term {
// Check the ID collision as we are in swarm scope here, and
// the map (of the listByFullName) may have already had a
// network with the same ID (from local scope previously)
if _, ok := listByFullName[network.ID]; !ok {
listByFullName[network.ID] = network
if _, ok := listByFullName[nw.ID]; !ok {
listByFullName[nw.ID] = nw
}
}
if strings.HasPrefix(network.ID, term) {
if strings.HasPrefix(nw.ID, term) {
// Check the ID collision as we are in swarm scope here, and
// the map (of the listByPartialID) may have already had a
// network with the same ID (from local scope previously)
if _, ok := listByPartialID[network.ID]; !ok {
listByPartialID[network.ID] = network
if _, ok := listByPartialID[nw.ID]; !ok {
listByPartialID[nw.ID] = nw
}
}
}

View file

@ -392,7 +392,7 @@ func (daemon *Daemon) findAndAttachNetwork(container *container.Container, idOrN
}
var (
config *networktypes.NetworkingConfig
nwCfg *networktypes.NetworkingConfig
retryCount int
)
@ -406,7 +406,7 @@ func (daemon *Daemon) findAndAttachNetwork(container *container.Container, idOrN
// trigger attachment in the swarm cluster manager.
if daemon.clusterProvider != nil {
var err error
config, err = daemon.clusterProvider.AttachNetwork(id, container.ID, addresses)
nwCfg, err = daemon.clusterProvider.AttachNetwork(id, container.ID, addresses)
if err != nil {
return nil, nil, err
}
@ -427,7 +427,7 @@ func (daemon *Daemon) findAndAttachNetwork(container *container.Container, idOrN
// attached to the swarm scope network went down
// and removed the network while we were in
// the process of attaching.
if config != nil {
if nwCfg != nil {
if _, ok := err.(libnetwork.ErrNoSuchNetwork); ok {
if retryCount >= 5 {
return nil, nil, fmt.Errorf("could not find network %s after successful attachment", idOrName)
@ -446,7 +446,7 @@ func (daemon *Daemon) findAndAttachNetwork(container *container.Container, idOrN
// This container has attachment to a swarm scope
// network. Update the container network settings accordingly.
container.NetworkSettings.HasSwarmEndpoint = true
return n, config, nil
return n, nwCfg, nil
}
// updateContainerNetworkSettings updates the network settings
@ -737,7 +737,7 @@ func (daemon *Daemon) connectToNetwork(cfg *config.Config, container *container.
endpointConfig = &networktypes.EndpointSettings{}
}
n, config, err := daemon.findAndAttachNetwork(container, idOrName, endpointConfig)
n, nwCfg, err := daemon.findAndAttachNetwork(container, idOrName, endpointConfig)
if err != nil {
return err
}
@ -746,8 +746,8 @@ func (daemon *Daemon) connectToNetwork(cfg *config.Config, container *container.
}
var operIPAM bool
if config != nil {
if epConfig, ok := config.EndpointsConfig[n.Name()]; ok {
if nwCfg != nil {
if epConfig, ok := nwCfg.EndpointsConfig[n.Name()]; ok {
if endpointConfig.IPAMConfig == nil ||
(endpointConfig.IPAMConfig.IPv4Address == "" &&
endpointConfig.IPAMConfig.IPv6Address == "" &&