Skip to content

Commit

Permalink
distro/rhel8: fix default AMI image RHSM configuration
Browse files Browse the repository at this point in the history
The change in `common.VersionLessThan()` function revealed a bug in the
RHEL-8 AMI default image config, which resulted in RHSM configuration to
be present in CentOS Stream images. This caused the image build to fail,
since the RHSM configuration didn't exist on the filesystem (sub-man is
not installed by default on CS images).

Previously, the RHSM configuration was always removed from the image
config "by luck", as a result of lexicographical comparison of
"8-stream" and "8.7" -> "8-stream.0" > "8.7". This is no longer true and
comparison result is "8-stream" < "8.7", which resulted in the RHSM
configuration not being removed from CentOS Stream images.

Moreover, the code in RHEL-8 distro definition was comparing the
`osVersion` to "9.1", which was an obvious bug and copy & paste error
from previous refactoring.

Fixes:
 - Ensure that the base EC2 image config does not include any RHSM
   configuration.
 - Ensure that the RHSM configuration is added only to RHEL EC2 images
   older than 8.7. Since that version, the configuration is shipped as
   an RPM included in the image base package set.
 - Ensure that the RHSM configuration is always added to RHEL AMI (BYOS)
   images, since the configuration is not shipped there as an RPM.

Signed-off-by: Tomáš Hozza <[email protected]>
  • Loading branch information
thozza committed Oct 10, 2023
1 parent 9a933bb commit 884ad4f
Showing 1 changed file with 4 additions and 33 deletions.
37 changes: 4 additions & 33 deletions pkg/distro/rhel8/ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,29 +223,6 @@ func baseEc2ImageConfig() *distro.ImageConfig {
},
},
},
RHSMConfig: map[subscription.RHSMStatus]*osbuild.RHSMStageOptions{
subscription.RHSMConfigNoSubscription: {
// RHBZ#1932802
SubMan: &osbuild.RHSMStageOptionsSubMan{
Rhsmcertd: &osbuild.SubManConfigRHSMCERTDSection{
AutoRegistration: common.ToPtr(true),
},
Rhsm: &osbuild.SubManConfigRHSMSection{
ManageRepos: common.ToPtr(false),
},
},
},
subscription.RHSMConfigWithSubscription: {
// RHBZ#1932802
SubMan: &osbuild.RHSMStageOptionsSubMan{
Rhsmcertd: &osbuild.SubManConfigRHSMCERTDSection{
AutoRegistration: common.ToPtr(true),
},
// do not disable the redhat.repo management if the user
// explicitly request the system to be subscribed
},
},
},
SystemdLogind: []*osbuild.SystemdLogindStageOptions{
{
Filename: "00-getty-fixes.conf",
Expand Down Expand Up @@ -317,21 +294,15 @@ func baseEc2ImageConfig() *distro.ImageConfig {

func defaultEc2ImageConfig(rd distribution) *distro.ImageConfig {
ic := baseEc2ImageConfig()
if rd.isRHEL() && common.VersionLessThan(rd.osVersion, "9.1") {
// The RHSM configuration should not be applied since 8.7, but it is instead done by installing the
// redhat-cloud-client-configuration package. See COMPOSER-1804 for more information.
if rd.isRHEL() && common.VersionLessThan(rd.osVersion, "8.7") {
ic = appendRHSM(ic)
// Disable RHSM redhat.repo management
rhsmConf := ic.RHSMConfig[subscription.RHSMConfigNoSubscription]
rhsmConf.SubMan.Rhsm = &osbuild.SubManConfigRHSMSection{ManageRepos: common.ToPtr(false)}
ic.RHSMConfig[subscription.RHSMConfigNoSubscription] = rhsmConf
}
// The RHSM configuration should not be applied since 8.7, but it is instead done by installing the redhat-cloud-client-configuration package.
// See COMPOSER-1804 for more information.
rhel87PlusEc2ImageConfigOverride := &distro.ImageConfig{
RHSMConfig: map[subscription.RHSMStatus]*osbuild.RHSMStageOptions{},
}
if !common.VersionLessThan(rd.osVersion, "8.7") {
ic = rhel87PlusEc2ImageConfigOverride.InheritFrom(ic)
}

return ic
}
Expand All @@ -340,7 +311,7 @@ func defaultEc2ImageConfig(rd distribution) *distro.ImageConfig {
func defaultAMIImageConfig(rd distribution) *distro.ImageConfig {
ic := defaultEc2ImageConfig(rd)
if rd.isRHEL() {
// defaultAMIImageConfig() adds the rhsm options only for RHEL < 9.1
// defaultEc2ImageConfig() adds the rhsm options only for RHEL < 8.7
// Add it unconditionally for AMI
ic = appendRHSM(ic)
}
Expand Down

0 comments on commit 884ad4f

Please sign in to comment.