-
Notifications
You must be signed in to change notification settings - Fork 144
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
validate: Code optimization #486
Conversation
validate/validate.go
Outdated
} | ||
|
||
if ns.Path != "" && !filepath.IsAbs(ns.Path) { | ||
return false | ||
return fmt.Errorf("%v is not an absolute path", ns.Path) |
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.
maybe fmt.Errorf(path %v of namespace %v is not absolute, ns.Type, ns.Path) better?
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.
Fine.
17ea264
to
7d231cd
Compare
validate/validate.go
Outdated
@@ -903,14 +903,14 @@ func namespaceValid(ns rspec.LinuxNamespace) bool { | |||
case rspec.UserNamespace: | |||
case rspec.CgroupNamespace: | |||
default: | |||
return false | |||
return fmt.Errorf("invalid namespace type %s", ns.Type) |
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.
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.
validate/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) |
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.
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.
This PR belongs in v0.3.0. It's not using |
2711261
to
674d195
Compare
updated, @Mashimiao @liangchenye @wking PTAL |
specerror/config-linux.go
Outdated
) | ||
|
||
func init() { | ||
register(DefaultFilesystems, rfc2119.Should, defaultFilesystemsRef) | ||
register(NamespacesType, rfc2119.Should, namespacesRef) |
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.
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?
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.
Maybe we can add a PR to spec project?
Approve.
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.
I open opencontainers/runtime-spec#931.
specerror/config-linux.go
Outdated
@@ -10,14 +10,21 @@ import ( | |||
const ( | |||
// 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." |
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.
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.
specerror/config-linux.go
Outdated
@@ -10,14 +10,21 @@ import ( | |||
const ( | |||
// 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." |
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.
rename to NamespacePathAbs?
The naming is a problem, maybe we can add a document to specerror directory to tell our naming rule.
674d195
to
49767e8
Compare
49767e8
to
bc68a99
Compare
0fc41b9
to
57601a4
Compare
rebase required |
Signed-off-by: zhouhao <zhouhao@cn.fujitsu.com>
57601a4
to
a6345a3
Compare
rebased. |
Closed because the code has been deleted. |
Make the error message more specific.
Signed-off-by: zhouhao zhouhao@cn.fujitsu.com