diff --git a/apis/plugins/ContainerPlugin.go b/apis/plugins/ContainerPlugin.go index 3fec45e61..722825fb6 100644 --- a/apis/plugins/ContainerPlugin.go +++ b/apis/plugins/ContainerPlugin.go @@ -12,7 +12,7 @@ type ContainerPlugin interface { // used to sort the pre start array that pass to runc, network plugin hook always has priority value 0. PreStart(interface{}) ([]int, [][]string, error) - //NetworkGenericParams accepts the container id and env of this container and returns the priority of this endpoint + // PreCreateEndpoint accepts the container id and env of this container and returns the priority of this endpoint // and if this endpoint should enable resolver and a map which will be used as generic params to create endpoints of // this container PreCreateEndpoint(string, []string) (priority int, disableResolver bool, genericParam map[string]interface{}) @@ -20,4 +20,8 @@ type ContainerPlugin interface { // PreUpdate defines plugin point where receives a container update request, in this plugin point user // could change the container update body passed-in by http request body PreUpdate(io.ReadCloser) (io.ReadCloser, error) + + // PostUpdate called after update method successful, + // the method accepts the rootfs path and envs of container + PostUpdate(string, []string) error } diff --git a/daemon/mgr/container.go b/daemon/mgr/container.go index 7b731678a..1123fea54 100644 --- a/daemon/mgr/container.go +++ b/daemon/mgr/container.go @@ -930,13 +930,13 @@ func (mgr *ContainerManager) Update(ctx context.Context, name string, config *ty } restore := false - configBack := *c.Config - hostconfigBack := *c.HostConfig + oldConfig := *c.Config + oldHostconfig := *c.HostConfig defer func() { if restore { c.Lock() - c.Config = &configBack - c.HostConfig = &hostconfigBack + c.Config = &oldConfig + c.HostConfig = &oldHostconfig c.Unlock() } }() @@ -974,20 +974,6 @@ func (mgr *ContainerManager) Update(ctx context.Context, name string, config *ty } } } - - // TODO(ziren): we should use meta.Config.DiskQuota to record container diskquota - // compatibility with alidocker, when set DiskQuota for container - // add a DiskQuota label - if config.DiskQuota != nil { - if _, ok := c.Config.Labels["DiskQuota"]; ok { - labels := []string{} - for dir, quota := range c.Config.DiskQuota { - labels = append(labels, fmt.Sprintf("%s=%s", dir, quota)) - } - c.Config.Labels["DiskQuota"] = strings.Join(labels, ";") - } - } - c.Unlock() // update Resources of a container. @@ -1020,6 +1006,12 @@ func (mgr *ContainerManager) Update(ctx context.Context, name string, config *ty } c.Config.Env = newEnvSlice + if mgr.containerPlugin != nil { + if err = mgr.containerPlugin.PostUpdate(c.BaseFS, c.Config.Env); err != nil { + return err + } + } + // If container is not running, update container metadata struct is enough, // resources will be updated when the container is started again, // If container is running, we need to update configs to the real world.