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

Add mems, cpus check and move common codes into utils #344

Closed
wants to merge 2 commits into from

Conversation

Mashimiao
Copy link

No description provided.

utils/utils.go Outdated
)

// CapValid checks whether a capability is valid
func CapValid(c string, hostSpecific bool) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

This (and UnitListValid) are both validators. Why not keep them in the validate package?

@Mashimiao
Copy link
Author

Mashimiao commented Mar 11, 2017 via email

@wking
Copy link
Contributor

wking commented Mar 11, 2017

As they also be used by generate...

I think generate importing validate is fine (although I wouldn't like it if validate imported generate). Moving validation functions into utils as generate needs them seems like it would destabilize the validate API without much gain.

@Mashimiao
Copy link
Author

They were not member functions of Validator, I think this change will not destabilize the validate API.
And they really works as tiny tool function for validations and params check, let them to be public functions in Validation seems also not suitable. From this point, it's a good modification.

@Mashimiao
Copy link
Author

ping @mrunalp @liangchenye

@liangchenye
Copy link
Member

I prefer to change UnitListValid to a regular expression

var match = regexp.MustCompile
var cpuMemReg = match(`^([0-9]+|[0-9]+-[0-9]+)(,([0-9]+|[0-9]+-[0-9]+))*$`)

And we can use it in validation code:
cpuMemReg.MatchString(***)
I tested it, it works.

// 1
// 0-3
// 0-2,1,3
// 0-2,1-3,4
Copy link
Contributor

Choose a reason for hiding this comment

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

These validity checks are not backed by the spec, and since opencontainers/runtime-spec#780 landed I think the spec is unlikely to add them in the future. Do runtime-tools maintainers intend to reach past runtime-spec and enforce limits that have been silently punted to the kernel (runtime-spec doesn't even have “MUST be a valid value for kernel interface [link]”)? If so, we'll need a validation level for “kernel limits not covered by runtime-spec”. If not, I think we can drop UnitListValid.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I don't know the history very well. Why do we remove these limits? These parameters are very related with kernel, if they are not accepted by kernel, that makes no sense, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we remove these limits? These parameters are very related with kernel, if they are not accepted by kernel, that makes no sense, right?

My impression is that runtime-spec maintainers feel that inlining kernel limits isn't particularly useful. The spec itself has no opinion on these limits, and just punts to the kernel (although I think the wording for the punts still needs work, e.g. opencontainers/runtime-spec#746).

But you could write a config with foo-bar as your linux.resources.cpu.cpus value, it would be valid vs. runtime-spec, and if you had a very strange kernel it would actually work for creating a new container. As far as runtime-spec (and our spec-targeting validation here) is concerned, that would be fine. Luckily, the kernel APIs are fairly stable, so config-authors don't have to worry too much about which kernel they're targeting when they figure out these values. And again, if we want to inline these checks with a “kernel limits not covered by runtime-spec” level, I'm fine with that.

@Mashimiao Mashimiao force-pushed the add-utils branch 2 times, most recently from 515efdb to 4708aab Compare July 5, 2017 09:15
@Mashimiao
Copy link
Author

Mashimiao commented Jul 6, 2017 via email

@liangchenye
Copy link
Member

I feel that we need more validation works in 'generate' module.
so it seems better that 'generate' module is using 'validate' module other than sharing a common utils module with 'generate' module.

And another comment is, we are using great project 'syndtr/gocapability', it is already a common 'utils'. Maybe capValid should be upstreamed to it?

Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
@Mashimiao
Copy link
Author

@liangchenye I reconsidered your suggestion. As our CapValid has host-specific check, it's not so good to put it into gocapability Lib. But move it into validate module again is OK.
updated, PTAL

Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
if r.CPU != nil {
if r.CPU.Cpus != "" {
if err := utils.UnitListValid(r.CPU.Cpus); err != nil {
msgs = append(msgs, err.Error())
Copy link
Contributor

@wking wking Sep 28, 2017

Choose a reason for hiding this comment

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

I'm not sure this check (or your following mems check) is grounded in the spec, but if the runtime-tools maintainer consensus is that it is (or if they just want “unlikely to be supported by the kernel” warnings), then the validate/ changes from this PR belong in v0.3.0. I've also made a similar suggestion for #386 here, in case runtime-tools maintainers want to handle both instances the same way.

@Mashimiao
Copy link
Author

I think this PR is not so valuable as I considered, so I decide to close it.
Will open it depends on our future needs.

@Mashimiao Mashimiao closed this Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants