Repository navigation
distro: add DNFSetReleaseVerVar to ImageConfig - #1465
Conversation
Well, now you got me thinking about having pre-defined variables in our image definition yaml files. But no, let's not go down that path just yet please :) |
thozza
left a comment
There was a problem hiding this comment.
Thank you for this new version. I like it a lot more. I've added two comments. The question about not exporting the DNF config-related options in ImageConfig is probably something for the future, but the other comment is something that I'd like to resolve before we merge this PR.
| // Do not use DNFConfig directly, call "DNFConfigOptions()" | ||
| DNFConfig []*osbuild.DNFConfigStageOptions | ||
| DNFSetReleaseVerVar *bool |
There was a problem hiding this comment.
Perhaps we could make these non-exported and export only DNFConfigOptions(). This, however, would require a custom Unmarshaler.
There was a problem hiding this comment.
Thanks for the suggestion, I'm inclined to do this in a followup.
| func (c *ImageConfig) DNFConfigOptions(osVersion string) []*osbuild.DNFConfigStageOptions { | ||
| if c.DNFSetReleaseVerVar == nil || !*c.DNFSetReleaseVerVar { | ||
| return c.DNFConfig | ||
| } | ||
|
|
||
| return append(c.DNFConfig, osbuild.NewDNFConfigStageOptions( | ||
| []osbuild.DNFVariable{ | ||
| { | ||
| Name: "releasever", | ||
| Value: osVersion, | ||
| }, | ||
| }, | ||
| nil, | ||
| )) | ||
| } |
There was a problem hiding this comment.
I have two comments:
- The result of this change is that two DNF config stages may be added to the manifest, instead of a single one. Probably not a big deal, but it is a behavior change.
- I'm not sure how pedantic we should be, because if two DNF config stages are added to the manifest, the one not created from the newly introduced
booloption can also define thereleasevervariable. Then we will end up with one overriding the other. Would it be worth it to handle such a situation?
There was a problem hiding this comment.
Right, the old behavior is to just override any existing DNFConfig and because we do not do a deep merge inheriting also resulting silent overriding.
If we want to be as close as possible to the original behavior we could do:
diff --git a/pkg/distro/image_config.go b/pkg/distro/image_config.go
index 39023874c..6fc0c46c7 100644
--- a/pkg/distro/image_config.go
+++ b/pkg/distro/image_config.go
@@ -153,15 +153,22 @@ func (c *ImageConfig) DNFConfigOptions(osVersi
on string) []*osbuild.DNFConfigSta
return c.DNFConfig
}
- return append(c.DNFConfig, osbuild.NewDNFConfigStageOptions(
- []osbuild.DNFVariable{
- {
- Name: "releasever",
- Value: osVersion,
+ // YAGNI: support both DNFConfig and DNFSetReleaseVerVar onc
e we
+ // have a use-case
+ if c.DNFConfig != nil {
+ panic("internal error: DNFConfig and DNFSetReleaseVe
rVar cannot be used together")
+ }
+ return []*osbuild.DNFConfigStageOptions{
+ osbuild.NewDNFConfigStageOptions(
+ []osbuild.DNFVariable{
+ {
+ Name: "releasever",
+ Value: osVersion,
+ },
},
- },
- nil,
- ))
+ nil,
+ ),
+ }
}
func (c *ImageConfig) WSLConfStageOptions() *osbuild.WSLConfStageOp
tions {
diff --git a/pkg/distro/image_config_test.go b/pkg/distro/image_conf
ig_test.go
index ad63570c6..a439df96f 100644
--- a/pkg/distro/image_config_test.go
+++ b/pkg/distro/image_config_test.go
@@ -190,14 +190,8 @@ func TestImageConfigDNFConfigOptionsPreExisting
(t *testing.T) {
}
assert.Equal(t, cnf.DNFConfig, cnf.DNFConfigOptions("9-strea
m"))
- expected := append(cnf.DNFConfig, &osbuild.DNFConfigStageOpt
ions{
- Variables: []osbuild.DNFVariable{
- {
- Name: "releasever",
- Value: "9-stream",
- },
- },
- })
cnf.DNFSetReleaseVerVar = common.ToPtr(true)
- assert.Equal(t, expected, cnf.DNFConfigOptions("9-stream"))
+ assert.Panics(t, func() {
+ cnf.DNFConfigOptions("9-stream")
+ })
}(the upside is that it becomes very clear when we need to handle this case which is not a bad property).
As for (2) - that is a good question. My strawman would be that we just leave it to the user for now, if they want to manually create a releasever that conflicts with the one we automatically set they can keep the pieces. If mean, if we expose all of the DNFConfig options they have the freedom to break things, if we don't want this, we probably need an approach close to the original PR that restricts the settings. Maybe we could add a comment to the code saying something like // users could create DNFConfig stages with conflicting releasever values maually, for now we ignore this failure scenario as there are more things a user can do that might break the DNFConfig stages (or something along these lines).
There was a problem hiding this comment.
Right, the old behavior is to just override any existing DNFConfig and because we do not do a deep merge inheriting also resulting silent overriding.
I'm not sure what do you mean by silent overriding. ImageConfig can only inherit unset values from another ImageConfig instance. The behavior is very much intentional, because doing a deep merge would become a nightmare to get right for any reasonably complex stage options (especially if we want to support "unseting" values).
Nevertheless, you brought up an important case that I didn't consider before - ImageConfig inheritance.
The desire is for ImageConfig on lower level (i.e. distro-level vs. image-type-level) not to inherit values that are set on the lower level. However, by splitting the DNF config into two ImageConfig properties, one needs to set both values in the lower-level ImageConfig. I'm wondering if it wouldn't be better to nest all "DNF config options" (meaning the stage options + the new bool option) under a common struct. In this particular case, the use case for it is probably not that prominent, but we should keep this in mind to keep the ImageConfig inheritance model sane at least for the time being.
If we want to be as close as possible to the original behavior we could do:
diff --git a/pkg/distro/image_config.go b/pkg/distro/image_config.go index 39023874c..6fc0c46c7 100644 --- a/pkg/distro/image_config.go +++ b/pkg/distro/image_config.go @@ -153,15 +153,22 @@ func (c *ImageConfig) DNFConfigOptions(osVersi on string) []*osbuild.DNFConfigSta return c.DNFConfig } - return append(c.DNFConfig, osbuild.NewDNFConfigStageOptions( - []osbuild.DNFVariable{ - { - Name: "releasever", - Value: osVersion, + // YAGNI: support both DNFConfig and DNFSetReleaseVerVar onc e we + // have a use-case + if c.DNFConfig != nil { + panic("internal error: DNFConfig and DNFSetReleaseVe rVar cannot be used together") + } + return []*osbuild.DNFConfigStageOptions{ + osbuild.NewDNFConfigStageOptions( + []osbuild.DNFVariable{ + { + Name: "releasever", + Value: osVersion, + }, }, - }, - nil, - )) + nil, + ), + } } func (c *ImageConfig) WSLConfStageOptions() *osbuild.WSLConfStageOp tions { diff --git a/pkg/distro/image_config_test.go b/pkg/distro/image_conf ig_test.go index ad63570c6..a439df96f 100644 --- a/pkg/distro/image_config_test.go +++ b/pkg/distro/image_config_test.go @@ -190,14 +190,8 @@ func TestImageConfigDNFConfigOptionsPreExisting (t *testing.T) { } assert.Equal(t, cnf.DNFConfig, cnf.DNFConfigOptions("9-strea m")) - expected := append(cnf.DNFConfig, &osbuild.DNFConfigStageOpt ions{ - Variables: []osbuild.DNFVariable{ - { - Name: "releasever", - Value: "9-stream", - }, - }, - }) cnf.DNFSetReleaseVerVar = common.ToPtr(true) - assert.Equal(t, expected, cnf.DNFConfigOptions("9-stream")) + assert.Panics(t, func() { + cnf.DNFConfigOptions("9-stream") + }) }(the upside is that it becomes very clear when we need to handle this case which is not a bad property).
As for (2) - that is a good question. My strawman would be that we just leave it to the user for now, if they want to manually create a releasever that conflicts with the one we automatically set they can keep the pieces. If mean, if we expose all of the DNFConfig options they have the freedom to break things, if we don't want this, we probably need an approach close to the original PR that restricts the settings. Maybe we could add a comment to the code saying something like
// users could create DNFConfig stages with conflicting releasever values maually, for now we ignore this failure scenario as there are more things a user can do that might break the DNFConfig stages(or something along these lines).
For now, the user in this context is someone defining an image type or a distribution. If we ever expose the defining DNF configuration as a BP customization, it should override any settings set in the ImageConfig.
That said, I'm mostly worried about our image definitions silently overriding configuration values in the resulting image. So from that point of view, we should ideally catch such issues at compile time or at startup (when reading the definition from the YAML). Your suggestion is OK from my PoV. An alternative would be to check for the existence of the releasever variable in the config when DNFSetReleaseVerVar is set. I'm fine with deferring this to the time when we will need to set both, the DNFSetReleaseVerVar value as well as some other DNF config values.
There was a problem hiding this comment.
Grouping them into a struct makes a lot of sense. 👍
There was a problem hiding this comment.
Right, the old behavior is to just override any existing DNFConfig and because we do not do a deep merge inheriting also resulting silent overriding.
I'm not sure what do you mean by silent overriding.
ImageConfigcan only inherit unset values from anotherImageConfiginstance. The behavior is very much intentional, because doing a deep merge would become a nightmare to get right for any reasonably complex stage options (especially if we want to support "unseting" values).
[..]
Sorry, I agree with the exiting merging behavior of imageConfig. I just wanted to mention that it can be surprising in this particular context: if we would create a gce-sap image today just lke we have azure-sap and ec2-sap we would end up with something like:
gce-sap.diff.txt, the relevant part:
+func mkGCESapImageType(osVersion string) *rhel.ImageType {
...
+ it.DefaultImageConfig = sapImageConfig(osVersion).InheritFrom(baseGCEImageConfig())
...but that would not include the baseGCEImageConfig.DNFConfig that sets IPResolve: 4 as the sap image config overrides this (silently) with the DNFConfig to set the releasever. (just did this diff to illustrate what I meant with the inheriting/silent override comment).
There was a problem hiding this comment.
@thozza Fwiw, I updated the code so that it errors when both a manual DNFConfig is set and DNFSetReleaseVerVar is requested.
There was a problem hiding this comment.
Thanks.
Can you please group the two DNF config options in a single struct in a follow-up?
There was a problem hiding this comment.
Sure, just to double check that I got the suggestion right, you mean group them like this into a single struct?
diff --git a/pkg/distro/image_config.go b/pkg/distro/image_config.go
index f09e3e734..5cdcd6a4a 100644
--- a/pkg/distro/image_config.go
+++ b/pkg/distro/image_config.go
@@ -58,8 +58,7 @@ type ImageConfig struct {
PamLimitsConf []*osbuild.PamLimitsConfStageOptions
Sysctld []*osbuild.SysctldStageOptions
// Do not use DNFConfig directly, call "DNFConfigOptions()"
- DNFConfig []*osbuild.DNFConfigStageOptions
- DNFSetReleaseVerVar *bool
+ DNFConfig *DNFConfig
SshdConfig *osbuild.SshdConfigStageOptions
Authconfig *osbuild.AuthconfigStageOptions
PwQuality *osbuild.PwqualityConfStageOptions
@@ -119,6 +118,11 @@ type ImageConfig struct {
MountUnits *bool
}
+type DNFConfig struct {
+ Options []*osbuild.DNFConfigStageOptions
+ DNFSetReleaseVerVar *bool
+}
+
type WSLConfig struct {
BootSystemd bool
}There was a problem hiding this comment.
Yes, exactly like this. Thank you.
This commit adds a new `DNFSetReleaseVerVar` to `ImageConfig` and a new `DNFConfigOptions() helper. The rational is that `DNFConfigStageOptions` current gets the `osVersion` passed in directly. When we move to a YAML based ImageConfig this will be problematic as we do not have access to variables like this. By making this new declarative option we sidestep the problem. This option is used in the rhel sap images. Its slightly unfortunate that we need to change two places (images.go in rhel/fedora) to use the new helper (pr#1387 would fix this) but with more YAML work eventually this should converge. Thanks to thozza for suggesting this simplified approach.
3dd08f3 to
515a888
Compare
tag v0.140.0 Tagger: imagebuilder-bot <[email protected]> Changes with 0.140.0 ---------------- * Loader part override followups (osbuild/image-builder#1466) * Author: Michael Vogt, Reviewers: Tomáš Hozza * RHEL-10/gce: install cloud-utils-growpart by default (osbuild/image-builder#1463) * Author: Tomáš Hozza, Reviewers: Michael Vogt, Simon de Vlieger * base-host-check: expand to cover more (COMPOSER-2498) (osbuild/image-builder#1432) * Author: Simon de Vlieger, Reviewers: Tomáš Hozza * rhel8,9: move partitioning into YAML (osbuild/image-builder#1390) * Author: Michael Vogt, Reviewers: Tomáš Hozza — Somewhere on the Internet, 2025-04-28 --- tag v0.141.0 Tagger: imagebuilder-bot <[email protected]> Changes with 0.141.0 ---------------- * Shrink the current installer images a bit (osbuild/image-builder#1423) * Author: Brian C. Lane, Reviewers: Achilleas Koutsou, Simon de Vlieger, Tomáš Hozza * Update EL10 Azure images with changes made in RHEL 9.6 (osbuild/image-builder#1472) * Author: Achilleas Koutsou, Reviewers: Michael Vogt, Tomáš Hozza * distro: add DNFSetReleaseVerVar to ImageConfig (osbuild/image-builder#1465) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Tomáš Hozza * test/base-host-check.sh: fix disabled firewall services check (osbuild/image-builder#1471) * Author: Sanne Raymaekers, Reviewers: Achilleas Koutsou, Tomáš Hozza — Somewhere on the Internet, 2025-04-29 ---
tag v0.140.0 Tagger: imagebuilder-bot <[email protected]> Changes with 0.140.0 ---------------- * Loader part override followups (osbuild/image-builder#1466) * Author: Michael Vogt, Reviewers: Tomáš Hozza * RHEL-10/gce: install cloud-utils-growpart by default (osbuild/image-builder#1463) * Author: Tomáš Hozza, Reviewers: Michael Vogt, Simon de Vlieger * base-host-check: expand to cover more (COMPOSER-2498) (osbuild/image-builder#1432) * Author: Simon de Vlieger, Reviewers: Tomáš Hozza * rhel8,9: move partitioning into YAML (osbuild/image-builder#1390) * Author: Michael Vogt, Reviewers: Tomáš Hozza — Somewhere on the Internet, 2025-04-28 --- tag v0.141.0 Tagger: imagebuilder-bot <[email protected]> Changes with 0.141.0 ---------------- * Shrink the current installer images a bit (osbuild/image-builder#1423) * Author: Brian C. Lane, Reviewers: Achilleas Koutsou, Simon de Vlieger, Tomáš Hozza * Update EL10 Azure images with changes made in RHEL 9.6 (osbuild/image-builder#1472) * Author: Achilleas Koutsou, Reviewers: Michael Vogt, Tomáš Hozza * distro: add DNFSetReleaseVerVar to ImageConfig (osbuild/image-builder#1465) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Tomáš Hozza * test/base-host-check.sh: fix disabled firewall services check (osbuild/image-builder#1471) * Author: Sanne Raymaekers, Reviewers: Achilleas Koutsou, Tomáš Hozza — Somewhere on the Internet, 2025-04-29 ---
This commit creates a new 'ImageConfig.DNFConfig` struct that contains the `Options` and the `SetReleaseVerVar` options in a single struct. This is a followup for osbuild#1465 (comment) Thanks to Tomáš for the suggestion.
This commit creates a new 'ImageConfig.DNFConfig` struct that contains the `Options` and the `SetReleaseVerVar` options in a single struct. This is a followup for #1465 (comment) Thanks to Tomáš for the suggestion.
This commit adds a new
DNFSetReleaseVerVartoImageConfigand a new `DNFConfigOptions() helper.The rational is that
DNFConfigStageOptionscurrent gets theosVersionpassed in directly. When we move to a YAML based ImageConfig this will be problematic as we do not have access to variables like this. By making this new declarative option we sidestep the problem.This option is used in the rhel sap images.
Its slightly unfortunate that we need to change two places (images.go in rhel/fedora) to use the new
helper (pr#1387 would fix this) but with more YAML work eventually this should converge.
Thanks to thozza for suggesting this simplified approach.
JIRA: HMS-5284