runtime-config: Drop optional 'options' when empty#123
Closed
wking wants to merge 1 commit intoopencontainers:masterfrom
Closed
runtime-config: Drop optional 'options' when empty#123wking wants to merge 1 commit intoopencontainers:masterfrom
wking wants to merge 1 commit intoopencontainers:masterfrom
Conversation
The field is optional, so why bother giving an empty value? Signed-off-by: W. Trevor King <[email protected]>
Contributor
|
eh, I don't see how it maters either way. I am just going to close this. |
Contributor
Author
|
On Sat, Aug 29, 2015 at 09:35:04AM -0700, Brandon Philips wrote:
I think giving explicit empty values for optional parameters is |
wking
added a commit
to wking/opencontainer-runtime-spec
that referenced
this pull request
Sep 27, 2015
So it matches (modulo key order) our examples from the
runtime-config.md series. To get as much matching up as possible,
I've converted externally-visible runtime_config.proto entries from
under_scores to camelCase. We're still not matching some cases well,
and I've interspersed my notes on why in the diff:
$ diff -u <(cat config.json runtime.json) <(./example_cpp | jq .)
--- /dev/fd/63 2015-09-27 00:04:18.464247761 -0700
+++ /dev/fd/62 2015-09-27 00:04:18.463247761 -0700
@@ -34,43 +34,9 @@
}
}
{
- "mounts": {
- "proc": {
- "type": "proc",
- "source": "proc",
- "options": []
- },
- ...
- },
+ "mounts": [
+ {}
+ ],
Protobuf doesn't like objects with arbitrary keys (or at least we
haven't found a way to set that up). So we probably need a
pre-processer to convert mount entries into:
"mounts": [
{
"key": "proc",
"value": {
"type": "proc",
"source": "proc",
"options": []
},
}
]
You can do that with jq [1], and that makes the mount difference much
smaller (sysctl need the same change):
$ mv runtime.json runtime.json-orig
$ jq '.mounts |= to_entries | .linuxx.sysctl |= to_entries' <runtime.json-orig >runtime.json
$ diff -u <(cat config.json runtime.json) <(./example_cpp | jq .)
--- /dev/fd/63 2015-09-27 00:15:56.656282533 -0700
+++ /dev/fd/62 2015-09-27 00:15:56.656282533 -0700
@@ -78,8 +78,7 @@
"key": "proc",
"value": {
"type": "proc",
- "source": "proc",
- "options": []
+ "source": "proc"
}
}
],
...
The difference here is that protobuf isn't serializing default values,
so it drops the empty array [2] (which I'd suggested we do anyway [3] ;)
...
"rlimits": [
{
"type": "RLIMIT_NPROC",
- "soft": 1024,
- "hard": 102400
+ "hard": "102400",
+ "soft": "1024"
}
],
...
Protobuf uses strings when writing 64-bit-wide numbers [2], but it
reads both numbers and strings, so this isn't a big deal.
@@ -198,63 +171,44 @@
"devices": [
{
"path": "/dev/random",
- "type": "c",
- "major": 1,
- "minor": 8,
- "permissions": "rwm",
- "fileMode": 666,
- "uid": 0,
- "gid": 0
+ "major": "1",
+ "minor": "8",
+ "permissions": "rwm",
+ "fileMode": 666
},
...
This has some of the default-dropping and number-string issues
mentioned earlier, as well as the effect of runtime_config.proto's:
// TODO(vbatts) ensure int32 is fine here, instead of golang's rune
optional int32 type = 2;
[1]: https://stedolan.github.io/jq/
[2]: https://developers.google.com/protocol-buffers/docs/proto3#json
[3]: opencontainers#123
Signed-off-by: W. Trevor King <[email protected]>
wking
added a commit
to wking/opencontainer-runtime-spec
that referenced
this pull request
Sep 27, 2015
So it matches (modulo key order) our examples from the
runtime-config.md series. To get as much matching up as possible,
I've converted externally-visible runtime_config.proto entries from
under_scores to camelCase. We're still not matching some cases well,
and I've interspersed my notes on why in the diff:
$ diff -u <(cat config.json runtime.json) <(./example_cpp | jq .)
--- /dev/fd/63 2015-09-27 00:04:18.464247761 -0700
+++ /dev/fd/62 2015-09-27 00:04:18.463247761 -0700
@@ -34,43 +34,9 @@
}
}
{
- "mounts": {
- "proc": {
- "type": "proc",
- "source": "proc",
- "options": []
- },
- ...
- },
+ "mounts": [
+ {}
+ ],
Protobuf doesn't like objects with arbitrary keys (or at least we
haven't found a way to set that up). So we probably need a
pre-processer to convert mount entries into:
"mounts": [
{
"key": "proc",
"value": {
"type": "proc",
"source": "proc",
"options": []
},
}
]
You can do that with jq [1], and that makes the mount difference much
smaller (sysctl need the same change):
$ mv runtime.json runtime.json-orig
$ jq '.mounts |= to_entries | .linuxx.sysctl |= to_entries' <runtime.json-orig >runtime.json
$ diff -u <(cat config.json runtime.json) <(./example_cpp | jq .)
--- /dev/fd/63 2015-09-27 00:15:56.656282533 -0700
+++ /dev/fd/62 2015-09-27 00:15:56.656282533 -0700
@@ -78,8 +78,7 @@
"key": "proc",
"value": {
"type": "proc",
- "source": "proc",
- "options": []
+ "source": "proc"
}
}
],
...
The difference here is that protobuf isn't serializing default values,
so it drops the empty array [2] (which I'd suggested we do anyway [3] ;)
...
"rlimits": [
{
"type": "RLIMIT_NPROC",
- "soft": 1024,
- "hard": 102400
+ "hard": "102400",
+ "soft": "1024"
}
],
...
Protobuf uses strings when writing 64-bit-wide numbers [2], but it
reads both numbers and strings, so this isn't a big deal.
@@ -198,63 +171,44 @@
"devices": [
{
"path": "/dev/random",
- "type": "c",
- "major": 1,
- "minor": 8,
- "permissions": "rwm",
- "fileMode": 666,
- "uid": 0,
- "gid": 0
+ "major": "1",
+ "minor": "8",
+ "permissions": "rwm",
+ "fileMode": 666
},
...
This has some of the default-dropping and number-string issues
mentioned earlier, as well as the effect of runtime_config.proto's:
// TODO(vbatts) ensure int32 is fine here, instead of golang's rune
optional int32 type = 2;
[1]: https://stedolan.github.io/jq/
[2]: https://developers.google.com/protocol-buffers/docs/proto3#json
[3]: opencontainers#123
Signed-off-by: W. Trevor King <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The field is optional, so why bother giving an empty value?
I'd suggested this after looking over #120, but this change is
orthogonal to that PR's string→array change.