Networks from the compose-file type to the engine API type
(namespace Namespace, networks networkMap, servicesNetworks map[string]struct{})
| 59 | |
| 60 | // Networks from the compose-file type to the engine API type |
| 61 | func Networks(namespace Namespace, networks networkMap, servicesNetworks map[string]struct{}) (map[string]client.NetworkCreateOptions, []string) { |
| 62 | if networks == nil { |
| 63 | networks = make(map[string]composetypes.NetworkConfig) |
| 64 | } |
| 65 | |
| 66 | externalNetworks := []string{} |
| 67 | result := make(map[string]client.NetworkCreateOptions) |
| 68 | for internalName := range servicesNetworks { |
| 69 | nw := networks[internalName] |
| 70 | if nw.External.External { |
| 71 | externalNetworks = append(externalNetworks, nw.Name) |
| 72 | continue |
| 73 | } |
| 74 | |
| 75 | createOpts := client.NetworkCreateOptions{ |
| 76 | Labels: addStackLabel(namespace, nw.Labels), |
| 77 | Driver: nw.Driver, |
| 78 | Options: nw.DriverOpts, |
| 79 | Internal: nw.Internal, |
| 80 | Attachable: nw.Attachable, |
| 81 | } |
| 82 | |
| 83 | if nw.Ipam.Driver != "" || len(nw.Ipam.Config) > 0 { |
| 84 | createOpts.IPAM = &network.IPAM{ |
| 85 | Driver: nw.Ipam.Driver, |
| 86 | } |
| 87 | for _, ipamConfig := range nw.Ipam.Config { |
| 88 | sn, _ := netip.ParsePrefix(ipamConfig.Subnet) |
| 89 | createOpts.IPAM.Config = append(createOpts.IPAM.Config, network.IPAMConfig{ |
| 90 | Subnet: sn, |
| 91 | }) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | networkName := nw.Name |
| 96 | if nw.Name == "" { |
| 97 | networkName = namespace.Scope(internalName) |
| 98 | } |
| 99 | result[networkName] = createOpts |
| 100 | } |
| 101 | |
| 102 | return result, externalNetworks |
| 103 | } |
| 104 | |
| 105 | // Secrets converts secrets from the Compose type to the engine API type |
| 106 | func Secrets(namespace Namespace, secrets map[string]composetypes.SecretConfig) ([]swarm.SecretSpec, error) { |
searching dependent graphs…