Skip to content

Commit

Permalink
Distro: add initial support for el10/c10s
Browse files Browse the repository at this point in the history
To unblock c10s development, add a quick and dirty version of
RHEL-10/c10s.

Fix #501

Signed-off-by: Tomáš Hozza <[email protected]>
  • Loading branch information
thozza authored and ondrejbudai committed Mar 14, 2024
1 parent d9e9ead commit 1554ad2
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 17 deletions.
9 changes: 7 additions & 2 deletions pkg/distro/rhel9/ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,9 @@ func ec2BuildPackageSet(t *imageType) rpmmd.PackageSet {
}

func ec2CommonPackageSet(t *imageType) rpmmd.PackageSet {
return rpmmd.PackageSet{
ps := rpmmd.PackageSet{
Include: []string{
"@core",
"authselect-compat",
"chrony",
"cloud-init",
"cloud-utils-growpart",
Expand Down Expand Up @@ -350,6 +349,12 @@ func ec2CommonPackageSet(t *imageType) rpmmd.PackageSet {
"qemu-guest-agent",
},
}.Append(distroSpecificPackageSet(t))

if common.VersionLessThan(t.arch.distro.osVersion, "10.0") {
ps.Include = append(ps.Include, "authselect-compat")
}

return ps
}

// common rhel ec2 RHUI image package set
Expand Down
6 changes: 5 additions & 1 deletion pkg/distro/rhel9/bare_metal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rhel9
import (
"fmt"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/arch"
"github.com/osbuild/images/pkg/rpmmd"
)
Expand Down Expand Up @@ -48,7 +49,6 @@ func bareMetalPackageSet(t *imageType) rpmmd.PackageSet {
ps := rpmmd.PackageSet{
Include: []string{
"@core",
"authselect-compat",
"chrony",
"cockpit-system",
"cockpit-ws",
Expand Down Expand Up @@ -90,6 +90,10 @@ func bareMetalPackageSet(t *imageType) rpmmd.PackageSet {
},
}.Append(distroBuildPackageSet(t))

if common.VersionLessThan(t.arch.distro.osVersion, "10.0") {
ps.Include = append(ps.Include, "authselect-compat")
}

// Ensure to not pull in subscription-manager on non-RHEL distro
if t.arch.distro.isRHEL() {
ps = ps.Append(rpmmd.PackageSet{
Expand Down
74 changes: 68 additions & 6 deletions pkg/distro/rhel9/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ func (d *distribution) getDefaultImageConfig() *distro.ImageConfig {
return d.defaultImageConfig
}

func newDistro(name string, minor int) *distribution {
func newDistro(name string, major, minor int) *distribution {
var rd distribution
switch name {
case "rhel":
switch fmt.Sprintf("%s-%d", name, major) {
case "rhel-9":
rd = distribution{
name: fmt.Sprintf("rhel-9.%d", minor),
product: "Red Hat Enterprise Linux",
Expand All @@ -141,7 +141,20 @@ func newDistro(name string, minor int) *distribution {
runner: &runner.RHEL{Major: uint64(9), Minor: uint64(minor)},
defaultImageConfig: defaultDistroImageConfig,
}
case "centos":
case "rhel-10":
rd = distribution{
name: fmt.Sprintf("rhel-10.%d", minor),
product: "Red Hat Enterprise Linux",
osVersion: fmt.Sprintf("10.%d", minor),
releaseVersion: "10",
modulePlatformID: "platform:el10",
vendor: "redhat",
ostreeRefTmpl: "rhel/10/%s/edge",
isolabelTmpl: fmt.Sprintf("RHEL-10-%d-0-BaseOS-%%s", minor),
runner: &runner.RHEL{Major: uint64(10), Minor: uint64(minor)},
defaultImageConfig: defaultDistroImageConfig,
}
case "centos-9":
rd = distribution{
name: "centos-9",
product: "CentOS Stream",
Expand All @@ -154,8 +167,21 @@ func newDistro(name string, minor int) *distribution {
runner: &runner.CentOS{Version: uint64(9)},
defaultImageConfig: defaultDistroImageConfig,
}
case "centos-10":
rd = distribution{
name: "centos-10",
product: "CentOS Stream",
osVersion: "10-stream",
releaseVersion: "10",
modulePlatformID: "platform:el10",
vendor: "centos",
ostreeRefTmpl: "centos/10/%s/edge",
isolabelTmpl: "CentOS-Stream-10-BaseOS-%s",
runner: &runner.CentOS{Version: uint64(10)},
defaultImageConfig: defaultDistroImageConfig,
}
default:
panic(fmt.Sprintf("unknown distro name: %s", name))
panic(fmt.Sprintf("unknown distro name: %s and major: %d", name, major))
}

// Architecture definitions
Expand Down Expand Up @@ -510,5 +536,41 @@ func DistroFactory(idStr string) distro.Distro {
return nil
}

return newDistro(id.Name, id.MinorVersion)
return newDistro(id.Name, 9, id.MinorVersion)
}

func ParseIDEl10(idStr string) (*distro.ID, error) {
id, err := distro.ParseID(idStr)
if err != nil {
return nil, err
}

if id.Name != "rhel" && id.Name != "centos" {
return nil, fmt.Errorf("invalid distro name: %s", id.Name)
}

if id.MajorVersion != 10 {
return nil, fmt.Errorf("invalid distro major version: %d", id.MajorVersion)
}

// CentOS does not use minor version
if id.Name == "centos" && id.MinorVersion != -1 {
return nil, fmt.Errorf("centos does not use minor version, but got: %d", id.MinorVersion)
}

// RHEL uses minor version
if id.Name == "rhel" && id.MinorVersion == -1 {
return nil, fmt.Errorf("rhel requires minor version, but got: %d", id.MinorVersion)
}

return id, nil
}

func DistroFactoryEl10(idStr string) distro.Distro {
id, err := ParseIDEl10(idStr)
if err != nil {
return nil
}

return newDistro(id.Name, 10, id.MinorVersion)
}
14 changes: 7 additions & 7 deletions pkg/distro/rhel9/distro_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,31 @@ func TestDistroFactory(t *testing.T) {
testCases := []testCase{
{
strID: "rhel-90",
expected: newDistro("rhel", 0),
expected: newDistro("rhel", 9, 0),
},
{
strID: "rhel-9.0",
expected: newDistro("rhel", 0),
expected: newDistro("rhel", 9, 0),
},
{
strID: "rhel-93",
expected: newDistro("rhel", 3),
expected: newDistro("rhel", 9, 3),
},
{
strID: "rhel-9.3",
expected: newDistro("rhel", 3),
expected: newDistro("rhel", 9, 3),
},
{
strID: "rhel-910",
expected: newDistro("rhel", 10),
expected: newDistro("rhel", 9, 10),
},
{
strID: "rhel-9.10",
expected: newDistro("rhel", 10),
expected: newDistro("rhel", 9, 10),
},
{
strID: "centos-9",
expected: newDistro("centos", -1),
expected: newDistro("centos", 9, -1),
},
{
strID: "centos-9.0",
Expand Down
5 changes: 4 additions & 1 deletion pkg/distro/rhel9/qcow2.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func qcow2CommonPackageSet(t *imageType) rpmmd.PackageSet {
ps := rpmmd.PackageSet{
Include: []string{
"@core",
"authselect-compat",
"chrony",
"cloud-init",
"cloud-utils-growpart",
Expand Down Expand Up @@ -94,6 +93,10 @@ func qcow2CommonPackageSet(t *imageType) rpmmd.PackageSet {
},
}.Append(distroSpecificPackageSet(t))

if common.VersionLessThan(t.arch.distro.osVersion, "10.0") {
ps.Include = append(ps.Include, "authselect-compat")
}

// Ensure to not pull in subscription-manager on non-RHEL distro
if t.arch.distro.isRHEL() {
ps = ps.Append(rpmmd.PackageSet{
Expand Down
1 change: 1 addition & 0 deletions pkg/distrofactory/distrofactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func NewDefault() *Factory {
rhel7.DistroFactory,
rhel8.DistroFactory,
rhel9.DistroFactory,
rhel9.DistroFactoryEl10,
)
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/distrofactory/distrofactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ func TestGetDistroDefaultList(t *testing.T) {
strID: "rhel-9.10",
expectedDistroName: "rhel-9.10",
},
{
strID: "rhel-10.1",
expectedDistroName: "rhel-10.1",
},
{
strID: "rhel-10.10",
expectedDistroName: "rhel-10.10",
},
{
strID: "fedora-38",
expectedDistroName: "fedora-38",
Expand Down
1 change: 1 addition & 0 deletions pkg/distroidparser/idparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ func NewDefaultParser() *Parser {
rhel7.ParseID,
rhel8.ParseID,
rhel9.ParseID,
rhel9.ParseIDEl10,
)
}
30 changes: 30 additions & 0 deletions pkg/distroidparser/idparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,36 @@ func TestDefaltParser(t *testing.T) {
idStr: "centos-9.2.2",
err: true,
},
// RHEL-10
{
idStr: "rhel-10",
expected: &distro.ID{Name: "rhel", MajorVersion: 10, MinorVersion: -1},
},
{
idStr: "rhel-10.0",
expected: &distro.ID{Name: "rhel", MajorVersion: 10, MinorVersion: 0},
},
{
idStr: "rhel-10.10",
expected: &distro.ID{Name: "rhel", MajorVersion: 10, MinorVersion: 10},
},
{
idStr: "rhel-10.1.1",
err: true,
},
// CentOS-10
{
idStr: "centos-10",
expected: &distro.ID{Name: "centos", MajorVersion: 10, MinorVersion: -1},
},
{
idStr: "centos-10.2",
expected: &distro.ID{Name: "centos", MajorVersion: 10, MinorVersion: 2},
},
{
idStr: "centos-10.2.2",
err: true,
},
// Non-existing distro
{
idStr: "tuxdistro-1",
Expand Down

0 comments on commit 1554ad2

Please sign in to comment.