Skip to content

validate: Code optimization - #486

Closed
zhouhao3 wants to merge 1 commit into
opencontainers:masterfrom
zhouhao3:namespec-fix
Closed

validate: Code optimization#486
zhouhao3 wants to merge 1 commit into
opencontainers:masterfrom
zhouhao3:namespec-fix

Conversation

@zhouhao3

Copy link
Copy Markdown

Make the error message more specific.

Signed-off-by: zhouhao zhouhao@cn.fujitsu.com

Comment threadvalidate/validate.go Outdated

if ns.Path != "" && !filepath.IsAbs(ns.Path) {
return false
return fmt.Errorf("%v is not an absolute path", ns.Path)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

maybe fmt.Errorf(path %v of namespace %v is not absolute, ns.Type, ns.Path) better?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fine.

Comment threadvalidate/validate.go Outdated
case rspec.CgroupNamespace:
default:
return false
return fmt.Errorf("invalid namespace type %s", ns.Type)

@wkingwkingSep 28, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The spec actually has no RFC 2119 wording for this check, saying only “The following namespace types are supported”. It doesn't say that runtimes MUST support them, or that they MUST NOT support additional values, or even that configurations SHOULD use values from that list. I'd guess the spec-maintainer intention was closer to:

Configurations SHOULD use, and runtimes SHOULD support, the following values:

Compliance testing would be easier with “runtimes MUST support”, but see opencontainers/runtime-spec#813.

Anyhow, from the config-validation side, I'd be happier seeing this supported by an effective-SHOULD, similar to what I've proposed in #481.

Comment threadvalidate/validate.go Outdated

if ns.Path != "" && !filepath.IsAbs(ns.Path) {
return false
return fmt.Errorf("path %v of namespace %v is not absolute path", ns.Path, ns)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the 1.0 spec is clearer on this point, but I've filed opencontainers/runtime-spec#925 to attach a MUST to this condition. I'm fine treating the requirement as an implicit-MUST in the meantime.

@wking

Copy link
Copy Markdown
Contributor

This PR belongs in v0.3.0. It's not using specerror.NewError yet, but returning an error from namespaceValid is necessary groundwork for future NewError use.

@zhouhao3
zhouhao3force-pushed the namespec-fix branch 2 times, most recently from 2711261 to 674d195CompareOctober 18, 2017 06:45
@zhouhao3

Copy link
Copy Markdown
Author

updated, @Mashimiao@liangchenye@wking PTAL

Comment threadspecerror/config-linux.go Outdated

func init() {
register(DefaultFilesystems, rfc2119.Should, defaultFilesystemsRef)
register(NamespacesType, rfc2119.Should, namespacesRef)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The spec says: "The following namespace types are supported", We don't have key words like 'SHOULD'. Maybe we can add a PR to spec project?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Maybe we can add a PR to spec project?

Approve.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Comment threadspecerror/config-linux.go Outdated
// DefaultFilesystems represents "The following filesystems SHOULD be made available in each container's filesystem:"
DefaultFilesystems = "The following filesystems SHOULD be made available in each container's filesystem:"
NamespacesType = "The following namespace types are supported:"
NamespacesPath = "This value MUST be an absolute path."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I prefer to extend it to "This value MUST be an absolute path in the runtime mount namespace. "
There are several 'an absolute path' RFCs, https://github.com/opencontainers/runtime-tools/blob/master/specerror/config.go#L32, https://github.com/opencontainers/runtime-tools/blob/master/specerror/config.go#L42.
It will be easier to differentiate them.

Comment threadspecerror/config-linux.go Outdated
// DefaultFilesystems represents "The following filesystems SHOULD be made available in each container's filesystem:"
DefaultFilesystems = "The following filesystems SHOULD be made available in each container's filesystem:"
NamespacesType = "The following namespace types are supported:"
NamespacesPath = "This value MUST be an absolute path."

@liangchenyeliangchenyeOct 18, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rename to NamespacePathAbs?

The naming is a problem, maybe we can add a document to specerror directory to tell our naming rule.

@liangchenye

Copy link
Copy Markdown
Member

rebase required

Signed-off-by: zhouhao <zhouhao@cn.fujitsu.com>
@zhouhao3

Copy link
Copy Markdown
Author

rebased.

@zhouhao3

Copy link
Copy Markdown
Author

Closed because the code has been deleted.

@zhouhao3
zhouhao3 deleted the namespec-fix branch December 13, 2017 06:55
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@zhouhao3@wking@liangchenye@Mashimiao