Skip to content

distro: make DNFConfig more declarative - #1464

Closed
mvo5 wants to merge 1 commit into
osbuild:mainfrom
mvo5:dnf-vars-declarative
Closed

mvo5 wants to merge 1 commit into
osbuild:mainfrom
mvo5:dnf-vars-declarative

Conversation

@mvo5

@mvo5 mvo5 commented Apr 24, 2025

Copy link
Copy Markdown
Contributor

This commit removes the DNFConfigStageOptions from ImageConfig in favor of a simpler DNFConfig struct.

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 a declarative option we sidestep the problem.

This generates no manifest diff.

Needed for #1462

This commit removes the `DNFConfigStageOptions` from
`ImageConfig` in favor of a simpler `DNFConfig` struct.

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
a declarative option we sidestep the problem.
Comment on lines +154 to +180
func (c *ImageConfig) DNFConfigOptions(osVersion string) []*osbuild.DNFConfigStageOptions {
if c.DNFConfig == nil {
return nil
}
var res []*osbuild.DNFConfigStageOptions
if c.DNFConfig.SetReleaseVerVar {
res = append(res, osbuild.NewDNFConfigStageOptions(
[]osbuild.DNFVariable{
{
Name: "releasever",
Value: osVersion,
},
},
nil,
))
}
if c.DNFConfig.ForceIPv4 {
res = append(res, &osbuild.DNFConfigStageOptions{
Config: &osbuild.DNFConfig{
Main: &osbuild.DNFConfigMain{
IPResolve: "4",
},
},
})
}
return res
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I like this approach.

FWIW, I do understand that setting the releasever from the YAML to osVersion would require introducing some magic value that we would need to replace. Which is a can of worms, because then we get into templating the YAML. This solution is simple from that PoV.

What I don't like is that this limits our options in the ImageConfig significantly going forward. My position is that we should keep ImageConfig as powerful as possible, which means keeping the ability to take advantage of the stage options that we have. With this change, we lose the option to define arbitrary variables for DNF easily. Additionally, if we ever add any additional DNF config options, I don't want us to be adding booleans for every possible combination.

I'd like us to use abstracted options only for complex things that would require touching multiple configurations. Or at the minimum, keep our options open and don't reduce what we can define via ImageConfig.

What about a compromise such as:

  • Keep the DNFConfigStageOptions in ImageConfig and expose it in YAML. Set the IPResolve value explicitly in the YAML.
  • Add a bool option specifically just for SetReleaseVerVar and in such case, set the releasever to osVersion in the DNFConfigStageOptions (potentially combining it with values and other variables set in the YAML). I understand that there is still the corner case of someone defining releasever in the YAML as well as setting the bool option, but that could be an error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I opened #1465 with this alternative approach.

Variables: []osbuild.DNFVariable{
{
Name: "releasever",
Value: "centos-9",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I know that these are just unit tests, but the releasever is ever set only to X.Y in RHEL images (and for centos it is X-stream). This mechanism allows you to pin the host repositories to a specific Extended Update Support (EUS) version of RHEL. Using centos-9 may give one the wrong impression of its purpose.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed in the other PR

}
}

func TestImageConfiDNCConfigNone(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func TestImageConfiDNCConfigNone(t *testing.T) {
func TestImageConfigDNFConfigNone(t *testing.T) {

AI found a double-typo here. :)

@mvo5

mvo5 commented Apr 25, 2025

Copy link
Copy Markdown
Contributor Author

Closing in favor of #1465

@mvo5 mvo5 closed this Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants