Skip to content
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

Expose RHSM configuration as BP customization (COMPOSER-2308) #824

Merged
merged 13 commits into from
Aug 7, 2024

Conversation

thozza
Copy link
Member

@thozza thozza commented Jul 31, 2024

RHSM in the image definitions is the last difference between RHEL RHUI images on el9 / el10, which can't be expressed as a BP customization. To enable the unification of RHUI and non-RHUI images and simplification of the image definitions, expose the RHSM configuration as a BP customization.

I considered naming the high-level customization Subscription, however the name is already used by a customization exposed only by the Cloud API in osbuild-composer. So using it for the BP customization would make it clash with the existing one and look different for on-prem vs. service scenario.

Notable changes

  • I introduced an internal implementation of the RHSM configuration and replaced the osbuild stage options with it in the distro and pipeline implementations.
  • Simplified the OSCustomizations by having only a single instance of the RHSM configuration, which should be applied to the image, instead of having two and deciding which one to use based on the fact if the image should be subscribed or not. The decision logic is now moved to the function which produces OSCustomization instance from ImageConfig, ImageOptions and BP customizations.

Open questions

  • I'm not sure if we want to simply override the default RHSM configuration from the image definition if the RHSM configuration is provided also as a BP customization, or merge them with the BP customization having precedence. Overriding would mean that values set in the default image configuration, but not set in the BP would disappear from the produced manifest. However, overriding would make the implementation much simpler, because the merging requires quite a lot of additional code, which I don't like.

@achilleas-k
Copy link
Member

  • I introduced an internal implementation of the RHSM configuration and replaced the osbuild stage options with it in the distro and pipeline implementations.
  • Simplified the OSCustomizations by having only a single instance of the RHSM configuration, which should be applied to the image, instead of having two and deciding which one to use based on the fact if the image should be subscribed or not. The decision logic is now moved to the function which produces OSCustomization instance from ImageConfig, ImageOptions and BP customizations.

❤️ ❤️

Open questions

  • I'm not sure if we want to simply override the default RHSM configuration from the image definition if the RHSM configuration is provided also as a BP customization, or merge them with the BP customization having precedence. Overriding would mean that values set in the default image configuration, but not set in the BP would disappear from the produced manifest. However, overriding would make the implementation much simpler, because the merging requires quite a lot of additional code, which I don't like.

Yeah, I'm not sure either. There's a lot of code in there to accommodate this and I'm wondering if it's worth it. I think this blueprint customization is mostly for us (I don't expect users to be fiddling with RHSM configs) and the brew build configs will be pretty stable, not changing much if at all. Given all that, it's probably not worth having a bunch of code to support conveniently changing a small subset of the configuration. If this was a more user-facing customization, I'd argue for making it easier to tweak individual options without completely changing the config, but if I'm right that it's not, maybe simplifying the code (and the behaviour) is better in the long run.

Copy link
Member

@achilleas-k achilleas-k left a comment

Choose a reason for hiding this comment

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

Requesting changes for the package move (from pkg/subscription to pkg/customizations/subscription).
Otherwise LGTM (pending discussion about merging vs overriding the full config).

pkg/subscription/subscription.go Outdated Show resolved Hide resolved
pkg/distro/image_config.go Show resolved Hide resolved
pkg/distro/rhel/images.go Outdated Show resolved Hide resolved
pkg/subscription/subscription.go Outdated Show resolved Hide resolved
pkg/subscription/subscription_test.go Outdated Show resolved Hide resolved
@kingsleyzissou
Copy link
Contributor

Open questions

  • I'm not sure if we want to simply override the default RHSM configuration from the image definition if the RHSM configuration is provided also as a BP customization, or merge them with the BP customization having precedence. Overriding would mean that values set in the default image configuration, but not set in the BP would disappear from the produced manifest. However, overriding would make the implementation much simpler, because the merging requires quite a lot of additional code, which I don't like.

Yeah, I'm not sure either. There's a lot of code in there to accommodate this and I'm wondering if it's worth it. I think this blueprint customization is mostly for us (I don't expect users to be fiddling with RHSM configs) and the brew build configs will be pretty stable, not changing much if at all. Given all that, it's probably not worth having a bunch of code to support conveniently changing a small subset of the configuration. If this was a more user-facing customization, I'd argue for making it easier to tweak individual options without completely changing the config, but if I'm right that it's not, maybe simplifying the code (and the behaviour) is better in the long run.

Just to add to the open question with additional questions. If we go the route of overriding the configs this means that the YumPlugins config will always get removed. Would we want to at least check for that and merge it, since that would be pretty straight forward? Or if it's mostly a customization used by us, would we want to expose that and make sure the customizations are okay?

@thozza
Copy link
Member Author

thozza commented Aug 1, 2024

  • I'm not sure if we want to simply override the default RHSM configuration from the image definition if the RHSM configuration is provided also as a BP customization, or merge them with the BP customization having precedence. Overriding would mean that values set in the default image configuration, but not set in the BP would disappear from the produced manifest. However, overriding would make the implementation much simpler, because the merging requires quite a lot of additional code, which I don't like.

Yeah, I'm not sure either. There's a lot of code in there to accommodate this and I'm wondering if it's worth it. I think this blueprint customization is mostly for us (I don't expect users to be fiddling with RHSM configs) and the brew build configs will be pretty stable, not changing much if at all. Given all that, it's probably not worth having a bunch of code to support conveniently changing a small subset of the configuration. If this was a more user-facing customization, I'd argue for making it easier to tweak individual options without completely changing the config, but if I'm right that it's not, maybe simplifying the code (and the behaviour) is better in the long run.

I literally felt bad while writing all that code. 😅 I also don't like the end result and agree that it is too much code for a little benefit.

While I agree that the customization is mostly for us, it will get exposed to end users because Cloud API uses the blueprint implementation from osbuild-composer. And it is also used by Weldr API, thus exposed to users. I could add the customization to ImageOptions, so that it could be exposed only via Cloud API, but it feels wrong.

I can think of only one relatively good reason to keep the merging behavior. The default image RHSM config may contain configuration for subscription-manager itself and for its DNF plugins. Imagine that one provides only subscription-manager config in the BP, which would then wipe out DNF plugins config if these were part of the default configuration. This felt weird. But we can clearly document it.

There's maybe a middle-ground to do the merging only one level higher. This means that if ones provides DNF plugins config, we override only that part and don't touch the sub-man part. If one provides sub-man config, we override only that part and don't touch DNF plugins config. But this may still mean quite a lot of code to handle the logic...

IOW, I'm happy to simplify this in any way, just want to find out what majority of people think is the best option. 😇

@thozza
Copy link
Member Author

thozza commented Aug 1, 2024

Just to add to the open question with additional questions. If we go the route of overriding the configs this means that the YumPlugins config will always get removed. Would we want to at least check for that and merge it, since that would be pretty straight forward? Or if it's mostly a customization used by us, would we want to expose that and make sure the customizations are okay?

Fair question.

So, the reason why YumPlugins are kind of neglected by the implementation is that they are used only for RHEL-7 image definitions. And we do not expose or support building RHEL-7 anywhere externally, only internally in Brew. My plan is to unify the RHUI / non-RHUI image definitions only for RHEL-9+ once this lands, so I kind of ignored YUM 😇

So in this regard, a complete override or the middle-ground that I outlined in my previous comment would probably be cleaner.

Copy link
Contributor

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

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

Thank you! Inline are two quick drive-by ideas

pkg/distro/rhel/images.go Outdated Show resolved Hide resolved
pkg/manifest/os.go Outdated Show resolved Hide resolved
@achilleas-k
Copy link
Member

While I agree that the customization is mostly for us, it will get exposed to end users because Cloud API uses the blueprint implementation from osbuild-composer. And it is also used by Weldr API, thus exposed to users.

Right, of course. I just meant that users probably wont be using it much, but I could be wrong. I don't imagine many users would want to change the configuration for subman. Or would they?

@thozza
Copy link
Member Author

thozza commented Aug 1, 2024

While I agree that the customization is mostly for us, it will get exposed to end users because Cloud API uses the blueprint implementation from osbuild-composer. And it is also used by Weldr API, thus exposed to users.

Right, of course. I just meant that users probably wont be using it much, but I could be wrong. I don't imagine many users would want to change the configuration for subman. Or would they?

Right. Hopefully none of the end users will use it 🤞 They shouldn't need to.

@schuellerf
Copy link
Contributor

ultimately this will imply an additional section in https://github.com/osbuild/osbuild.github.io/blob/main/docs/user-guide/01-blueprint-reference.md
did I get this right?
probably stating that it's for on-prem only (until it's handed up to the API?)

@achilleas-k
Copy link
Member

ultimately this will imply an additional section in https://github.com/osbuild/osbuild.github.io/blob/main/docs/user-guide/01-blueprint-reference.md did I get this right? probably stating that it's for on-prem only (until it's handed up to the API?)

Needs to land in osbuild-composer first but yes.

I forgot to fix the unit test function name when I renamed the 'rpm'
BP customization to its current name. Fixing it now.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
Add an internal representation of the RHSM configuration, which can be
applied to an image.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
Add a helper function for converting `subscription.RHSMConfig` to the
`org.osbuild.rhsm` stage options.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
Replace the use of `org.osbuild.rhsm` stage options for in
`distro.ImageConfig` with the internal representation
`subscription.RHSMConfig`. The same applies also to
`manifest.OSCustomizations`, which inherits the value from
`distro.ImageConfig`.

Adjust all image definitions accordingly.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
Add a new BP customization, allowing the user to configure RHSM and DNF
plugins shipped by subscription-manager.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
@thozza
Copy link
Member Author

thozza commented Aug 2, 2024

I implemented all of the suggestions, except for the override behavior. The reason is that removal of pointers from the internal representation of RHSMConfig simplified the code enough that it may be acceptable. Nevertheless, I'm happy to change it.

To summarize the options for BP RHSM customization behavior when interacting with the image default configuration:

  1. Merge the image default config with BP customization with the BP customization having a precedence. Merging is done on the lower level of struct properties. (the current implementation)
  2. Override the image default config with BP customization. Potentially throwing away configuration values specified in the image definition, even if not set in the BP customization.
  3. Do merging as in the point (1,), but on a higher level configuration blocks (e.g. "DNF Plugins" and "SubMan configuration").

Summary:

  • Moved subscription package to pkg/customizations.
  • Simplified the internal representation of RHSMConfig to use pointers only for primitive types, which simplified the implementation quite a lot.
  • Implemented suggestions from @mvo5 to simplify a few conditions and reduce nesting.

[edit] I force pushed once more, because I additionally simplified RHSMConfigFromBP() and handling of BP customization in osCustomizations().

Add a helper function for converting the RHSM BP customization to
RHSMConfig.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
Historically, the RHSMConfig is defined for two scenarios in the default
image definition - when the image should be subscribed and when not. The
config for both scenarios has been previously copied to the
`OSCustomizations` struct and the appropriate RHSMConfig would be picked
when serializing the `OS` pipeline.

Simplify the flow and make `OSCustomizations` struct contain only the
infal RHSMConfig that should be applied to the image, if any. Move the
logic deciding which RHSMConfig should be used, to the function handling
the creation of `OSCustomizations` from the BP customizations, default
`ImageConfig` and `ImageOptions`. This means to the `osCustomizations()`
function, which is part of the distro implementation.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
Add helper functions for creating a deep copy of RHSMConfig and for
creating an updated RHSMConfig instance from an existing one, with
overridden values set in a second instance. This will be useful for
merging the RHSM configuration from BP with the one in the default image
configuration.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
Update the `osCustomizations()` function to take the RHSM customization
provided in the BP into account and update the RHSM configuration in
`OSCustomizations` instance accordingly.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
Refactor the handling of RHSMConfig to reduce the nesting of conditions
by one level.

Co-authored-by: Michael Vogt <michael.vogt@gmail.com>

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
Co-authored-by: Michael Vogt <michael.vogt@gmail.com>
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
Copy link
Member

@achilleas-k achilleas-k left a comment

Choose a reason for hiding this comment

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

Great stuff.
LGTM

Copy link
Contributor

@kingsleyzissou kingsleyzissou left a comment

Choose a reason for hiding this comment

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

LGTM

@achilleas-k
Copy link
Member

@mvo5 Can you take a look at your comments and resolve them (if you're happy :) )?

Copy link
Contributor

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

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

Thank you!

pkg/osbuild/rhsm_stage.go Show resolved Hide resolved
@achilleas-k achilleas-k added this pull request to the merge queue Aug 7, 2024
Merged via the queue into osbuild:main with commit cdcabab Aug 7, 2024
16 of 18 checks passed
@thozza thozza deleted the rhsm-customization branch August 7, 2024 11:52
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.

5 participants