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

Add support for RHEL 8.10 / 9.4 distros #195

Merged
merged 8 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/google/uuid v1.3.1
github.com/gophercloud/gophercloud v1.7.0
github.com/hashicorp/go-retryablehttp v0.7.4
github.com/hashicorp/go-version v1.6.0
github.com/kolo/xmlrpc v0.0.0-20201022064351-38db28db192b
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-retryablehttp v0.7.4 h1:ZQgVdpTdAL7WpMIwLzCfbalOcSUdkDZnpUv3/+BxzFA=
github.com/hashicorp/go-retryablehttp v0.7.4/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/honeycombio/beeline-go v1.10.0 h1:cUDe555oqvw8oD76BQJ8alk7FP0JZ/M/zXpNvOEDLDc=
github.com/honeycombio/libhoney-go v1.16.0 h1:kPpqoz6vbOzgp7jC6SR7SkNj7rua7rgxvznI6M3KdHc=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down
33 changes: 14 additions & 19 deletions internal/common/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io"
"os"
"strings"

"github.com/hashicorp/go-version"
)

func GetHostDistroName() (string, bool, bool, error) {
Expand Down Expand Up @@ -54,30 +56,23 @@ func readOSRelease(r io.Reader) (map[string]string, error) {

// Returns true if the version represented by the first argument is
// semantically older than the second.
//
// Meant to be used for comparing distro versions for differences between minor
// releases.
// Evaluates to false if a and b are equal.
//
// Provided version strings are of any characters which are not
// digits or periods, and then split on periods.
// Assumes any missing components are 0, so 8 < 8.1.
// Evaluates to false if a and b are equal.
func VersionLessThan(a, b string) bool {
aParts := strings.Split(a, ".")
bParts := strings.Split(b, ".")

// pad shortest argument with zeroes
for len(aParts) < len(bParts) {
aParts = append(aParts, "0")
}
for len(bParts) < len(aParts) {
bParts = append(bParts, "0")
aV, err := version.NewVersion(a)
if err != nil {
panic(err)
}

for idx := 0; idx < len(aParts); idx++ {
if aParts[idx] < bParts[idx] {
return true
} else if aParts[idx] > bParts[idx] {
return false
}
bV, err := version.NewVersion(b)
if err != nil {
panic(err)
}

// equal
return false
return aV.LessThan(bV)
}
86 changes: 86 additions & 0 deletions internal/common/distro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,89 @@ VARIANT_ID=workstation`,
}
}
}

func TestVersionLessThan(t *testing.T) {
type testCases struct {
Name string
VersionA string
VersionB string
Expected bool
}

cases := []testCases{
{
Name: "8 < 8.1",
VersionA: "8",
VersionB: "8.1",
Expected: true,
},
{
Name: "8.1 < 8.2",
VersionA: "8.1",
VersionB: "8.2",
Expected: true,
},
{
Name: "8 < 9",
VersionA: "8",
VersionB: "9",
Expected: true,
},
{
Name: "8.1 < 9",
VersionA: "8.1",
VersionB: "9",
Expected: true,
},
{
Name: "8.1 < 9.1",
VersionA: "8.1",
VersionB: "9.1",
Expected: true,
},
{
Name: "8 < 8.10",
VersionA: "8",
VersionB: "8.10",
Expected: true,
},
{
Name: "8.1 < 8.10",
VersionA: "8.1",
VersionB: "8.10",
Expected: true,
},
{
Name: "8.10 < 8.11",
VersionA: "8.10",
VersionB: "8.11",
Expected: true,
},
{
Name: "8.10 > 8.6",
VersionA: "8.10",
VersionB: "8.6",
Expected: false,
},
{
Name: "8-stream < 9-stream",
VersionA: "8-stream",
VersionB: "9-stream",
Expected: true,
},
{
Name: "9-stream < 9.1",
achilleas-k marked this conversation as resolved.
Show resolved Hide resolved
VersionA: "9-stream",
VersionB: "9.1",
Expected: true,
},
}

for _, c := range cases {
t.Run(c.Name, func(t *testing.T) {
if VersionLessThan(c.VersionA, c.VersionB) != c.Expected {
t.Fatalf("VersionLessThan(%s, %s) returned unexpected result", c.VersionA, c.VersionB)
}
})
}
}
39 changes: 5 additions & 34 deletions pkg/distro/rhel8/ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func ec2ImgTypeX86_64(rd distribution) imageType {
func ec2HaImgTypeX86_64(rd distribution) imageType {
basePartitionTables := ec2BasePartitionTables
// use legacy partition tables for RHEL 8.8 and older
if common.VersionLessThan(rd.osVersion, "8.9") {
if rd.isRHEL() && common.VersionLessThan(rd.osVersion, "8.9") {
basePartitionTables = ec2LegacyBasePartitionTables
}

Expand Down 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
6 changes: 5 additions & 1 deletion pkg/distro/rhel8/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (d *distribution) getDefaultImageConfig() *distro.ImageConfig {
// New creates a new distro object, defining the supported architectures and image types
func New() distro.Distro {
// default minor: create default minor version (current GA) and rename it
d := newDistro("rhel", 8)
d := newDistro("rhel", 10)
d.name = "rhel-8"
return d

Expand Down Expand Up @@ -155,6 +155,10 @@ func NewRHEL89() distro.Distro {
return newDistro("rhel", 9)
}

func NewRHEL810() distro.Distro {
return newDistro("rhel", 10)
}

func NewCentos() distro.Distro {
return newDistro("centos", 0)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/distro/rhel9/ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func defaultEc2ImageConfig(osVersion string, rhsm bool) *distro.ImageConfig {
func defaultAMIImageConfig(osVersion string, rhsm bool) *distro.ImageConfig {
ic := defaultEc2ImageConfig(osVersion, rhsm)
if rhsm {
// defaultAMIImageConfig() adds the rhsm options only for RHEL < 9.1
// defaultEc2ImageConfig() adds the rhsm options only for RHEL < 9.1
// Add it unconditionally for AMI
ic = appendRHSM(ic)
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/distro/rhel9/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (d *distribution) getDefaultImageConfig() *distro.ImageConfig {

func New() distro.Distro {
// default minor: create default minor version (current GA) and rename it
d := newDistro("rhel", 2)
d := newDistro("rhel", 4)
d.name = "rhel-9"
return d
}
Expand All @@ -151,6 +151,10 @@ func NewRHEL93() distro.Distro {
return newDistro("rhel", 3)
}

func NewRHEL94() distro.Distro {
return newDistro("rhel", 4)
}

func newDistro(name string, minor int) *distribution {
var rd distribution
switch name {
Expand Down
2 changes: 1 addition & 1 deletion pkg/distro/rhel9/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func edgeCommitPackageSet(t *imageType) rpmmd.PackageSet {
ps = ps.Append(aarch64EdgeCommitPackageSet(t))
}

if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || !common.VersionLessThan(t.arch.distro.osVersion, "9-stream") {
if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || !t.arch.distro.isRHEL() {
ps.Include = append(ps.Include, "ignition", "ignition-edge", "ssh-key-dir")
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/distro/rhel9/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func edgeCommitImage(workload workload.Workload,
img.OSVersion = t.arch.distro.osVersion
img.Filename = t.Filename()

if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || t.arch.distro.osVersion == "9-stream" {
if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || !t.arch.distro.isRHEL() {
img.OSCustomizations.EnabledServices = append(img.OSCustomizations.EnabledServices, "ignition-firstboot-complete.service", "coreos-ignition-write-issues.service")
}
img.Environment = t.environment
Expand Down Expand Up @@ -334,7 +334,7 @@ func edgeContainerImage(workload workload.Workload,
img.ExtraContainerPackages = packageSets[containerPkgsKey]
img.Filename = t.Filename()

if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || t.arch.distro.osVersion == "9-stream" {
if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || !t.arch.distro.isRHEL() {
img.OSCustomizations.EnabledServices = append(img.OSCustomizations.EnabledServices, "ignition-firstboot-complete.service", "coreos-ignition-write-issues.service")
}

Expand Down Expand Up @@ -408,12 +408,12 @@ func edgeRawImage(workload workload.Workload,
img.KernelOptionsAppend = []string{"modprobe.blacklist=vc4"}
img.Keyboard = "us"
img.Locale = "C.UTF-8"
if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || t.arch.distro.osVersion == "9-stream" {
if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || !t.arch.distro.isRHEL() {
img.SysrootReadOnly = true
img.KernelOptionsAppend = append(img.KernelOptionsAppend, "rw")
}

if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || t.arch.distro.osVersion == "9-stream" {
if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || !t.arch.distro.isRHEL() {
img.Ignition = true
img.IgnitionPlatform = "metal"
if bpIgnition := customizations.GetIgnition(); bpIgnition != nil && bpIgnition.FirstBoot != nil && bpIgnition.FirstBoot.ProvisioningURL != "" {
Expand Down Expand Up @@ -467,7 +467,7 @@ func edgeSimplifiedInstallerImage(workload workload.Workload,
rawImg.KernelOptionsAppend = []string{"modprobe.blacklist=vc4"}
rawImg.Keyboard = "us"
rawImg.Locale = "C.UTF-8"
if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || t.arch.distro.osVersion == "9-stream" {
if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || !t.arch.distro.isRHEL() {
rawImg.SysrootReadOnly = true
rawImg.KernelOptionsAppend = append(rawImg.KernelOptionsAppend, "rw")
}
Expand All @@ -481,7 +481,7 @@ func edgeSimplifiedInstallerImage(workload workload.Workload,
}
rawImg.OSName = "redhat"

if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || t.arch.distro.osVersion == "9-stream" {
if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || !t.arch.distro.isRHEL() {
rawImg.Ignition = true
rawImg.IgnitionPlatform = "metal"
if bpIgnition := customizations.GetIgnition(); bpIgnition != nil && bpIgnition.FirstBoot != nil && bpIgnition.FirstBoot.ProvisioningURL != "" {
Expand Down
2 changes: 2 additions & 0 deletions pkg/distroregistry/distroregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ var supportedDistros = []func() distro.Distro{
rhel8.NewRHEL87,
rhel8.NewRHEL88,
rhel8.NewRHEL89,
rhel8.NewRHEL810,
rhel8.NewCentos,

rhel9.New,
rhel9.NewRHEL90,
rhel9.NewRHEL91,
rhel9.NewRHEL92,
rhel9.NewRHEL93,
rhel9.NewRHEL94,
rhel9.NewCentOS9,
}

Expand Down
Loading
Loading