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

feature: UpdateContainerResources of CRI Manager #1511

Merged
merged 1 commit into from
Jun 14, 2018

Conversation

starnop
Copy link
Contributor

@starnop starnop commented Jun 12, 2018

Signed-off-by: Starnop [email protected]

Ⅰ. Describe what this PR did

add feature: UpdateContainerResources of CRI Manager

Ⅱ. Does this pull request fix one issue?

None

Ⅲ. Describe how you did it

Ⅳ. Describe how to verify it

# pouch run -d -m 20m --name cri-update-test registry.hub.docker.com/library/nginx:latest
WARNING: Current Kernel does not support memory swap, discard --memory-swap 
bd6c5b9de4874f6703961ed543a9056a9762279433c6cad0fd8b63f42f636ff5

# cat /sys/fs/cgroup/memory/default/bd6c5b9de4874f6703961ed543a9056a9762279433c6cad0fd8b63f42f636ff5/memory.limit_in_bytes 
20971520

# crictl update --memory 31457280 bd6c5b9de4874f6703961ed543a9056a9762279433c6cad0fd8b63f42f636ff5
DEBU[0000] UpdateContainerResourcesRequest: &UpdateContainerResourcesRequest{ContainerId:bd6c5b9de4874f6703961ed543a9056a9762279433c6cad0fd8b63f42f636ff5,Linux:&LinuxContainerResources{CpuPeriod:0,CpuQuota:0,CpuShares:0,MemoryLimitInBytes:31457280,OomScoreAdj:0,CpusetCpus:,CpusetMems:,},} 
DEBU[0000] UpdateContainerResourcesResponse: &UpdateContainerResourcesResponse{} 
bd6c5b9de4874f6703961ed543a9056a9762279433c6cad0fd8b63f42f636ff5

# cat /sys/fs/cgroup/memory/default/bd6c5b9de4874f6703961ed543a9056a9762279433c6cad0fd8b63f42f636ff5/memory.limit_in_bytes 
31457280

Ⅴ. Special notes for reviews

@codecov-io
Copy link

codecov-io commented Jun 12, 2018

Codecov Report

Merging #1511 into master will increase coverage by 23.79%.
The diff coverage is 2.22%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1511       +/-   ##
===========================================
+ Coverage   16.88%   40.68%   +23.79%     
===========================================
  Files         211      254       +43     
  Lines       14020    16647     +2627     
===========================================
+ Hits         2367     6772     +4405     
+ Misses      11490     9006     -2484     
- Partials      163      869      +706
Impacted Files Coverage Δ
daemon/mgr/container_state.go 82.08% <0%> (+82.08%) ⬆️
cri/v1alpha2/cri.go 0% <0%> (ø) ⬆️
cri/v1alpha1/cri.go 0% <0%> (ø) ⬆️
daemon/mgr/container.go 48.8% <100%> (+48.8%) ⬆️
storage/volume/driver/proxy.go 53.42% <0%> (ø)
storage/quota/grpquota.go 0% <0%> (ø)
main.go 62.5% <0%> (ø)
storage/volume/driver/remote.go 68.96% <0%> (ø)
pkg/debug/debug.go 22.22% <0%> (ø)
pkg/serializer/serialize.go 9.52% <0%> (ø)
... and 117 more

containerID := r.GetContainerId()
container, err := c.ContainerMgr.Get(ctx, containerID)
if err != nil {
return nil, fmt.Errorf("failed to get container of %q: %v", containerID, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We do not need the work of. 😄


// Do not update the container when there is a removal in progress.
if container.State.Status == apitypes.StatusRemoving {
return nil, fmt.Errorf("container %q is in removing state", containerID)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This error is not so readable. How about cannot update container resource when it is in removing state?

Resources: resources,
}
c.ContainerMgr.Update(ctx, containerID, updateConfig)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Which err this line code is using? From resources, err := resourceToCriResource(r.GetLinux()) or c.ContainerMgr.Update(ctx, containerID, updateConfig)?

If it is the latter one, please add more to be err = c.ContainerMgr.Update(ctx, containerID, updateConfig), and in the next line of fmt.Errorf() to construct this with the specific error. Thanks a lot.

@@ -770,3 +770,29 @@ func parseUserFromImageUser(id string) string {
// no group, just return the id
return id
}

// resourceToCriResource converts OCILinuxResource to apitypes.Resources Object.
func resourceToCriResource(new *runtime.LinuxContainerResources) (apitypes.Resources, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is the input parameter's naming is new? Quite strange, how about changing another new name, like resource or something like that.

@starnop starnop force-pushed the cri-update branch 4 times, most recently from 77cbd41 to cd3450e Compare June 12, 2018 09:09
@@ -770,3 +770,27 @@ func parseUserFromImageUser(id string) string {
// no group, just return the id
return id
}

// resourceToCriResource converts OCILinuxResource to apitypes.Resources Object.
func resourceToCriResource(newresource *runtime.LinuxContainerResources) apitypes.Resources {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use the Camel-Case naming. s/newresource/newResource/g.

@pouchrobot pouchrobot added size/L and removed size/M labels Jun 12, 2018
@starnop starnop changed the title [WIP] feature: UpdateContainerResources of CRI Manager feature: UpdateContainerResources of CRI Manager Jun 12, 2018
@starnop
Copy link
Contributor Author

starnop commented Jun 12, 2018

@allencloud Thank you for your patient guidance. Everything mentioned above has been resolved.

@@ -686,7 +686,27 @@ func (c *CriManager) ListContainerStats(ctx context.Context, r *runtime.ListCont

// UpdateContainerResources updates ContainerConfig of the container.
func (c *CriManager) UpdateContainerResources(ctx context.Context, r *runtime.UpdateContainerResourcesRequest) (*runtime.UpdateContainerResourcesResponse, error) {
return nil, fmt.Errorf("UpdateContainerResources Not Implemented Yet")
containerID := r.GetContainerId()
container, err := c.ContainerMgr.Get(ctx, containerID)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am wondering if we need to add lock here for container.

}

// cannot update container resource when it is in removing state
if container.State.Status == apitypes.StatusRemoving {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please check here if we have already support StatusRemoving in container manager. @HusterWan

}
err = c.ContainerMgr.Update(ctx, containerID, updateConfig)
if err != nil {
return nil, fmt.Errorf("failed to update resource for container %q with error: %v", containerID, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

please remove with error

defer container.Unlock()

// cannot update container resource when it is in removing state
if container.State.Status == apitypes.StatusRemoving {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please move this part into container_state.go

@starnop starnop force-pushed the cri-update branch 3 times, most recently from a807c6e to 390d95e Compare June 13, 2018 08:24
@pouchrobot pouchrobot added size/M and removed size/L labels Jun 13, 2018
@allencloud
Copy link
Collaborator

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature LGTM one maintainer or community participant agrees to merge the pull reuqest. size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants