-
Notifications
You must be signed in to change notification settings - Fork 203
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
POC: appendable string arrays in containers.conf #1675
POC: appendable string arrays in containers.conf #1675
Conversation
7636620
to
d85d2ac
Compare
Makefile
Outdated
@@ -100,6 +100,7 @@ test: test-unit | |||
test-unit: netavark-testplugin | |||
go test --tags $(BUILDTAGS) -v ./libimage/... | |||
go test --tags $(BUILDTAGS) -v ./libnetwork/... | |||
go test --tags $(BUILDTAGS) -v ./internal/... |
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 it is time to change this to go test --tags $(BUILDTAGS) -v ./...
, people will forget to add the packages when they add top level dirs.
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.
Agreed. I opened #1681 to not forget about it.
kind := reflect.ValueOf(x).Kind() | ||
switch kind { | ||
case reflect.String: // Strings are directly appended to the slice. | ||
loadedStrings = append(loadedStrings, fmt.Sprintf("%v", x)) | ||
case reflect.Map: // The attribute struct is represented as a map. |
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 this is better written as
switch val := x.(type) {
case string:
slice = append(slice, val)
case map[string]interface{}:
...
default:
// no match
}
This avoids the extra type casts you need
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 did not know such a switch table is possible. Thanks for sharing!
4f1f29f
to
8fdb670
Compare
I am all for merging this. |
LGTM |
As discussed in containers/podman#20000, we need an opt-in mechanism to _append_ string arrays during loading sequence of containers.conf files. At the moment, existing fields/data will be overriden with each loaded config that sets the specified field/option. The TOML (toml.io) config format does not allow for attributing fields and structs are implicitly represented as "tables". I wanted to extend a string array with a simple boolean field, for instance: ```TOML env=["FOO=bar"] env.append=true ``` TOML doesn't suppor tthe upper idea as it's not a properly formatted table. So I looked for alternatives and found that TOML supports so-called "mixed-type arrays". As the same suggests, such arrays allow for including more than one type and that seemed like a reasonable candidate as it allows for _extending_ the existing syntax without introducing new fields or even yet-another way of loading conf files. The new format can be seen in the tests. Please note that this is just a _tested_ POC. Integrating the POC in containers.conf may turn into a bigger journey as Podman is directly (ab)using many of the fields. Since they have to be changed to the new type (see POC), Podman will not compile without changes. Signed-off-by: Valentin Rothberg <[email protected]>
8fdb670
to
6506f4f
Compare
Rebased |
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Luap99, vrothberg The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
As discussed in containers/podman#20000, we need an opt-in mechanism to append string arrays during the loading sequence of containers.conf files.
At the moment, existing fields/data will be overriden with each loaded config that sets the specified field/option. The TOML (toml.io) config format does not allow for attributing fields and structs are implicitly represented as "tables". I wanted to extend a string array with a simple boolean field, for instance:
TOML doesn't suppor tthe upper idea as it's not a properly formatted table. So I looked for alternatives and found that TOML supports so-called "mixed-type arrays". As the same suggests, such arrays allow for including more than one type and that seemed like a reasonable candidate as it allows for extending the existing syntax without introducing new fields or even yet-another way of loading conf files.
The new format can be seen in the tests. Please note that this is just a tested POC. Integrating the POC in containers.conf may turn into a bigger journey as Podman is directly (ab)using many of the fields. Since they have to be changed to the new type (see POC), Podman will not compile without changes.