2015-04-29 22:53:35 +00:00
|
|
|
package daemon
|
|
|
|
|
2016-10-13 21:51:10 +00:00
|
|
|
import (
|
2016-12-01 16:11:15 +00:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
2016-10-13 21:51:10 +00:00
|
|
|
"github.com/docker/docker/container"
|
2016-12-01 16:11:15 +00:00
|
|
|
"github.com/docker/docker/pkg/system"
|
2016-10-13 21:51:10 +00:00
|
|
|
"github.com/docker/libnetwork"
|
2016-12-01 16:11:15 +00:00
|
|
|
"github.com/pkg/errors"
|
2016-10-13 21:51:10 +00:00
|
|
|
)
|
2015-04-29 22:53:35 +00:00
|
|
|
|
2015-11-12 19:55:17 +00:00
|
|
|
func (daemon *Daemon) setupLinkedContainers(container *container.Container) ([]string, error) {
|
2015-04-29 22:53:35 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2017-05-11 18:55:03 +00:00
|
|
|
func (daemon *Daemon) setupConfigDir(c *container.Container) (setupErr error) {
|
|
|
|
if len(c.ConfigReferences) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
localPath := c.ConfigsDirPath()
|
|
|
|
logrus.Debugf("configs: setting up config dir: %s", localPath)
|
|
|
|
|
|
|
|
// create local config root
|
2017-06-02 01:59:11 +00:00
|
|
|
if err := system.MkdirAllWithACL(localPath, 0, system.SddlAdministratorsLocalSystem); err != nil {
|
2017-05-11 18:55:03 +00:00
|
|
|
return errors.Wrap(err, "error creating config dir")
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if setupErr != nil {
|
|
|
|
if err := os.RemoveAll(localPath); err != nil {
|
|
|
|
logrus.Errorf("error cleaning up config dir: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if c.DependencyStore == nil {
|
|
|
|
return fmt.Errorf("config store is not initialized")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, configRef := range c.ConfigReferences {
|
|
|
|
// TODO (ehazlett): use type switch when more are supported
|
|
|
|
if configRef.File == nil {
|
|
|
|
logrus.Error("config target type is not a file target")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
fPath := c.ConfigFilePath(*configRef)
|
|
|
|
|
|
|
|
log := logrus.WithFields(logrus.Fields{"name": configRef.File.Name, "path": fPath})
|
|
|
|
|
|
|
|
log.Debug("injecting config")
|
2017-06-15 18:11:48 +00:00
|
|
|
config, err := c.DependencyStore.Configs().Get(configRef.ConfigID)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "unable to get config from config store")
|
2017-05-11 18:55:03 +00:00
|
|
|
}
|
|
|
|
if err := ioutil.WriteFile(fPath, config.Spec.Data, configRef.File.Mode); err != nil {
|
|
|
|
return errors.Wrap(err, "error injecting config")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-11-03 01:06:09 +00:00
|
|
|
// getSize returns real size & virtual size
|
2017-02-19 02:11:48 +00:00
|
|
|
func (daemon *Daemon) getSize(containerID string) (int64, int64) {
|
2015-04-29 22:53:35 +00:00
|
|
|
// TODO Windows
|
|
|
|
return 0, 0
|
|
|
|
}
|
|
|
|
|
2015-11-12 19:55:17 +00:00
|
|
|
func (daemon *Daemon) setupIpcDirs(container *container.Container) error {
|
2015-08-03 22:05:34 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-04-06 19:01:29 +00:00
|
|
|
// TODO Windows: Fix Post-TP5. This is a hack to allow docker cp to work
|
2015-11-12 19:55:17 +00:00
|
|
|
// against containers which have volumes. You will still be able to cp
|
|
|
|
// to somewhere on the container drive, but not to any mounted volumes
|
|
|
|
// inside the container. Without this fix, docker cp is broken to any
|
|
|
|
// container which has a volume, regardless of where the file is inside the
|
|
|
|
// container.
|
|
|
|
func (daemon *Daemon) mountVolumes(container *container.Container) error {
|
2015-08-03 22:05:34 +00:00
|
|
|
return nil
|
|
|
|
}
|
2015-09-24 21:59:23 +00:00
|
|
|
|
2015-11-12 19:55:17 +00:00
|
|
|
func detachMounted(path string) error {
|
2015-12-01 18:39:34 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-12-01 16:11:15 +00:00
|
|
|
func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
|
|
|
|
if len(c.SecretReferences) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
localMountPath := c.SecretMountPath()
|
|
|
|
logrus.Debugf("secrets: setting up secret dir: %s", localMountPath)
|
|
|
|
|
|
|
|
// create local secret root
|
2017-06-02 01:59:11 +00:00
|
|
|
if err := system.MkdirAllWithACL(localMountPath, 0, system.SddlAdministratorsLocalSystem); err != nil {
|
2016-12-01 16:11:15 +00:00
|
|
|
return errors.Wrap(err, "error creating secret local directory")
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if setupErr != nil {
|
|
|
|
if err := os.RemoveAll(localMountPath); err != nil {
|
|
|
|
logrus.Errorf("error cleaning up secret mount: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if c.DependencyStore == nil {
|
|
|
|
return fmt.Errorf("secret store is not initialized")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range c.SecretReferences {
|
|
|
|
// TODO (ehazlett): use type switch when more are supported
|
|
|
|
if s.File == nil {
|
|
|
|
logrus.Error("secret target type is not a file target")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// secrets are created in the SecretMountPath on the host, at a
|
|
|
|
// single level
|
|
|
|
fPath := c.SecretFilePath(*s)
|
|
|
|
logrus.WithFields(logrus.Fields{
|
|
|
|
"name": s.File.Name,
|
|
|
|
"path": fPath,
|
|
|
|
}).Debug("injecting secret")
|
2017-06-15 18:11:48 +00:00
|
|
|
secret, err := c.DependencyStore.Secrets().Get(s.SecretID)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "unable to get secret from secret store")
|
2016-12-01 16:11:15 +00:00
|
|
|
}
|
|
|
|
if err := ioutil.WriteFile(fPath, secret.Spec.Data, s.File.Mode); err != nil {
|
|
|
|
return errors.Wrap(err, "error injecting secret")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-11-12 19:55:17 +00:00
|
|
|
func killProcessDirectly(container *container.Container) error {
|
2015-11-11 21:53:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
2016-03-10 04:33:21 +00:00
|
|
|
|
|
|
|
func isLinkable(child *container.Container) bool {
|
|
|
|
return false
|
|
|
|
}
|
2016-04-20 22:35:11 +00:00
|
|
|
|
|
|
|
func enableIPOnPredefinedNetwork() bool {
|
|
|
|
return true
|
|
|
|
}
|
2016-09-21 19:02:20 +00:00
|
|
|
|
|
|
|
func (daemon *Daemon) isNetworkHotPluggable() bool {
|
|
|
|
return false
|
|
|
|
}
|
2016-10-13 21:51:10 +00:00
|
|
|
|
|
|
|
func setupPathsAndSandboxOptions(container *container.Container, sboxOptions *[]libnetwork.SandboxOption) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-06-12 22:20:23 +00:00
|
|
|
func (daemon *Daemon) initializeNetworkingPaths(container *container.Container, nc *container.Container) error {
|
|
|
|
|
|
|
|
if nc.HostConfig.Isolation.IsHyperV() {
|
|
|
|
return fmt.Errorf("sharing of hyperv containers network is not supported")
|
|
|
|
}
|
|
|
|
|
2017-03-01 04:03:43 +00:00
|
|
|
container.NetworkSharedContainerID = nc.ID
|
2017-06-12 22:20:23 +00:00
|
|
|
|
|
|
|
if nc.NetworkSettings != nil {
|
|
|
|
for n := range nc.NetworkSettings.Networks {
|
|
|
|
sn, err := daemon.FindNetwork(n)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
ep, err := nc.GetEndpointInNetwork(sn)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := ep.DriverInfo()
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if data["GW_INFO"] != nil {
|
|
|
|
gwInfo := data["GW_INFO"].(map[string]interface{})
|
|
|
|
if gwInfo["hnsid"] != nil {
|
|
|
|
container.SharedEndpointList = append(container.SharedEndpointList, gwInfo["hnsid"].(string))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if data["hnsid"] != nil {
|
|
|
|
container.SharedEndpointList = append(container.SharedEndpointList, data["hnsid"].(string))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2016-10-13 21:51:10 +00:00
|
|
|
}
|