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:
parent
262c90e06f
commit
0a29b374e6
1 changed files with 23 additions and 24 deletions
|
@ -38,15 +38,14 @@ import (
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type GetFullyQualifiedImageFunc func(string, string) string
|
||||||
type ParseReleaseFunc func(string) (string, error)
|
type ParseReleaseFunc func(string) (string, error)
|
||||||
|
|
||||||
type Distro struct {
|
type Distro struct {
|
||||||
ContainerNamePrefix string
|
ContainerNamePrefix string
|
||||||
ImageBasename string
|
ImageBasename string
|
||||||
|
GetFullyQualifiedImage GetFullyQualifiedImageFunc
|
||||||
ParseRelease ParseReleaseFunc
|
ParseRelease ParseReleaseFunc
|
||||||
Registry string
|
|
||||||
Repository string
|
|
||||||
RepositoryNeedsRelease bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -99,18 +98,14 @@ var (
|
||||||
"fedora": {
|
"fedora": {
|
||||||
"fedora-toolbox",
|
"fedora-toolbox",
|
||||||
"fedora-toolbox",
|
"fedora-toolbox",
|
||||||
|
getFullyQualifiedImageFedora,
|
||||||
parseReleaseFedora,
|
parseReleaseFedora,
|
||||||
"registry.fedoraproject.org",
|
|
||||||
"",
|
|
||||||
false,
|
|
||||||
},
|
},
|
||||||
"rhel": {
|
"rhel": {
|
||||||
"rhel-toolbox",
|
"rhel-toolbox",
|
||||||
"toolbox",
|
"toolbox",
|
||||||
|
getFullyQualifiedImageRHEL,
|
||||||
parseReleaseRHEL,
|
parseReleaseRHEL,
|
||||||
"registry.access.redhat.com",
|
|
||||||
"ubi8",
|
|
||||||
false,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -319,21 +314,8 @@ func GetFullyQualifiedImageFromDistros(image, release string) (string, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var repository string
|
getFullyQualifiedImageImpl := distroObj.GetFullyQualifiedImage
|
||||||
|
imageFull := getFullyQualifiedImageImpl(image, release)
|
||||||
if distroObj.RepositoryNeedsRelease {
|
|
||||||
repository = fmt.Sprintf(distroObj.Repository, release)
|
|
||||||
} else {
|
|
||||||
repository = distroObj.Repository
|
|
||||||
}
|
|
||||||
|
|
||||||
imageFull := distroObj.Registry
|
|
||||||
|
|
||||||
if repository != "" {
|
|
||||||
imageFull = imageFull + "/" + repository
|
|
||||||
}
|
|
||||||
|
|
||||||
imageFull = imageFull + "/" + image
|
|
||||||
|
|
||||||
logrus.Debugf("Resolved image %s to %s", image, imageFull)
|
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)
|
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.
|
// GetGroupForSudo returns the name of the sudoers group.
|
||||||
//
|
//
|
||||||
// Some distros call it 'sudo' (eg. Ubuntu) and some call it 'wheel' (eg. Fedora).
|
// Some distros call it 'sudo' (eg. Ubuntu) and some call it 'wheel' (eg. Fedora).
|
||||||
|
|
Loading…
Reference in a new issue