pkg/utils: Support RHEL 9 Toolbx containers

The URLs for the RHEL Toolbx images based on the Red Hat Universal Base
Images (or UBI) are a bit more complicated to construct, in comparison
to the URLs for Fedora's fedora-toolbox images.  It's not enough to just
concatenate the registry, the image's basename and the release.  Some
parts of the URL depend on the release's major number, which requires
custom code.

So far, the release's major number was hard coded to 8 since only RHEL 8
Toolbx containers were supported.

To support other RHEL major releases, it's necessary to have custom code
to construct the URLs for the Toolbx images.

https://github.com/containers/toolbox/issues/1065
This commit is contained in:
Debarshi Ray 2023-01-29 09:47:13 +01:00
parent 262c90e06f
commit 0a29b374e6

View file

@ -38,15 +38,14 @@ import (
"golang.org/x/sys/unix"
)
type GetFullyQualifiedImageFunc func(string, string) string
type ParseReleaseFunc func(string) (string, error)
type Distro struct {
ContainerNamePrefix string
ImageBasename string
GetFullyQualifiedImage GetFullyQualifiedImageFunc
ParseRelease ParseReleaseFunc
Registry string
Repository string
RepositoryNeedsRelease bool
}
const (
@ -99,18 +98,14 @@ var (
"fedora": {
"fedora-toolbox",
"fedora-toolbox",
getFullyQualifiedImageFedora,
parseReleaseFedora,
"registry.fedoraproject.org",
"",
false,
},
"rhel": {
"rhel-toolbox",
"toolbox",
getFullyQualifiedImageRHEL,
parseReleaseRHEL,
"registry.access.redhat.com",
"ubi8",
false,
},
}
)
@ -319,21 +314,8 @@ func GetFullyQualifiedImageFromDistros(image, release string) (string, error) {
continue
}
var repository string
if distroObj.RepositoryNeedsRelease {
repository = fmt.Sprintf(distroObj.Repository, release)
} else {
repository = distroObj.Repository
}
imageFull := distroObj.Registry
if repository != "" {
imageFull = imageFull + "/" + repository
}
imageFull = imageFull + "/" + image
getFullyQualifiedImageImpl := distroObj.GetFullyQualifiedImage
imageFull := getFullyQualifiedImageImpl(image, release)
logrus.Debugf("Resolved image %s to %s", image, imageFull)
@ -343,6 +325,23 @@ func GetFullyQualifiedImageFromDistros(image, release string) (string, error) {
return "", fmt.Errorf("failed to resolve image %s", image)
}
func getFullyQualifiedImageFedora(image, release string) string {
imageFull := "registry.fedoraproject.org/" + image
return imageFull
}
func getFullyQualifiedImageRHEL(image, release string) string {
i := strings.IndexRune(release, '.')
if i == -1 {
panicMsg := fmt.Sprintf("release %s not in '<major>.<minor>' format", release)
panic(panicMsg)
}
releaseMajor := release[:i]
imageFull := "registry.access.redhat.com/ubi" + releaseMajor + "/" + image
return imageFull
}
// GetGroupForSudo returns the name of the sudoers group.
//
// Some distros call it 'sudo' (eg. Ubuntu) and some call it 'wheel' (eg. Fedora).