Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: delete update specific code #2165

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a rule to record the error log in the caller's code or the implementation part? @HusterWan

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we will record the error log in the end of api.

}
}

// 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