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: add container setting check #1537

Merged
merged 1 commit into from
Jun 20, 2018
Merged

feature: add container setting check #1537

merged 1 commit into from
Jun 20, 2018

Conversation

Ace-Tang
Copy link
Contributor

add container config settings check, include container config and
host config in create container, update container.
fix memory_swappiness initial value to zero, since -1 is invalid.

#echo -1 > /sys/fs/cgroup/memory/pouch/4d770c0e1a84320c513d9569511c0d65046eda456723340851356b9eb86c0e01/memory.swappiness 
bash: echo: write error: Invalid argument

Signed-off-by: Ace-Tang aceapril@126.com

Ⅰ. Describe what this PR did

Ⅱ. Does this pull request fix one issue?

Ⅲ. Describe how you did it

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov-io
Copy link

codecov-io commented Jun 15, 2018

Codecov Report

Merging #1537 into master will increase coverage by 0.06%.
The diff coverage is 23.72%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1537      +/-   ##
==========================================
+ Coverage   41.22%   41.29%   +0.06%     
==========================================
  Files         266      266              
  Lines       17313    17313              
==========================================
+ Hits         7138     7149      +11     
+ Misses       9288     9275      -13     
- Partials      887      889       +2
Impacted Files Coverage Δ
daemon/mgr/container_types.go 76.11% <ø> (ø) ⬆️
cli/common_flags.go 0% <0%> (ø) ⬆️
apis/opts/memory_swappiness.go 100% <100%> (ø) ⬆️
daemon/mgr/container_utils.go 55.45% <14.28%> (+2.26%) ⬆️
daemon/mgr/container.go 49.41% <71.42%> (+0.23%) ⬆️
ctrd/image.go 77.71% <0%> (-1.72%) ⬇️
daemon/logger/jsonfile/utils.go 73.17% <0%> (+1.62%) ⬆️
apis/server/container_bridge.go 84.68% <0%> (+1.8%) ⬆️

if r.Memory != 0 && r.Memory < MinMemory {
return warnings, fmt.Errorf("Minimal memory should greater than 4M")
}
if r.Memory == 0 && r.MemorySwap > 0 && !update {
Copy link
Contributor

Choose a reason for hiding this comment

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

If it is the create action, the --memory-swap should also work with memory, right?

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 check only in create, and memory-swap should work with memory

warn := "Current Kernel does not support memory limit, discard --memory"
logrus.Warn(warn)
warnings = append(warnings, warn)
r.Memory = 0
r.MemorySwap = 0
}
if r.MemorySwap != 0 && !cgroupInfo.Memory.MemorySwap {
if r.MemorySwap > 0 && !cgroupInfo.Memory.MemorySwap {
warn := "Current Kernel does not support memory swap, discard --memory-swap"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we put the warn as the const or package var? WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean every warn make a const or warn ? will this too many?

// cpu.cfs_quota_us can accept value less than 0, we allow -1 and > 1000
if r.CPUQuota > 0 && r.CPUQuota < 1000 {
return warnings, fmt.Errorf("CPU cfs quota should be greater than 1ms(1000)")
}
if r.CPUPeriod > 0 && !cgroupInfo.CPU.CPUPeriod {
warn := "Current Kernel does not support cpu period, discard --cpu-period"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we put the warn as the const or package var? WDYT?

if r.CPUPeriod > 0 && !cgroupInfo.CPU.CPUPeriod {
warn := "Current Kernel does not support cpu period, discard --cpu-period"
logrus.Warn(warn)
warnings = append(warnings, warn)
r.CPUPeriod = 0
}
if r.CPUPeriod != 0 && (r.CPUPeriod < 1000 || r.CPUPeriod > 1000000) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the number of if branch are too many, could we put the CPU related into one function? It can make the function readable....

res.Assert(c, icmd.Success)

output := command.PouchRun("inspect", name).Stdout()
result := []types.ContainerJSON{}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need result here. The inspect action should be tested by other suite.

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, it can be removed.

@pouchrobot pouchrobot added size/XL and removed size/L labels Jun 19, 2018
@Ace-Tang
Copy link
Contributor Author

PTAL, @fuweid

@fuweid
Copy link
Contributor

fuweid commented Jun 19, 2018

LGTM. I think next step we should separate validateResource into several pieces to make it testable.

add container config settings check, include container config and
host config in create container, update container.
fix memory_swappiness initial value to zero, since -1 is invalid.

Signed-off-by: Ace-Tang <aceapril@126.com>
@fuweid
Copy link
Contributor

fuweid commented Jun 20, 2018

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants