-
Notifications
You must be signed in to change notification settings - Fork 950
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: mv cli params parse and validate part of code into opts package #1041
refactor: mv cli params parse and validate part of code into opts package #1041
Conversation
7d4877d
to
4054dc3
Compare
Codecov Report
@@ 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
|
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
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := opts.VerifyRestartPolicy(restartPolicy); err != nil { |
There was a problem hiding this comment.
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 != nil { | ||
return nil, err | ||
} | ||
|
||
if err := validateOOMScore(c.oomScoreAdj); err != nil { | ||
if err := opts.VerifyDiskQuota(diskQuota); err != nil { |
There was a problem hiding this comment.
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
|
||
return quotaMaps, nil | ||
} | ||
|
||
// validateOOMScore validates oom score | ||
func validateOOMScore(score int64) error { |
There was a problem hiding this comment.
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.
daemon/mgr/spec_devices.go
Outdated
@@ -109,7 +109,7 @@ func setupDevices(ctx context.Context, meta *ContainerMeta, spec *SpecWrapper) e | |||
} | |||
} else { | |||
for _, deviceMapping := range meta.HostConfig.Devices { | |||
if !runconfig.ValidDeviceMode(deviceMapping.CgroupPermissions) { | |||
if !opts.ValidDeviceMode(deviceMapping.CgroupPermissions) { |
There was a problem hiding this comment.
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.
pkg/opts/devicemappings.go
Outdated
return results, nil | ||
|
||
} | ||
|
||
// ParseDevice parses a device mapping string to a container.DeviceMapping struct | ||
func ParseDevice(device string) (*types.DeviceMapping, error) { |
There was a problem hiding this comment.
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
.
pkg/opts/diskquota.go
Outdated
} | ||
|
||
// VerifyDiskQuota verifies diskquota configurations of container. | ||
func VerifyDiskQuota(quotaMaps map[string]string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Verify/Validate
pkg/opts/networks.go
Outdated
} | ||
|
||
// VerifyNetworks verifies network configurations of container. | ||
func VerifyNetworks(nwConfig *types.NetworkingConfig) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Verify/Validate
pkg/opts/portbindings.go
Outdated
} | ||
|
||
// VerifyPortBinding verify PortMap struct correctness. | ||
func VerifyPortBinding(portBindings types.PortMap) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Verify/Validate
pkg/opts/portbindings.go
Outdated
for port := range portBindings { | ||
_, portStr := nat.SplitProtoPort(string(port)) | ||
if _, err := nat.ParsePort(portStr); err != nil { | ||
return fmt.Errorf("invalid port specification: %q", portStr) |
There was a problem hiding this comment.
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)
pkg/opts/ports.go
Outdated
} | ||
|
||
// VerifyExposedPorts verify the correction of exposed ports. | ||
func VerifyExposedPorts(ports map[string]interface{}) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Verify/Validate
4054dc3
to
4caed31
Compare
4caed31
to
639194b
Compare
639194b
to
9e15503
Compare
…nd daemon can both use Signed-off-by: Michael Wan <zirenwan@gmail.com>
9e15503
to
6257735
Compare
LGTM |
Signed-off-by: Michael Wan zirenwan@gmail.com
Ⅰ. 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