Skip to content

Conversation

@HusterWan
Copy link
Contributor

Signed-off-by: Michael Wan [email protected]

Ⅰ. Describe what this PR did

Now pouch daemon still have not params validation, but we need a policy to verify api request params

i refactor cli params validation part to opts package, so that we can put all params parse and verify code to it.

Ⅱ. 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 Apr 3, 2018

Codecov Report

Merging #1041 into master will increase coverage by 0.28%.
The diff coverage is 49.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1041      +/-   ##
==========================================
+ Coverage   16.03%   16.32%   +0.28%     
==========================================
  Files         142      155      +13     
  Lines        8685     8770      +85     
==========================================
+ Hits         1393     1432      +39     
- Misses       7190     7234      +44     
- Partials      102      104       +2
Impacted Files Coverage Δ
cli/update.go 0% <0%> (ø) ⬆️
pkg/opts/oom_score.go 0% <0%> (ø)
pkg/opts/ports.go 0% <0%> (ø)
daemon/mgr/container_validation.go 0% <0%> (ø)
cli/container.go 0% <0%> (-35.17%) ⬇️
pkg/opts/intel_rdt.go 0% <0%> (ø)
pkg/opts/portbindings.go 0% <0%> (ø)
daemon/mgr/spec_devices.go 0% <0%> (ø) ⬆️
pkg/opts/memory_swappiness.go 100% <100%> (ø)
pkg/opts/sysctl.go 100% <100%> (ø)
... and 26 more

@allencloud
Copy link
Collaborator

This is a big work. I cannot think of any reason to be against this. While this may bring some influences, we need to pick things carefully. Also related to #1051 for your info. @HusterWan

cli/container.go Outdated
return nil, err
}

if err := opts.VerifyRestartPolicy(restartPolicy); 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.

s/Verify/Validate?

cli/container.go Outdated
}

if err := validateOOMScore(c.oomScoreAdj); err != nil {
if err := opts.VerifyDiskQuota(diskQuota); 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.

s/Verify/Validate

cli/container.go Outdated
}

// validateOOMScore validates oom score
func validateOOMScore(score int64) error {
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 function to opts as well.

} else {
for _, deviceMapping := range meta.HostConfig.Devices {
if !runconfig.ValidDeviceMode(deviceMapping.CgroupPermissions) {
if !opts.ValidDeviceMode(deviceMapping.CgroupPermissions) {
Copy link
Collaborator

@allencloud allencloud Apr 4, 2018

Choose a reason for hiding this comment

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

Actually I do not think validate options in spec is a good choice. Maybe we need to move this part a little bit upper.
Not to block the process of this pull request. Just comment to record it.

}

// ParseDevice parses a device mapping string to a container.DeviceMapping struct
func ParseDevice(device string) (*types.DeviceMapping, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this a function which is only used in package opts, I suggest that we make it private with parseDevice.

}

// VerifyDiskQuota verifies diskquota configurations of container.
func VerifyDiskQuota(quotaMaps map[string]string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/Verify/Validate

}

// VerifyNetworks verifies network configurations of container.
func VerifyNetworks(nwConfig *types.NetworkingConfig) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/Verify/Validate

}

// VerifyPortBinding verify PortMap struct correctness.
func VerifyPortBinding(portBindings types.PortMap) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/Verify/Validate

for port := range portBindings {
_, portStr := nat.SplitProtoPort(string(port))
if _, err := nat.ParsePort(portStr); err != nil {
return fmt.Errorf("invalid port specification: %q", portStr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

fmt.Errorf("invalid port specification %q: %s", portStr, %v)

}

// VerifyExposedPorts verify the correction of exposed ports.
func VerifyExposedPorts(ports map[string]interface{}) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/Verify/Validate

@HusterWan HusterWan changed the title refactor: mv params parse and valid part to opts packagge refactor: mv cli params parse and validate part of code into opts package Apr 4, 2018
@allencloud
Copy link
Collaborator

LGTM

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Apr 8, 2018
@allencloud allencloud merged commit 01a90a6 into AliyunContainerService:master Apr 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor LGTM one maintainer or community participant agrees to merge the pull reuqest. size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants