Merge pull request #16228 from duglin/ContextualizeEvents

Add context.RequestID to event stream
This commit is contained in:
David Calavera
2015-09-24 14:16:22 -07:00
68 changed files with 737 additions and 565 deletions
+28 -27
View File
@@ -15,6 +15,7 @@ import (
"time"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/context"
"github.com/docker/docker/daemon/execdriver"
"github.com/docker/docker/daemon/links"
"github.com/docker/docker/daemon/network"
@@ -77,12 +78,12 @@ func killProcessDirectly(container *Container) error {
return nil
}
func (container *Container) setupLinkedContainers() ([]string, error) {
func (container *Container) setupLinkedContainers(ctx context.Context) ([]string, error) {
var (
env []string
daemon = container.daemon
)
children, err := daemon.children(container.Name)
children, err := daemon.children(ctx, container.Name)
if err != nil {
return nil, err
}
@@ -175,7 +176,7 @@ func getDevicesFromPath(deviceMapping runconfig.DeviceMapping) (devs []*configs.
return devs, derr.ErrorCodeDeviceInfo.WithArgs(deviceMapping.PathOnHost, err)
}
func populateCommand(c *Container, env []string) error {
func populateCommand(ctx context.Context, c *Container, env []string) error {
var en *execdriver.Network
if !c.Config.NetworkDisabled {
en = &execdriver.Network{}
@@ -185,7 +186,7 @@ func populateCommand(c *Container, env []string) error {
parts := strings.SplitN(string(c.hostConfig.NetworkMode), ":", 2)
if parts[0] == "container" {
nc, err := c.getNetworkedContainer()
nc, err := c.getNetworkedContainer(ctx)
if err != nil {
return err
}
@@ -206,7 +207,7 @@ func populateCommand(c *Container, env []string) error {
}
if c.hostConfig.IpcMode.IsContainer() {
ic, err := c.getIpcContainer()
ic, err := c.getIpcContainer(ctx)
if err != nil {
return err
}
@@ -349,18 +350,18 @@ func mergeDevices(defaultDevices, userDevices []*configs.Device) []*configs.Devi
}
// GetSize returns the real size & virtual size of the container.
func (container *Container) getSize() (int64, int64) {
func (container *Container) getSize(ctx context.Context) (int64, int64) {
var (
sizeRw, sizeRootfs int64
err error
driver = container.daemon.driver
)
if err := container.Mount(); err != nil {
if err := container.Mount(ctx); err != nil {
logrus.Errorf("Failed to compute size of container rootfs %s: %s", container.ID, err)
return sizeRw, sizeRootfs
}
defer container.Unmount()
defer container.Unmount(ctx)
initID := fmt.Sprintf("%s-init", container.ID)
sizeRw, err = driver.DiffSize(container.ID, initID)
@@ -412,7 +413,7 @@ func (container *Container) buildHostnameFile() error {
return ioutil.WriteFile(container.HostnamePath, []byte(container.Config.Hostname+"\n"), 0644)
}
func (container *Container) buildSandboxOptions() ([]libnetwork.SandboxOption, error) {
func (container *Container) buildSandboxOptions(ctx context.Context) ([]libnetwork.SandboxOption, error) {
var (
sboxOptions []libnetwork.SandboxOption
err error
@@ -489,7 +490,7 @@ func (container *Container) buildSandboxOptions() ([]libnetwork.SandboxOption, e
var childEndpoints, parentEndpoints []string
children, err := container.daemon.children(container.Name)
children, err := container.daemon.children(ctx, container.Name)
if err != nil {
return nil, err
}
@@ -520,7 +521,7 @@ func (container *Container) buildSandboxOptions() ([]libnetwork.SandboxOption, e
continue
}
c, err := container.daemon.Get(ref.ParentID)
c, err := container.daemon.Get(ctx, ref.ParentID)
if err != nil {
logrus.Error(err)
}
@@ -679,7 +680,7 @@ func (container *Container) updateSandboxNetworkSettings(sb libnetwork.Sandbox)
// UpdateNetwork is used to update the container's network (e.g. when linked containers
// get removed/unlinked).
func (container *Container) updateNetwork() error {
func (container *Container) updateNetwork(ctx context.Context) error {
ctrl := container.daemon.netController
sid := container.NetworkSettings.SandboxID
@@ -688,7 +689,7 @@ func (container *Container) updateNetwork() error {
return derr.ErrorCodeNoSandbox.WithArgs(sid, err)
}
options, err := container.buildSandboxOptions()
options, err := container.buildSandboxOptions(ctx)
if err != nil {
return derr.ErrorCodeNetworkUpdate.WithArgs(err)
}
@@ -812,7 +813,7 @@ func createNetwork(controller libnetwork.NetworkController, dnet string, driver
return controller.NewNetwork(driver, dnet, createOptions...)
}
func (container *Container) secondaryNetworkRequired(primaryNetworkType string) bool {
func (container *Container) secondaryNetworkRequired(ctx context.Context, primaryNetworkType string) bool {
switch primaryNetworkType {
case "bridge", "none", "host", "container":
return false
@@ -831,7 +832,7 @@ func (container *Container) secondaryNetworkRequired(primaryNetworkType string)
return false
}
func (container *Container) allocateNetwork() error {
func (container *Container) allocateNetwork(ctx context.Context) error {
mode := container.hostConfig.NetworkMode
controller := container.daemon.netController
if container.Config.NetworkDisabled || mode.IsContainer() {
@@ -865,21 +866,21 @@ func (container *Container) allocateNetwork() error {
service = strings.Replace(service, "/", "", -1)
}
if container.secondaryNetworkRequired(networkDriver) {
if container.secondaryNetworkRequired(ctx, networkDriver) {
// Configure Bridge as secondary network for port binding purposes
if err := container.configureNetwork("bridge", service, "bridge", false); err != nil {
if err := container.configureNetwork(ctx, "bridge", service, "bridge", false); err != nil {
return err
}
}
if err := container.configureNetwork(networkName, service, networkDriver, mode.IsDefault()); err != nil {
if err := container.configureNetwork(ctx, networkName, service, networkDriver, mode.IsDefault()); err != nil {
return err
}
return container.writeHostConfig()
}
func (container *Container) configureNetwork(networkName, service, networkDriver string, canCreateNetwork bool) error {
func (container *Container) configureNetwork(ctx context.Context, networkName, service, networkDriver string, canCreateNetwork bool) error {
controller := container.daemon.netController
n, err := controller.NetworkByName(networkName)
@@ -923,7 +924,7 @@ func (container *Container) configureNetwork(networkName, service, networkDriver
return false
})
if sb == nil {
options, err := container.buildSandboxOptions()
options, err := container.buildSandboxOptions(ctx)
if err != nil {
return err
}
@@ -946,12 +947,12 @@ func (container *Container) configureNetwork(networkName, service, networkDriver
return nil
}
func (container *Container) initializeNetworking() error {
func (container *Container) initializeNetworking(ctx context.Context) error {
var err error
if container.hostConfig.NetworkMode.IsContainer() {
// we need to get the hosts files from the container to join
nc, err := container.getNetworkedContainer()
nc, err := container.getNetworkedContainer(ctx)
if err != nil {
return err
}
@@ -977,7 +978,7 @@ func (container *Container) initializeNetworking() error {
}
if err := container.allocateNetwork(); err != nil {
if err := container.allocateNetwork(ctx); err != nil {
return err
}
@@ -998,9 +999,9 @@ func (container *Container) setNetworkNamespaceKey(pid int) error {
return sandbox.SetKey(path)
}
func (container *Container) getIpcContainer() (*Container, error) {
func (container *Container) getIpcContainer(ctx context.Context) (*Container, error) {
containerID := container.hostConfig.IpcMode.Container()
c, err := container.daemon.Get(containerID)
c, err := container.daemon.Get(ctx, containerID)
if err != nil {
return nil, err
}
@@ -1036,14 +1037,14 @@ func (container *Container) setupWorkingDirectory() error {
return nil
}
func (container *Container) getNetworkedContainer() (*Container, error) {
func (container *Container) getNetworkedContainer(ctx context.Context) (*Container, error) {
parts := strings.SplitN(string(container.hostConfig.NetworkMode), ":", 2)
switch parts[0] {
case "container":
if len(parts) != 2 {
return nil, derr.ErrorCodeParseContainer
}
nc, err := container.daemon.Get(parts[1])
nc, err := container.daemon.Get(ctx, parts[1])
if err != nil {
return nil, err
}