( networks map[string]*composetypes.ServiceNetworkConfig, networkConfigs networkMap, namespace Namespace, name string, )
| 195 | } |
| 196 | |
| 197 | func convertServiceNetworks( |
| 198 | networks map[string]*composetypes.ServiceNetworkConfig, |
| 199 | networkConfigs networkMap, |
| 200 | namespace Namespace, |
| 201 | name string, |
| 202 | ) ([]swarm.NetworkAttachmentConfig, error) { |
| 203 | if len(networks) == 0 { |
| 204 | networks = map[string]*composetypes.ServiceNetworkConfig{ |
| 205 | defaultNetwork: {}, |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | nets := make([]swarm.NetworkAttachmentConfig, 0, len(networks)) |
| 210 | for networkName, nw := range networks { |
| 211 | networkConfig, ok := networkConfigs[networkName] |
| 212 | if !ok && networkName != defaultNetwork { |
| 213 | return nil, fmt.Errorf("undefined network %q", networkName) |
| 214 | } |
| 215 | var aliases []string |
| 216 | var driverOpts map[string]string |
| 217 | if nw != nil { |
| 218 | aliases = nw.Aliases |
| 219 | driverOpts = nw.DriverOpts |
| 220 | } |
| 221 | target := namespace.Scope(networkName) |
| 222 | if networkConfig.Name != "" { |
| 223 | target = networkConfig.Name |
| 224 | } |
| 225 | netAttachConfig := swarm.NetworkAttachmentConfig{ |
| 226 | Target: target, |
| 227 | Aliases: aliases, |
| 228 | DriverOpts: driverOpts, |
| 229 | } |
| 230 | // Only add default aliases to user defined networks. Other networks do |
| 231 | // not support aliases. |
| 232 | if container.NetworkMode(target).IsUserDefined() { |
| 233 | netAttachConfig.Aliases = append(netAttachConfig.Aliases, name) |
| 234 | } |
| 235 | nets = append(nets, netAttachConfig) |
| 236 | } |
| 237 | |
| 238 | sort.Slice(nets, func(i, j int) bool { |
| 239 | return nets[i].Target < nets[j].Target |
| 240 | }) |
| 241 | return nets, nil |
| 242 | } |
| 243 | |
| 244 | // TODO: fix secrets API so that SecretAPIClient is not required here |
| 245 | func convertServiceSecrets( |
searching dependent graphs…