diff --git a/daemon/oci_windows.go b/daemon/oci_windows.go index 96c5070bab..4f2947cf79 100644 --- a/daemon/oci_windows.go +++ b/daemon/oci_windows.go @@ -69,34 +69,6 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e s.Root.Path = c.BaseFS s.Root.Readonly = c.HostConfig.ReadonlyRootfs - // In s.Windows.Networking - // Connect all the libnetwork allocated networks to the container - var epList []string - if c.NetworkSettings != nil { - for n := range c.NetworkSettings.Networks { - sn, err := daemon.FindNetwork(n) - if err != nil { - continue - } - - ep, err := c.GetEndpointInNetwork(sn) - if err != nil { - continue - } - - data, err := ep.DriverInfo() - if err != nil { - continue - } - if data["hnsid"] != nil { - epList = append(epList, data["hnsid"].(string)) - } - } - } - s.Windows.Networking = &windowsoci.WindowsNetworking{ - EndpointList: epList, - } - // In s.Windows.Resources // @darrenstahlmsft implement these resources cpuShares := uint64(c.HostConfig.CPUShares) diff --git a/daemon/start_windows.go b/daemon/start_windows.go index cae36e5806..710c8ccbf4 100644 --- a/daemon/start_windows.go +++ b/daemon/start_windows.go @@ -51,10 +51,37 @@ func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Contain layerOpts.LayerPaths = append([]string{layerPath}, layerOpts.LayerPaths...) } + // Get endpoints for the libnetwork allocated networks to the container + var epList []string + if container.NetworkSettings != nil { + for n := range container.NetworkSettings.Networks { + sn, err := daemon.FindNetwork(n) + if err != nil { + continue + } + + ep, err := container.GetEndpointInNetwork(sn) + if err != nil { + continue + } + + data, err := ep.DriverInfo() + if err != nil { + continue + } + if data["hnsid"] != nil { + epList = append(epList, data["hnsid"].(string)) + } + } + } + // Now build the full set of options createOptions = append(createOptions, &libcontainerd.FlushOption{IgnoreFlushesDuringBoot: !container.HasBeenStartedBefore}) createOptions = append(createOptions, hvOpts) createOptions = append(createOptions, layerOpts) + if epList != nil { + createOptions = append(createOptions, &libcontainerd.NetworkEndpointsOption{Endpoints: epList}) + } return &createOptions, nil } diff --git a/libcontainerd/client_windows.go b/libcontainerd/client_windows.go index 9443f40738..e3cb7a8d62 100644 --- a/libcontainerd/client_windows.go +++ b/libcontainerd/client_windows.go @@ -106,10 +106,6 @@ func (clnt *client) Create(containerID string, checkpoint string, checkpointDir HvPartition: false, } - if spec.Windows.Networking != nil { - configuration.EndpointList = spec.Windows.Networking.EndpointList - } - if spec.Windows.Resources != nil { if spec.Windows.Resources.CPU != nil { if spec.Windows.Resources.CPU.Shares != nil { @@ -151,6 +147,9 @@ func (clnt *client) Create(containerID string, checkpoint string, checkpointDir } if l, ok := option.(*LayerOption); ok { layerOpt = l + } + if n, ok := option.(*NetworkEndpointsOption); ok { + configuration.EndpointList = n.Endpoints continue } } diff --git a/libcontainerd/types_windows.go b/libcontainerd/types_windows.go index 56f243cbbf..89652f1ff9 100644 --- a/libcontainerd/types_windows.go +++ b/libcontainerd/types_windows.go @@ -32,13 +32,13 @@ type Stats hcsshim.Statistics // Resources defines updatable container resource values. type Resources struct{} -// ServicingOption is an empty CreateOption with a no-op application that signifies +// ServicingOption is a CreateOption with a no-op application that signifies // the container needs to be used for a Windows servicing operation. type ServicingOption struct { IsServicing bool } -// FlushOption is an empty CreateOption that signifies if the container should be +// FlushOption is a CreateOption that signifies if the container should be // started with flushes ignored until boot has completed. This is an optimisation // for first boot of a container. type FlushOption struct { @@ -61,6 +61,12 @@ type LayerOption struct { LayerPaths []string } +// NetworkEndpointsOption is a CreateOption that provides the runtime list +// of network endpoints to which a container should be attached during its creation. +type NetworkEndpointsOption struct { + Endpoints []string +} + // Checkpoint holds the details of a checkpoint (not supported in windows) type Checkpoint struct { Name string diff --git a/libcontainerd/utils_windows.go b/libcontainerd/utils_windows.go index 5c43603538..77fd5dacf2 100644 --- a/libcontainerd/utils_windows.go +++ b/libcontainerd/utils_windows.go @@ -34,3 +34,8 @@ func (h *HyperVIsolationOption) Apply(interface{}) error { func (h *LayerOption) Apply(interface{}) error { return nil } + +// Apply for the network endpoints option is a no-op. +func (s *NetworkEndpointsOption) Apply(interface{}) error { + return nil +} diff --git a/libcontainerd/windowsoci/oci_windows.go b/libcontainerd/windowsoci/oci_windows.go index f4621e35ee..aa54e333aa 100644 --- a/libcontainerd/windowsoci/oci_windows.go +++ b/libcontainerd/windowsoci/oci_windows.go @@ -37,8 +37,6 @@ type Spec struct { type Windows struct { // Resources contains information for handling resource constraints for the container Resources *WindowsResources `json:"resources,omitempty"` - // Networking contains the platform specific network settings for the container. - Networking *WindowsNetworking `json:"networking,omitempty"` } // Process contains information to start a specific application inside the container. @@ -116,12 +114,6 @@ type Mount struct { Options []string `json:"options,omitempty"` } -// WindowsNetworking contains the platform specific network settings for the container -type WindowsNetworking struct { - // List of endpoints to be attached to the container - EndpointList []string `json:"endpoints,omitempty"` -} - // WindowsStorage contains storage resource management settings type WindowsStorage struct { // Specifies maximum Iops for the system drive