Skip to content

Commit e7c8563

Browse files
committed
pkg/distro: Add Oracle Linux case in GetDistroAndRunner()
Signed-off-by: Laurence Rochfort <laurence.rochfort@oracle.com>
1 parent a073608 commit e7c8563

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

pkg/distro/bootc/shared.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,29 @@ func GetDistroAndRunner(osRelease osinfo.OSRelease) (manifest.Distro, runner.Run
101101
return manifest.DISTRO_NULL, r, nil
102102
}
103103

104+
case "ol":
105+
versionParts := strings.Split(osRelease.VersionID, ".")
106+
// We only use versionParts[0], but check osRelease is valid for safety
107+
if len(versionParts) < 2 {
108+
return manifest.DISTRO_NULL, nil, fmt.Errorf("invalid Oracle Linux version format: %s", osRelease.VersionID)
109+
}
110+
major, err := strconv.ParseUint(versionParts[0], 10, 64)
111+
if err != nil {
112+
return manifest.DISTRO_NULL, nil, fmt.Errorf("cannot parse Oracle Linux major version (%s): %w", versionParts[0], err)
113+
}
114+
r := &runner.Ol{
115+
Version: major,
116+
}
117+
switch major {
118+
case 9:
119+
return manifest.DISTRO_EL9, r, nil
120+
case 10:
121+
return manifest.DISTRO_EL10, r, nil
122+
default:
123+
olog.Printf("Unknown Oracle Linux version %d, using default distro for manifest generation", major)
124+
return manifest.DISTRO_NULL, r, nil
125+
}
126+
104127
case "rhel":
105128
versionParts := strings.Split(osRelease.VersionID, ".")
106129
if len(versionParts) != 2 {

pkg/distro/bootc/shared_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ func TestGetDistroAndRunner(t *testing.T) {
2727
{"centos", "9", manifest.DISTRO_EL9, &runner.CentOS{Version: 9}, ""},
2828
{"centos", "10", manifest.DISTRO_EL10, &runner.CentOS{Version: 10}, ""},
2929
{"centos", "11", manifest.DISTRO_NULL, &runner.CentOS{Version: 11}, ""},
30+
{"ol", "9.7", manifest.DISTRO_EL9, &runner.Ol{Version: 9}, ""},
31+
{"ol", "10.1", manifest.DISTRO_EL10, &runner.Ol{Version: 10}, ""},
32+
{"ol", "10.asdf", manifest.DISTRO_EL10, &runner.Ol{Version: 10}, ""},
33+
{"ol", "10.1.2", manifest.DISTRO_EL10, &runner.Ol{Version: 10}, ""},
34+
{"ol", "11.1", manifest.DISTRO_NULL, &runner.Ol{Version: 11}, ""},
3035
{"rhel", "9.4", manifest.DISTRO_EL9, &runner.RHEL{Major: 9, Minor: 4}, ""},
3136
{"rhel", "10.4", manifest.DISTRO_EL10, &runner.RHEL{Major: 10, Minor: 4}, ""},
3237
{"rhel", "11.4", manifest.DISTRO_NULL, &runner.RHEL{Major: 11, Minor: 4}, ""},
@@ -35,6 +40,8 @@ func TestGetDistroAndRunner(t *testing.T) {
3540
// Sad
3641
{"fedora", "asdf", manifest.DISTRO_NULL, nil, "cannot parse Fedora version (asdf)"},
3742
{"centos", "asdf", manifest.DISTRO_NULL, nil, "cannot parse CentOS version (asdf)"},
43+
{"ol", "10", manifest.DISTRO_NULL, nil, "invalid Oracle Linux version format: 10"},
44+
{"ol", "asdf.1", manifest.DISTRO_NULL, nil, "cannot parse Oracle Linux major version (asdf)"},
3845
{"rhel", "10", manifest.DISTRO_NULL, nil, "invalid RHEL version format: 10"},
3946
{"rhel", "10.asdf", manifest.DISTRO_NULL, nil, "cannot parse RHEL minor version (asdf)"},
4047
}

0 commit comments

Comments
 (0)