-
Notifications
You must be signed in to change notification settings - Fork 159
[NO MERGE] generate: Adjust command-line generator to use .Config directly #267
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
Conversation
This makes the attribute public, since quite a few config manipulations are easier using Go's types than they are via getter/setter/mutator methods. This also means that we can drop methods that are more awkward than direct access (although we'll want to keep methods that are more convenient than direct access). I haven't done any method-dropping in this commit though, aside from the getter/setter for the config itself. I'd called for this back when we started adding these methods [1], and Mrunal was sounding more positive about the public-attribute approach a few weeks ago [2]. I've also renamed this from "spec" to "config", because it is a config. I'm not sure why runtime-spec decided to call the main config.go type 'Spec' [3], but I don't think we should repeat that idiosyncrasy. [1]: opencontainers#137 (comment) [2]: opencontainers#253 (comment) [3]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc2/specs-go/config.go#L6 Signed-off-by: W. Trevor King <[email protected]>
In most cases it's easier for the user to mutate Generator.Config directly, and exposing the pointer-property initializers lets them do that easily. Signed-off-by: W. Trevor King <[email protected]>
This saves a few lines of code and removes a layer of indirection.
It's now obvious to the caller exactly what is changing, although
there is sometimes less per-setting validation. That's ok though;
folks interested in validating the config can call the validator on it
after they've finished mucking about.
This new approach also initializes any needer pointer fields at the
top. With the current runtime-spec types, that can lead to some
orphaned pointer fields, e.g.;
$ ./oci-runtime-tool generate --template <(echo '{}')
{
"ociVersion": "1.0.0-rc1-dev",
"platform": {
"os": "linux",
"arch": "amd64"
},
"process": {
"user": {
"uid": 0,
"gid": 0
},
"args": null,
"cwd": "/"
},
"root": {
"path": "rootfs"
},
"hooks": {},
"linux": {
"resources": {
"devices": null
}
}
}
but the devices issue was fixed in runtime-spec 1.0.0-rc2 [1] and
there are other approaches to collapsing unused pointer properties
[2].
[1]: opencontainers/runtime-spec#526
[2]: opencontainers#112
Signed-off-by: W. Trevor King <[email protected]>
|
From the code, part of them uses Config directly, part of them still use set/add function(which needs loop logic or value checks). |
|
On Mon, Nov 07, 2016 at 11:21:25PM -0800, Ma Shimiao wrote:
I agree, and I've kept those methods here. Having a public Config
Value checks are nice, but some validation involves comparing multiple
Besides less maintainer time on existing wrappers, it also lifts the |
|
On 11/08/2016 03:32 PM, W. Trevor King wrote:
I am also considering about call 'oci-runtime-tool validate'. |
|
On Mon, Nov 07, 2016 at 11:47:08PM -0800, Ma Shimiao wrote:
I think there could be a few useful levels here:
The only validation I noticed myself removing in this PR was the func (v *Validator) CheckLinuxRootfsPropagation() (msgs []string) I don't think the lack of a real Validator.bundlePath would be a It would be nice to provide a way to conveniently check all such $ oci-runtime-tools generate --validate … and: $ oci-runtime-tools generate --no-validate … it seems like it would be easier to just suggest folks call: $ oci-runtime-tools generate … && oci-runtime-tools validate … if they felt like they were ready for validation. But I'm fine with |
|
NACK. I could not disagree more with this proposal. The whole benefit of By removing all of the "useless" |
|
On Wed, Nov 09, 2016 at 06:41:05AM -0800, Aleksa Sarai wrote:
I have no problem with the runtime-tools maintainers continuing to More broadly, I see a few points to the current generate package: a. It makes it easy to generate a default spec 1. My personal position is that the spec will be stable enough that (d) Keeping the config private, on the other hand, means that users who config := gen.Spec() I don't see a point in keeping that hoop in place. |
|
Can someone close this PR. |
This series has two (new) commits on top of #266. The first removes a lot of trivial generator methods and exposes the pointer-init methods. The second transitions the command-line generator to use
.Configdirectly. I don't actually care if we remove the trivial generator methods or not (I think the API is cleaner without them, but if maintainers like them enough to want to maintain them, I don't have a problem with that).The point of this PR is that the second commit allows maintainers to assess the effect of a public-
Configapproach. @Mashimiao had expressed concerns in #266 (where I'm floating the public-Configchange), and I thought looking at the second commit here would help show that:I didn't see anywhere where the direct access was less convenient, but that's because I kept the wrapping methods that held non-trivial logic. And I am certainly in favor of continuing to provide those wrappers where we find the wrapper more convenient than direct access.