2015-05-16 02:34:26 +03:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-01-08 06:43:11 +03:00
|
|
|
"os"
|
2015-11-19 01:20:54 +03:00
|
|
|
"strings"
|
2015-05-16 02:34:26 +03:00
|
|
|
|
2016-03-10 07:33:21 +03:00
|
|
|
"github.com/Microsoft/hcsshim"
|
2015-09-23 02:05:00 +03:00
|
|
|
"github.com/Sirupsen/logrus"
|
2016-09-06 21:18:12 +03:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
containertypes "github.com/docker/docker/api/types/container"
|
2015-11-12 22:55:17 +03:00
|
|
|
"github.com/docker/docker/container"
|
2015-11-19 01:20:54 +03:00
|
|
|
"github.com/docker/docker/image"
|
2016-01-08 06:43:11 +03:00
|
|
|
"github.com/docker/docker/pkg/idtools"
|
2016-03-18 21:53:27 +03:00
|
|
|
"github.com/docker/docker/pkg/parsers"
|
2016-09-08 02:08:51 +03:00
|
|
|
"github.com/docker/docker/pkg/platform"
|
2016-02-25 04:51:46 +03:00
|
|
|
"github.com/docker/docker/pkg/sysinfo"
|
2015-10-15 21:40:14 +03:00
|
|
|
"github.com/docker/docker/pkg/system"
|
2016-02-25 04:51:46 +03:00
|
|
|
"github.com/docker/docker/runconfig"
|
2015-05-16 02:34:26 +03:00
|
|
|
"github.com/docker/libnetwork"
|
2016-02-18 04:08:11 +03:00
|
|
|
nwconfig "github.com/docker/libnetwork/config"
|
2016-11-10 04:54:15 +03:00
|
|
|
"github.com/docker/libnetwork/datastore"
|
2016-03-10 07:33:21 +03:00
|
|
|
winlibnetwork "github.com/docker/libnetwork/drivers/windows"
|
|
|
|
"github.com/docker/libnetwork/netlabel"
|
|
|
|
"github.com/docker/libnetwork/options"
|
2015-06-12 03:34:20 +03:00
|
|
|
blkiodev "github.com/opencontainers/runc/libcontainer/configs"
|
2016-11-18 23:34:25 +03:00
|
|
|
"golang.org/x/sys/windows"
|
2015-05-16 02:34:26 +03:00
|
|
|
)
|
|
|
|
|
2015-08-07 19:33:29 +03:00
|
|
|
const (
|
2016-11-01 23:02:46 +03:00
|
|
|
defaultNetworkSpace = "172.16.0.0/12"
|
|
|
|
platformSupported = true
|
|
|
|
windowsMinCPUShares = 1
|
|
|
|
windowsMaxCPUShares = 10000
|
|
|
|
windowsMinCPUPercent = 1
|
|
|
|
windowsMaxCPUPercent = 100
|
|
|
|
windowsMinCPUCount = 1
|
2015-08-07 19:33:29 +03:00
|
|
|
)
|
2015-07-13 22:34:58 +03:00
|
|
|
|
2016-03-18 21:53:27 +03:00
|
|
|
func getBlkioWeightDevices(config *containertypes.HostConfig) ([]blkiodev.WeightDevice, error) {
|
2015-06-12 03:34:20 +03:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2015-12-18 21:36:17 +03:00
|
|
|
func parseSecurityOpt(container *container.Container, config *containertypes.HostConfig) error {
|
2015-05-16 02:34:26 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-03-18 21:53:27 +03:00
|
|
|
func getBlkioReadIOpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) {
|
2015-07-08 14:06:48 +03:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2016-03-18 21:53:27 +03:00
|
|
|
func getBlkioWriteIOpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) {
|
2015-07-08 14:06:48 +03:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2016-03-18 21:53:27 +03:00
|
|
|
func getBlkioReadBpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) {
|
2015-07-08 14:06:48 +03:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2016-03-18 21:53:27 +03:00
|
|
|
func getBlkioWriteBpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) {
|
2015-07-08 14:06:48 +03:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2015-10-08 18:51:41 +03:00
|
|
|
func setupInitLayer(initLayer string, rootUID, rootGID int) error {
|
2015-05-16 02:34:26 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-09-21 21:45:25 +03:00
|
|
|
func (daemon *Daemon) getLayerInit() func(string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-05-16 02:34:26 +03:00
|
|
|
func checkKernel() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-02-18 13:10:31 +03:00
|
|
|
func (daemon *Daemon) getCgroupDriver() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2015-07-31 01:28:11 +03:00
|
|
|
// adaptContainerSettings is called during container creation to modify any
|
|
|
|
// settings necessary in the HostConfig structure.
|
2015-12-18 21:36:17 +03:00
|
|
|
func (daemon *Daemon) adaptContainerSettings(hostConfig *containertypes.HostConfig, adjustCPUShares bool) error {
|
2015-09-24 22:10:41 +03:00
|
|
|
if hostConfig == nil {
|
2015-12-02 05:53:52 +03:00
|
|
|
return nil
|
2015-09-24 22:10:41 +03:00
|
|
|
}
|
|
|
|
|
2015-12-02 05:53:52 +03:00
|
|
|
return nil
|
2015-07-13 10:17:43 +03:00
|
|
|
}
|
|
|
|
|
2016-11-01 23:02:46 +03:00
|
|
|
func verifyContainerResources(resources *containertypes.Resources, isHyperv bool) ([]string, error) {
|
2016-03-05 04:24:09 +03:00
|
|
|
warnings := []string{}
|
|
|
|
|
2016-11-01 23:02:46 +03:00
|
|
|
if !isHyperv {
|
|
|
|
// The processor resource controls are mutually exclusive on
|
|
|
|
// Windows Server Containers, the order of precedence is
|
|
|
|
// CPUCount first, then CPUShares, and CPUPercent last.
|
|
|
|
if resources.CPUCount > 0 {
|
|
|
|
if resources.CPUShares > 0 {
|
|
|
|
warnings = append(warnings, "Conflicting options: CPU count takes priority over CPU shares on Windows Server Containers. CPU shares discarded")
|
|
|
|
logrus.Warn("Conflicting options: CPU count takes priority over CPU shares on Windows Server Containers. CPU shares discarded")
|
|
|
|
resources.CPUShares = 0
|
|
|
|
}
|
|
|
|
if resources.CPUPercent > 0 {
|
|
|
|
warnings = append(warnings, "Conflicting options: CPU count takes priority over CPU percent on Windows Server Containers. CPU percent discarded")
|
|
|
|
logrus.Warn("Conflicting options: CPU count takes priority over CPU percent on Windows Server Containers. CPU percent discarded")
|
|
|
|
resources.CPUPercent = 0
|
|
|
|
}
|
|
|
|
} else if resources.CPUShares > 0 {
|
|
|
|
if resources.CPUPercent > 0 {
|
|
|
|
warnings = append(warnings, "Conflicting options: CPU shares takes priority over CPU percent on Windows Server Containers. CPU percent discarded")
|
|
|
|
logrus.Warn("Conflicting options: CPU shares takes priority over CPU percent on Windows Server Containers. CPU percent discarded")
|
|
|
|
resources.CPUPercent = 0
|
|
|
|
}
|
|
|
|
}
|
2016-03-05 04:24:09 +03:00
|
|
|
}
|
|
|
|
|
2016-11-10 02:18:54 +03:00
|
|
|
if resources.CPUShares < 0 || resources.CPUShares > windowsMaxCPUShares {
|
|
|
|
return warnings, fmt.Errorf("range of CPUShares is from %d to %d", windowsMinCPUShares, windowsMaxCPUShares)
|
|
|
|
}
|
|
|
|
if resources.CPUPercent < 0 || resources.CPUPercent > windowsMaxCPUPercent {
|
|
|
|
return warnings, fmt.Errorf("range of CPUPercent is from %d to %d", windowsMinCPUPercent, windowsMaxCPUPercent)
|
|
|
|
}
|
|
|
|
if resources.CPUCount < 0 {
|
|
|
|
return warnings, fmt.Errorf("invalid CPUCount: CPUCount cannot be negative")
|
2016-11-01 20:12:29 +03:00
|
|
|
}
|
|
|
|
|
2016-11-10 02:18:54 +03:00
|
|
|
if resources.NanoCPUs > 0 && resources.CPUPercent > 0 {
|
|
|
|
return warnings, fmt.Errorf("conflicting options: Nano CPUs and CPU Percent cannot both be set")
|
|
|
|
}
|
2016-11-01 20:12:29 +03:00
|
|
|
if resources.NanoCPUs > 0 && resources.CPUShares > 0 {
|
2016-11-10 02:18:54 +03:00
|
|
|
return warnings, fmt.Errorf("conflicting options: Nano CPUs and CPU Shares cannot both be set")
|
2016-11-01 20:12:29 +03:00
|
|
|
}
|
2016-11-16 02:48:46 +03:00
|
|
|
// The precision we could get is 0.01, because on Windows we have to convert to CPUPercent.
|
|
|
|
// We don't set the lower limit here and it is up to the underlying platform (e.g., Windows) to return an error.
|
2016-11-01 20:12:29 +03:00
|
|
|
if resources.NanoCPUs < 0 || resources.NanoCPUs > int64(sysinfo.NumCPU())*1e9 {
|
2016-11-16 02:48:46 +03:00
|
|
|
return warnings, fmt.Errorf("range of CPUs is from 0.01 to %d.00, as there are only %d CPUs available", sysinfo.NumCPU(), sysinfo.NumCPU())
|
2016-11-01 20:12:29 +03:00
|
|
|
}
|
|
|
|
|
2016-11-10 02:18:54 +03:00
|
|
|
if len(resources.BlkioDeviceReadBps) > 0 {
|
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support BlkioDeviceReadBps")
|
|
|
|
}
|
|
|
|
if len(resources.BlkioDeviceReadIOps) > 0 {
|
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support BlkioDeviceReadIOps")
|
|
|
|
}
|
|
|
|
if len(resources.BlkioDeviceWriteBps) > 0 {
|
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support BlkioDeviceWriteBps")
|
|
|
|
}
|
|
|
|
if len(resources.BlkioDeviceWriteIOps) > 0 {
|
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support BlkioDeviceWriteIOps")
|
|
|
|
}
|
2016-02-25 04:51:46 +03:00
|
|
|
if resources.BlkioWeight > 0 {
|
2016-11-10 02:18:54 +03:00
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support BlkioWeight")
|
2016-02-25 04:51:46 +03:00
|
|
|
}
|
|
|
|
if len(resources.BlkioWeightDevice) > 0 {
|
2016-11-10 02:18:54 +03:00
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support BlkioWeightDevice")
|
2016-02-25 04:51:46 +03:00
|
|
|
}
|
2016-11-10 02:18:54 +03:00
|
|
|
if resources.CgroupParent != "" {
|
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support CgroupParent")
|
2016-02-25 04:51:46 +03:00
|
|
|
}
|
2016-11-10 02:18:54 +03:00
|
|
|
if resources.CPUPeriod != 0 {
|
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support CPUPeriod")
|
2016-02-25 04:51:46 +03:00
|
|
|
}
|
2016-11-10 02:18:54 +03:00
|
|
|
if resources.CpusetCpus != "" {
|
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support CpusetCpus")
|
2016-02-25 04:51:46 +03:00
|
|
|
}
|
2016-11-10 02:18:54 +03:00
|
|
|
if resources.CpusetMems != "" {
|
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support CpusetMems")
|
|
|
|
}
|
|
|
|
if resources.KernelMemory != 0 {
|
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support KernelMemory")
|
|
|
|
}
|
|
|
|
if resources.MemoryReservation != 0 {
|
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support MemoryReservation")
|
|
|
|
}
|
|
|
|
if resources.MemorySwap != 0 {
|
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support MemorySwap")
|
|
|
|
}
|
|
|
|
if resources.MemorySwappiness != nil && *resources.MemorySwappiness != -1 {
|
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support MemorySwappiness")
|
|
|
|
}
|
|
|
|
if resources.OomKillDisable != nil && *resources.OomKillDisable {
|
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support OomKillDisable")
|
|
|
|
}
|
|
|
|
if resources.PidsLimit != 0 {
|
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support PidsLimit")
|
|
|
|
}
|
|
|
|
if len(resources.Ulimits) != 0 {
|
|
|
|
return warnings, fmt.Errorf("invalid option: Windows does not support Ulimits")
|
2016-02-25 04:51:46 +03:00
|
|
|
}
|
2016-03-05 04:24:09 +03:00
|
|
|
return warnings, nil
|
|
|
|
}
|
|
|
|
|
2015-07-31 01:28:11 +03:00
|
|
|
// verifyPlatformContainerSettings performs platform-specific validation of the
|
|
|
|
// hostconfig and config structures.
|
2016-02-24 08:36:47 +03:00
|
|
|
func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) {
|
2016-03-05 04:24:09 +03:00
|
|
|
warnings := []string{}
|
|
|
|
|
2016-11-11 01:35:19 +03:00
|
|
|
hyperv := daemon.runAsHyperVContainer(hostConfig)
|
|
|
|
if !hyperv && system.IsWindowsClient() {
|
|
|
|
// @engine maintainers. This block should not be removed. It partially enforces licensing
|
|
|
|
// restrictions on Windows. Ping @jhowardmsft if there are concerns or PRs to change this.
|
|
|
|
return warnings, fmt.Errorf("Windows client operating systems only support Hyper-V containers")
|
|
|
|
}
|
|
|
|
|
|
|
|
w, err := verifyContainerResources(&hostConfig.Resources, hyperv)
|
2016-03-05 04:24:09 +03:00
|
|
|
warnings = append(warnings, w...)
|
|
|
|
if err != nil {
|
|
|
|
return warnings, err
|
|
|
|
}
|
|
|
|
return warnings, nil
|
2015-05-16 02:34:26 +03:00
|
|
|
}
|
|
|
|
|
2016-05-24 00:49:50 +03:00
|
|
|
// platformReload update configuration with platform specific options
|
2016-10-10 19:25:44 +03:00
|
|
|
func (daemon *Daemon) platformReload(config *Config) map[string]string {
|
|
|
|
return map[string]string{}
|
2016-05-24 00:49:50 +03:00
|
|
|
}
|
|
|
|
|
2016-01-23 05:15:09 +03:00
|
|
|
// verifyDaemonSettings performs validation of daemon config struct
|
|
|
|
func verifyDaemonSettings(config *Config) error {
|
2015-05-16 02:34:26 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-11 22:32:08 +03:00
|
|
|
// checkSystem validates platform-specific requirements
|
2015-05-16 02:34:26 +03:00
|
|
|
func checkSystem() error {
|
|
|
|
// Validate the OS version. Note that docker.exe must be manifested for this
|
|
|
|
// call to return the correct version.
|
2016-03-17 04:45:40 +03:00
|
|
|
osv := system.GetOSVersion()
|
2015-10-15 21:40:14 +03:00
|
|
|
if osv.MajorVersion < 10 {
|
2015-05-16 02:34:26 +03:00
|
|
|
return fmt.Errorf("This version of Windows does not support the docker daemon")
|
|
|
|
}
|
2016-09-16 01:20:16 +03:00
|
|
|
if osv.Build < 14393 {
|
|
|
|
return fmt.Errorf("The docker daemon requires build 14393 or later of Windows Server 2016 or Windows 10")
|
2015-11-12 01:47:02 +03:00
|
|
|
}
|
2016-11-18 23:34:25 +03:00
|
|
|
|
|
|
|
vmcompute := windows.NewLazySystemDLL("vmcompute.dll")
|
|
|
|
if vmcompute.Load() != nil {
|
|
|
|
return fmt.Errorf("Failed to load vmcompute.dll. Ensure that the Containers role is installed.")
|
|
|
|
}
|
2015-05-16 02:34:26 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// configureKernelSecuritySupport configures and validate security support for the kernel
|
|
|
|
func configureKernelSecuritySupport(config *Config, driverName string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-02 13:26:30 +03:00
|
|
|
// configureMaxThreads sets the Go runtime max threads threshold
|
|
|
|
func configureMaxThreads(config *Config) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-06-14 19:13:53 +03:00
|
|
|
func (daemon *Daemon) initNetworkController(config *Config, activeSandboxes map[string]interface{}) (libnetwork.NetworkController, error) {
|
2016-09-26 20:08:52 +03:00
|
|
|
netOptions, err := daemon.networkOptions(config, nil, nil)
|
2016-03-10 07:33:21 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
controller, err := libnetwork.New(netOptions...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error obtaining controller instance: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
hnsresponse, err := hcsshim.HNSListNetworkRequest("GET", "", "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove networks not present in HNS
|
|
|
|
for _, v := range controller.Networks() {
|
|
|
|
options := v.Info().DriverOptions()
|
|
|
|
hnsid := options[winlibnetwork.HNSID]
|
|
|
|
found := false
|
|
|
|
|
|
|
|
for _, v := range hnsresponse {
|
|
|
|
if v.Id == hnsid {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found {
|
2016-11-10 04:54:15 +03:00
|
|
|
// global networks should not be deleted by local HNS
|
|
|
|
if v.Info().Scope() != datastore.GlobalScope {
|
|
|
|
err = v.Delete()
|
|
|
|
if err != nil {
|
|
|
|
logrus.Errorf("Error occurred when removing network %v", err)
|
|
|
|
}
|
2016-03-10 07:33:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-08 10:33:16 +03:00
|
|
|
_, err = controller.NewNetwork("null", "none", "", libnetwork.NetworkOptionPersist(false))
|
2016-03-10 07:33:21 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-06-09 22:09:13 +03:00
|
|
|
defaultNetworkExists := false
|
|
|
|
|
|
|
|
if network, err := controller.NetworkByName(runconfig.DefaultDaemonNetworkMode().NetworkName()); err == nil {
|
|
|
|
options := network.Info().DriverOptions()
|
|
|
|
for _, v := range hnsresponse {
|
|
|
|
if options[winlibnetwork.HNSID] == v.Id {
|
|
|
|
defaultNetworkExists = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-10 07:33:21 +03:00
|
|
|
// discover and add HNS networks to windows
|
|
|
|
// network that exist are removed and added again
|
|
|
|
for _, v := range hnsresponse {
|
|
|
|
var n libnetwork.Network
|
|
|
|
s := func(current libnetwork.Network) bool {
|
|
|
|
options := current.Info().DriverOptions()
|
|
|
|
if options[winlibnetwork.HNSID] == v.Id {
|
|
|
|
n = current
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
controller.WalkNetworks(s)
|
|
|
|
if n != nil {
|
2016-11-10 04:54:15 +03:00
|
|
|
// global networks should not be deleted by local HNS
|
|
|
|
if n.Info().Scope() == datastore.GlobalScope {
|
|
|
|
continue
|
|
|
|
}
|
2016-03-10 07:33:21 +03:00
|
|
|
v.Name = n.Name()
|
2016-06-09 22:09:13 +03:00
|
|
|
// This will not cause network delete from HNS as the network
|
|
|
|
// is not yet populated in the libnetwork windows driver
|
2016-03-10 07:33:21 +03:00
|
|
|
n.Delete()
|
|
|
|
}
|
|
|
|
|
|
|
|
netOption := map[string]string{
|
|
|
|
winlibnetwork.NetworkName: v.Name,
|
|
|
|
winlibnetwork.HNSID: v.Id,
|
|
|
|
}
|
|
|
|
|
|
|
|
v4Conf := []*libnetwork.IpamConf{}
|
|
|
|
for _, subnet := range v.Subnets {
|
|
|
|
ipamV4Conf := libnetwork.IpamConf{}
|
|
|
|
ipamV4Conf.PreferredPool = subnet.AddressPrefix
|
|
|
|
ipamV4Conf.Gateway = subnet.GatewayAddress
|
|
|
|
v4Conf = append(v4Conf, &ipamV4Conf)
|
|
|
|
}
|
|
|
|
|
|
|
|
name := v.Name
|
2016-06-09 22:09:13 +03:00
|
|
|
|
|
|
|
// If there is no nat network create one from the first NAT network
|
|
|
|
// encountered
|
|
|
|
if !defaultNetworkExists && runconfig.DefaultDaemonNetworkMode() == containertypes.NetworkMode(strings.ToLower(v.Type)) {
|
2016-03-10 07:33:21 +03:00
|
|
|
name = runconfig.DefaultDaemonNetworkMode().NetworkName()
|
2016-06-09 22:09:13 +03:00
|
|
|
defaultNetworkExists = true
|
2016-03-10 07:33:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
v6Conf := []*libnetwork.IpamConf{}
|
2016-05-08 10:33:16 +03:00
|
|
|
_, err := controller.NewNetwork(strings.ToLower(v.Type), name, "",
|
2016-03-10 07:33:21 +03:00
|
|
|
libnetwork.NetworkOptionGeneric(options.Generic{
|
|
|
|
netlabel.GenericData: netOption,
|
|
|
|
}),
|
|
|
|
libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf, nil),
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
logrus.Errorf("Error occurred when creating network %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !config.DisableBridge {
|
|
|
|
// Initialize default driver "bridge"
|
|
|
|
if err := initBridgeDriver(controller, config); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return controller, nil
|
2015-05-16 02:34:26 +03:00
|
|
|
}
|
|
|
|
|
2016-03-10 07:33:21 +03:00
|
|
|
func initBridgeDriver(controller libnetwork.NetworkController, config *Config) error {
|
|
|
|
if _, err := controller.NetworkByName(runconfig.DefaultDaemonNetworkMode().NetworkName()); err == nil {
|
|
|
|
return nil
|
2015-07-13 22:34:58 +03:00
|
|
|
}
|
2016-03-10 07:33:21 +03:00
|
|
|
|
|
|
|
netOption := map[string]string{
|
|
|
|
winlibnetwork.NetworkName: runconfig.DefaultDaemonNetworkMode().NetworkName(),
|
|
|
|
}
|
|
|
|
|
2016-06-09 22:09:13 +03:00
|
|
|
var ipamOption libnetwork.NetworkOption
|
|
|
|
var subnetPrefix string
|
|
|
|
|
|
|
|
if config.bridgeConfig.FixedCIDR != "" {
|
|
|
|
subnetPrefix = config.bridgeConfig.FixedCIDR
|
2016-03-10 07:33:21 +03:00
|
|
|
} else {
|
2016-06-09 22:09:13 +03:00
|
|
|
// TP5 doesn't support properly detecting subnet
|
|
|
|
osv := system.GetOSVersion()
|
|
|
|
if osv.Build < 14360 {
|
|
|
|
subnetPrefix = defaultNetworkSpace
|
|
|
|
}
|
2016-03-10 07:33:21 +03:00
|
|
|
}
|
|
|
|
|
2016-06-09 22:09:13 +03:00
|
|
|
if subnetPrefix != "" {
|
|
|
|
ipamV4Conf := libnetwork.IpamConf{}
|
|
|
|
ipamV4Conf.PreferredPool = subnetPrefix
|
|
|
|
v4Conf := []*libnetwork.IpamConf{&ipamV4Conf}
|
|
|
|
v6Conf := []*libnetwork.IpamConf{}
|
|
|
|
ipamOption = libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf, nil)
|
|
|
|
}
|
2016-03-10 07:33:21 +03:00
|
|
|
|
2016-05-08 10:33:16 +03:00
|
|
|
_, err := controller.NewNetwork(string(runconfig.DefaultDaemonNetworkMode()), runconfig.DefaultDaemonNetworkMode().NetworkName(), "",
|
2016-03-10 07:33:21 +03:00
|
|
|
libnetwork.NetworkOptionGeneric(options.Generic{
|
|
|
|
netlabel.GenericData: netOption,
|
|
|
|
}),
|
2016-06-09 22:09:13 +03:00
|
|
|
ipamOption,
|
2016-03-10 07:33:21 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error creating default network: %v", err)
|
|
|
|
}
|
2016-06-09 22:09:13 +03:00
|
|
|
|
2016-03-10 07:33:21 +03:00
|
|
|
return nil
|
2015-05-16 02:34:26 +03:00
|
|
|
}
|
2015-06-23 20:13:42 +03:00
|
|
|
|
2015-07-31 00:01:53 +03:00
|
|
|
// registerLinks sets up links between containers and writes the
|
2015-11-16 08:32:31 +03:00
|
|
|
// configuration out for persistence. As of Windows TP4, links are not supported.
|
2015-12-18 21:36:17 +03:00
|
|
|
func (daemon *Daemon) registerLinks(container *container.Container, hostConfig *containertypes.HostConfig) error {
|
2015-06-23 20:13:42 +03:00
|
|
|
return nil
|
|
|
|
}
|
2015-07-17 00:14:58 +03:00
|
|
|
|
2016-03-18 21:53:27 +03:00
|
|
|
func (daemon *Daemon) cleanupMountsByID(in string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-08-04 01:05:34 +03:00
|
|
|
func (daemon *Daemon) cleanupMounts() error {
|
|
|
|
return nil
|
|
|
|
}
|
2015-11-03 04:06:09 +03:00
|
|
|
|
2016-01-08 06:43:11 +03:00
|
|
|
func setupRemappedRoot(config *Config) ([]idtools.IDMap, []idtools.IDMap, error) {
|
|
|
|
return nil, nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func setupDaemonRoot(config *Config, rootDir string, rootUID, rootGID int) error {
|
|
|
|
config.Root = rootDir
|
|
|
|
// Create the root directory if it doesn't exists
|
2016-11-04 22:42:21 +03:00
|
|
|
if err := system.MkdirAllWithACL(config.Root, 0); err != nil && !os.IsExist(err) {
|
2016-01-08 06:43:11 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-03-19 06:09:54 +03:00
|
|
|
// runasHyperVContainer returns true if we are going to run as a Hyper-V container
|
2016-11-01 23:02:46 +03:00
|
|
|
func (daemon *Daemon) runAsHyperVContainer(hostConfig *containertypes.HostConfig) bool {
|
|
|
|
if hostConfig.Isolation.IsDefault() {
|
2016-03-18 21:53:27 +03:00
|
|
|
// Container is set to use the default, so take the default from the daemon configuration
|
2016-03-19 06:09:54 +03:00
|
|
|
return daemon.defaultIsolation.IsHyperV()
|
2016-03-18 21:53:27 +03:00
|
|
|
}
|
|
|
|
|
2016-03-19 06:09:54 +03:00
|
|
|
// Container is requesting an isolation mode. Honour it.
|
2016-11-01 23:02:46 +03:00
|
|
|
return hostConfig.Isolation.IsHyperV()
|
2016-03-19 06:09:54 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// conditionalMountOnStart is a platform specific helper function during the
|
|
|
|
// container start to call mount.
|
|
|
|
func (daemon *Daemon) conditionalMountOnStart(container *container.Container) error {
|
2015-11-03 04:06:09 +03:00
|
|
|
// We do not mount if a Hyper-V container
|
2016-11-01 23:02:46 +03:00
|
|
|
if !daemon.runAsHyperVContainer(container.HostConfig) {
|
2016-03-19 06:09:54 +03:00
|
|
|
return daemon.Mount(container)
|
2015-11-03 04:06:09 +03:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// conditionalUnmountOnCleanup is a platform specific helper function called
|
|
|
|
// during the cleanup of a container to unmount.
|
2016-03-18 21:53:27 +03:00
|
|
|
func (daemon *Daemon) conditionalUnmountOnCleanup(container *container.Container) error {
|
2015-11-03 04:06:09 +03:00
|
|
|
// We do not unmount if a Hyper-V container
|
2016-11-01 23:02:46 +03:00
|
|
|
if !daemon.runAsHyperVContainer(container.HostConfig) {
|
2016-03-18 21:53:27 +03:00
|
|
|
return daemon.Unmount(container)
|
2015-11-19 01:20:54 +03:00
|
|
|
}
|
2016-03-18 21:53:27 +03:00
|
|
|
return nil
|
2015-11-19 01:20:54 +03:00
|
|
|
}
|
|
|
|
|
2016-03-10 07:33:21 +03:00
|
|
|
func driverOptions(config *Config) []nwconfig.Option {
|
|
|
|
return []nwconfig.Option{}
|
2016-02-18 04:08:11 +03:00
|
|
|
}
|
2016-03-18 21:53:27 +03:00
|
|
|
|
|
|
|
func (daemon *Daemon) stats(c *container.Container) (*types.StatsJSON, error) {
|
2016-09-08 02:08:51 +03:00
|
|
|
if !c.IsRunning() {
|
|
|
|
return nil, errNotRunning{c.ID}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain the stats from HCS via libcontainerd
|
|
|
|
stats, err := daemon.containerd.Stats(c.ID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start with an empty structure
|
|
|
|
s := &types.StatsJSON{}
|
|
|
|
|
|
|
|
// Populate the CPU/processor statistics
|
|
|
|
s.CPUStats = types.CPUStats{
|
|
|
|
CPUUsage: types.CPUUsage{
|
|
|
|
TotalUsage: stats.Processor.TotalRuntime100ns,
|
|
|
|
UsageInKernelmode: stats.Processor.RuntimeKernel100ns,
|
|
|
|
UsageInUsermode: stats.Processor.RuntimeKernel100ns,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate the memory statistics
|
|
|
|
s.MemoryStats = types.MemoryStats{
|
|
|
|
Commit: stats.Memory.UsageCommitBytes,
|
|
|
|
CommitPeak: stats.Memory.UsageCommitPeakBytes,
|
|
|
|
PrivateWorkingSet: stats.Memory.UsagePrivateWorkingSetBytes,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate the storage statistics
|
|
|
|
s.StorageStats = types.StorageStats{
|
|
|
|
ReadCountNormalized: stats.Storage.ReadCountNormalized,
|
|
|
|
ReadSizeBytes: stats.Storage.ReadSizeBytes,
|
|
|
|
WriteCountNormalized: stats.Storage.WriteCountNormalized,
|
|
|
|
WriteSizeBytes: stats.Storage.WriteSizeBytes,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate the network statistics
|
|
|
|
s.Networks = make(map[string]types.NetworkStats)
|
|
|
|
|
|
|
|
for _, nstats := range stats.Network {
|
|
|
|
s.Networks[nstats.EndpointId] = types.NetworkStats{
|
|
|
|
RxBytes: nstats.BytesReceived,
|
|
|
|
RxPackets: nstats.PacketsReceived,
|
|
|
|
RxDropped: nstats.DroppedPacketsIncoming,
|
|
|
|
TxBytes: nstats.BytesSent,
|
|
|
|
TxPackets: nstats.PacketsSent,
|
|
|
|
TxDropped: nstats.DroppedPacketsOutgoing,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the timestamp
|
|
|
|
s.Stats.Read = stats.Timestamp
|
|
|
|
s.Stats.NumProcs = platform.NumProcs()
|
|
|
|
|
|
|
|
return s, nil
|
2016-03-18 21:53:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// setDefaultIsolation determine the default isolation mode for the
|
|
|
|
// daemon to run in. This is only applicable on Windows
|
|
|
|
func (daemon *Daemon) setDefaultIsolation() error {
|
|
|
|
daemon.defaultIsolation = containertypes.Isolation("process")
|
2016-04-15 03:12:02 +03:00
|
|
|
// On client SKUs, default to Hyper-V
|
|
|
|
if system.IsWindowsClient() {
|
|
|
|
daemon.defaultIsolation = containertypes.Isolation("hyperv")
|
|
|
|
}
|
2016-03-18 21:53:27 +03:00
|
|
|
for _, option := range daemon.configStore.ExecOptions {
|
|
|
|
key, val, err := parsers.ParseKeyValueOpt(option)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
key = strings.ToLower(key)
|
|
|
|
switch key {
|
|
|
|
|
|
|
|
case "isolation":
|
|
|
|
if !containertypes.Isolation(val).IsValid() {
|
|
|
|
return fmt.Errorf("Invalid exec-opt value for 'isolation':'%s'", val)
|
|
|
|
}
|
|
|
|
if containertypes.Isolation(val).IsHyperV() {
|
|
|
|
daemon.defaultIsolation = containertypes.Isolation("hyperv")
|
|
|
|
}
|
2016-04-15 03:12:02 +03:00
|
|
|
if containertypes.Isolation(val).IsProcess() {
|
|
|
|
if system.IsWindowsClient() {
|
2016-10-25 20:30:00 +03:00
|
|
|
// @engine maintainers. This block should not be removed. It partially enforces licensing
|
|
|
|
// restrictions on Windows. Ping @jhowardmsft if there are concerns or PRs to change this.
|
2016-04-15 03:12:02 +03:00
|
|
|
return fmt.Errorf("Windows client operating systems only support Hyper-V containers")
|
|
|
|
}
|
|
|
|
daemon.defaultIsolation = containertypes.Isolation("process")
|
|
|
|
}
|
2016-03-18 21:53:27 +03:00
|
|
|
default:
|
|
|
|
return fmt.Errorf("Unrecognised exec-opt '%s'\n", key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logrus.Infof("Windows default isolation mode: %s", daemon.defaultIsolation)
|
|
|
|
return nil
|
|
|
|
}
|
2016-03-21 19:56:51 +03:00
|
|
|
|
|
|
|
func rootFSToAPIType(rootfs *image.RootFS) types.RootFS {
|
|
|
|
var layers []string
|
|
|
|
for _, l := range rootfs.DiffIDs {
|
|
|
|
layers = append(layers, l.String())
|
|
|
|
}
|
|
|
|
return types.RootFS{
|
2016-07-23 01:29:21 +03:00
|
|
|
Type: rootfs.Type,
|
|
|
|
Layers: layers,
|
2016-03-21 19:56:51 +03:00
|
|
|
}
|
|
|
|
}
|
2016-07-12 01:26:23 +03:00
|
|
|
|
|
|
|
func setupDaemonProcess(config *Config) error {
|
|
|
|
return nil
|
|
|
|
}
|
2016-09-06 16:49:10 +03:00
|
|
|
|
|
|
|
// verifyVolumesInfo is a no-op on windows.
|
|
|
|
// This is called during daemon initialization to migrate volumes from pre-1.7.
|
|
|
|
// volumes were not supported on windows pre-1.7
|
|
|
|
func (daemon *Daemon) verifyVolumesInfo(container *container.Container) error {
|
|
|
|
return nil
|
|
|
|
}
|
2016-09-02 16:20:54 +03:00
|
|
|
|
|
|
|
func (daemon *Daemon) setupSeccompProfile() error {
|
|
|
|
return nil
|
|
|
|
}
|