The commit adds capability to accept csv parameters
for network option in service create/update commands.The change
includes name,alias driver options specific to the network.
With this the following will be supported
docker service create --name web --network name=docknet,alias=web1,driver-opt=field1=value1 nginx
docker service create --name web --network docknet nginx
docker service update web --network-add name=docknet,alias=web1,driver-opt=field1=value1
docker service update web --network-rm docknet
Signed-off-by: Abhinandan Prativadi <abhi@docker.com>
| ... | ... |
@@ -94,8 +94,9 @@ type NetworkSpec struct {
|
| 94 | 94 |
|
| 95 | 95 |
// NetworkAttachmentConfig represents the configuration of a network attachment. |
| 96 | 96 |
type NetworkAttachmentConfig struct {
|
| 97 |
- Target string `json:",omitempty"` |
|
| 98 |
- Aliases []string `json:",omitempty"` |
|
| 97 |
+ Target string `json:",omitempty"` |
|
| 98 |
+ Aliases []string `json:",omitempty"` |
|
| 99 |
+ DriverOpts map[string]string `json:",omitempty"` |
|
| 99 | 100 |
} |
| 100 | 101 |
|
| 101 | 102 |
// NetworkAttachment represents a network attachment. |
| ... | ... |
@@ -645,7 +645,11 @@ func (container *Container) BuildJoinOptions(n libnetwork.Network) ([]libnetwork |
| 645 | 645 |
} |
| 646 | 646 |
joinOptions = append(joinOptions, libnetwork.CreateOptionAlias(name, alias)) |
| 647 | 647 |
} |
| 648 |
+ for k, v := range epConfig.DriverOpts {
|
|
| 649 |
+ joinOptions = append(joinOptions, libnetwork.EndpointOptionGeneric(options.Generic{k: v}))
|
|
| 650 |
+ } |
|
| 648 | 651 |
} |
| 652 |
+ |
|
| 649 | 653 |
return joinOptions, nil |
| 650 | 654 |
} |
| 651 | 655 |
|
| ... | ... |
@@ -743,6 +747,10 @@ func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epC |
| 743 | 743 |
|
| 744 | 744 |
createOptions = append(createOptions, libnetwork.EndpointOptionGeneric(genericOption)) |
| 745 | 745 |
} |
| 746 |
+ for k, v := range epConfig.DriverOpts {
|
|
| 747 |
+ createOptions = append(createOptions, libnetwork.EndpointOptionGeneric(options.Generic{k: v}))
|
|
| 748 |
+ } |
|
| 749 |
+ |
|
| 746 | 750 |
} |
| 747 | 751 |
|
| 748 | 752 |
// Port-mapping rules belong to the container & applicable only to non-internal networks |
| ... | ... |
@@ -80,7 +80,9 @@ func serviceSpecFromGRPC(spec *swarmapi.ServiceSpec) (*types.ServiceSpec, error) |
| 80 | 80 |
|
| 81 | 81 |
serviceNetworks := make([]types.NetworkAttachmentConfig, 0, len(spec.Networks)) |
| 82 | 82 |
for _, n := range spec.Networks {
|
| 83 |
- serviceNetworks = append(serviceNetworks, types.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases})
|
|
| 83 |
+ netConfig := types.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases, DriverOpts: n.DriverAttachmentOpts}
|
|
| 84 |
+ serviceNetworks = append(serviceNetworks, netConfig) |
|
| 85 |
+ |
|
| 84 | 86 |
} |
| 85 | 87 |
|
| 86 | 88 |
taskTemplate := taskSpecFromGRPC(spec.Task) |
| ... | ... |
@@ -136,12 +138,15 @@ func ServiceSpecToGRPC(s types.ServiceSpec) (swarmapi.ServiceSpec, error) {
|
| 136 | 136 |
|
| 137 | 137 |
serviceNetworks := make([]*swarmapi.NetworkAttachmentConfig, 0, len(s.Networks)) |
| 138 | 138 |
for _, n := range s.Networks {
|
| 139 |
- serviceNetworks = append(serviceNetworks, &swarmapi.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases})
|
|
| 139 |
+ netConfig := &swarmapi.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases, DriverAttachmentOpts: n.DriverOpts}
|
|
| 140 |
+ serviceNetworks = append(serviceNetworks, netConfig) |
|
| 140 | 141 |
} |
| 141 | 142 |
|
| 142 | 143 |
taskNetworks := make([]*swarmapi.NetworkAttachmentConfig, 0, len(s.TaskTemplate.Networks)) |
| 143 | 144 |
for _, n := range s.TaskTemplate.Networks {
|
| 144 |
- taskNetworks = append(taskNetworks, &swarmapi.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases})
|
|
| 145 |
+ netConfig := &swarmapi.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases, DriverAttachmentOpts: n.DriverOpts}
|
|
| 146 |
+ taskNetworks = append(taskNetworks, netConfig) |
|
| 147 |
+ |
|
| 145 | 148 |
} |
| 146 | 149 |
|
| 147 | 150 |
spec := swarmapi.ServiceSpec{
|
| ... | ... |
@@ -507,7 +512,8 @@ func updateConfigToGRPC(updateConfig *types.UpdateConfig) (*swarmapi.UpdateConfi |
| 507 | 507 |
func taskSpecFromGRPC(taskSpec swarmapi.TaskSpec) types.TaskSpec {
|
| 508 | 508 |
taskNetworks := make([]types.NetworkAttachmentConfig, 0, len(taskSpec.Networks)) |
| 509 | 509 |
for _, n := range taskSpec.Networks {
|
| 510 |
- taskNetworks = append(taskNetworks, types.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases})
|
|
| 510 |
+ netConfig := types.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases, DriverOpts: n.DriverAttachmentOpts}
|
|
| 511 |
+ taskNetworks = append(taskNetworks, netConfig) |
|
| 511 | 512 |
} |
| 512 | 513 |
|
| 513 | 514 |
c := taskSpec.GetContainer() |
| ... | ... |
@@ -494,6 +494,8 @@ func getEndpointConfig(na *api.NetworkAttachment, b executorpkg.Backend) *networ |
| 494 | 494 |
IPv4Address: ipv4, |
| 495 | 495 |
IPv6Address: ipv6, |
| 496 | 496 |
}, |
| 497 |
+ Aliases: na.Aliases, |
|
| 498 |
+ DriverOpts: na.DriverAttachmentOpts, |
|
| 497 | 499 |
} |
| 498 | 500 |
if v, ok := na.Network.Spec.Annotations.Labels["com.docker.swarm.predefined"]; ok && v == "true" {
|
| 499 | 501 |
if ln, err := b.FindNetwork(na.Network.Spec.Annotations.Name); err == nil {
|