many: HMS-10300 prepare splitting of imagetypes.yaml#2257
many: HMS-10300 prepare splitting of imagetypes.yaml#2257avitova wants to merge 5 commits intoosbuild:mainfrom
Conversation
supakeen
left a comment
There was a problem hiding this comment.
Thank you this is already shaping up to be quite nice. I've put some comments in the files. Let me know what you think, some of them are pretty straightforward left-overs and some of them are maybe up for discussion (e.g. the double-loop).
I'd really prefer to drop the idea of any image config key existing within a file containing image types so if we can I think we should.
I'll check out your branch when I find some time to play around with how I'd do that/figure out the approach that makes sense to me 🙂.
|
There's |
There was a problem hiding this comment.
Starting to look great functionally; can you please drop the commits that actually do the YAML splitting from this PR? We'll open a new PR based on this one after you do so where we can work on the splitting part separately.
Note: this also means that your last commit that introduces the common file should drop all the changes that are being done to the YAML.
The YAML changes causes a lot of conflicts with any other PRs while the code changes do not, and it'll also put the code commits in logical ordering 🙂
data/distrodefs/fedora/_common.yaml
Outdated
| @@ -0,0 +1,1243 @@ | |||
| --- | |||
| .common: | |||
There was a problem hiding this comment.
Perhaps we should just allow arbitrary top-level keys in the decoding, or introduce a second common section in the ImageTypesYAML so we can have two areas for people to define shared things. Let's start with a .global in imagetypes.yaml and rename the _common.yaml to _global.yaml.
Some things are shared 'globally' across all imagetype yaml's but some here clearly belong inside the variant YAMLs (such as the server package sets; they'd live inside server.yaml, etc).
a093674 to
bd48457
Compare
|
Great, I dropped everything that seems to create conflicts. |
|
This PR is ready for review, I'll be creating a PR based on this one to show what split imagetypes would actually look like in practice. We decided to do that separately since it will almost continuously conflict with anything. Some questions we can ask ourselves:
|
achilleas-k
left a comment
There was a problem hiding this comment.
The PR title suggests this will in fact split the Fedora image types. I understand we want to do this separately. But it'd be nice to see if this change is functional. Maybe we don't need to split everything all at once, but one image type can be moved to a separate file to see that this actually works.
Regardless, the PR title should be updated.
As for the test failures in GitLab, it seems everything's running correctly but the execution fails during cleanup (or during cache updates)? Not our own cache though, the gitlab one. Is this related to the recent changes in the terraform executor?
There's #2266 that actually implements the split so you can see what it looks like; we wanted to keep it out of this PR because it constantly conflicts (as you can see; that PR conflicts right now as well and it's only half a day old :>).
I've rebased on |
c03def3 to
1d486d6
Compare
thozza
left a comment
There was a problem hiding this comment.
Nice work!
I had a big comment in the first commit, that the distro-level ImageConfig should be moved out from image types YAML to the distro YAML with this split, only to find out that you did it in the next commit. So KUDOS for that 👏
On a general note, I've added a few nitpicks that I'd like to see addressed or at least discussed.
Also WRT commit messages, we tend to use imperative speech in general.
pkg/distro/defs/loader.go
Outdated
| if d.DistroImageConfig != nil { | ||
| return d.DistroImageConfig.For(d.ID) | ||
| } | ||
| return &distro.ImageConfig{} |
There was a problem hiding this comment.
Nitpick: the function would previously return nil, not a pointer to an empty struct.,
There was a problem hiding this comment.
oh, good catch, ty
fixed
pkg/distro/defs/loader.go
Outdated
| count := 0 | ||
| for _, cfg := range configs { | ||
| count += len(cfg.ImageTypes) | ||
| } | ||
|
|
||
| if count > 0 { | ||
| d.imageTypes = make(map[string]ImageTypeYAML, count) |
There was a problem hiding this comment.
Nitpick: this is unrelated to the commit it appears in, but it also changes the behavior. Previously, the d.imageTypes would be initialized only when it was nil, now it will be overwritten by a new value regardless of its original value if count > 0.
Moreover, you could simply return if count == 0.
Lastly, I'm not convinced that counting the image types from configs in a separate loop, just to allocate the map precisely is worth it. It adds complexity for marginal benefit and Go will keep some buffer and it is quite efficient when growing the map. It is unlikely that we will have thousands of image types defined in a distribution, so not specifying the size of the map should be acceptable.
There was a problem hiding this comment.
Well, this helps us not allocate a pointer to an empty map into imageTypes which is what happened with the previous version.
We can also do
d.imageTypes = make(map[string]ImageTypeYAML) as we previously did, and then if it is empty by the end of the function, we can set it back to nil - maybe even in a defer, but I don't like that either.
There was a problem hiding this comment.
I think it would be a lot cleaner and avoid pre-counting if we loaded everything into a separate map and skipped assigning it in the end if it's empty (to preserve nil).
imageTypes := make(map[string]ImageTypeYAML)
for _, cfg := range configs {
for name, v := cfg.ImageTypes {
... load etc ...
}
}
if len(imageTypes) > 0 {
d.imageTypes = imageTypes
}We're going to run through configs and image types anyway, no need to do it twice. The total count (len(imageTypes)) is right there in the end.
| imageTypes map[string]ImageTypeYAML | ||
| // distro wide default image config | ||
| imageConfig *distro.ImageConfig `yaml:"default"` | ||
| DistroImageConfig *distroImageConfig `yaml:"image_config,omitempty"` |
There was a problem hiding this comment.
Why the name change? This is a property of DistroYAML, so I think it's clear that it's an ImageConfig for the distro already.
There was a problem hiding this comment.
We need to have the field public, but there is already a method called ImageCongig, so there is a collision. 🥲
There was a problem hiding this comment.
I don't see any public use of the field, but maybe that's part of the follow-up?
There was a problem hiding this comment.
The reason is that private fields aren't deserialized (and the rest is the name clash).
pkg/distro/defs/loader.go
Outdated
| count := 0 | ||
| for _, cfg := range configs { | ||
| count += len(cfg.ImageTypes) | ||
| } | ||
|
|
||
| if count > 0 { | ||
| d.imageTypes = make(map[string]ImageTypeYAML, count) |
There was a problem hiding this comment.
I think it would be a lot cleaner and avoid pre-counting if we loaded everything into a separate map and skipped assigning it in the end if it's empty (to preserve nil).
imageTypes := make(map[string]ImageTypeYAML)
for _, cfg := range configs {
for name, v := cfg.ImageTypes {
... load etc ...
}
}
if len(imageTypes) > 0 {
d.imageTypes = imageTypes
}We're going to run through configs and image types anyway, no need to do it twice. The total count (len(imageTypes)) is right there in the end.
f27b3f0 to
e85fbe6
Compare
|
Thank you everyone for your reviews. I tried to address everyone's comments, I did keep the name of the field though, I am open to renaming it back if we find a nice way to solve this. :) |
Update LoadImageTypes to search for all relevant files in the folder, add image type from each of those. The function allows for each image type to appear in only one file.
Move the image config field from the image types yaml into distro definitions. Allow image types to contain only definitions of image types.
Remove anchors defined in imagetypes.yaml that were not used anywhere in the yaml.
Remove the default_kernel_options which was unused for fedora, and had also a typo.
Add a logic for prepending a file _common.yaml in front of other yaml image types. Allow splitting yaml files while keeping common anchors.
There was a problem hiding this comment.
Thank you. With all the comments addressed this is a great start to offering more options for organizing image types and our YAML in general (and moving image_config into the distro YAML is something I've wanted for a while).
I'm sure (some) things will change in the future in how all of this works but there's nothing that's actively bad in this PR 🙂.
I'll continue on #2266 so we can discuss there what the final form would/could look like (as soon as I get it non-conflicting again).
This PR contains changes in the functional part of the code, there is also a draft #2266 that shows what these changes allow us. We wanted to keep changes in the .yaml separately in order to prevent merge conflicts. :)