Skip to content

Commit

Permalink
Merge pull request #2165 from HusterWan/zr/fix-update-diskquota
Browse files Browse the repository at this point in the history
refactor: delete update specific code
  • Loading branch information
allencloud authored Aug 27, 2018
2 parents 27bbb23 + b2e7e10 commit 13d2766
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
6 changes: 5 additions & 1 deletion apis/plugins/ContainerPlugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ 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{})

// 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
}
28 changes: 10 additions & 18 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}()
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 13d2766

Please sign in to comment.