Skip to content

Commit

Permalink
pkg/utils: Support RHEL 9 Toolbx containers
Browse files Browse the repository at this point in the history
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.

containers#1065
  • Loading branch information
debarshiray committed Jan 29, 2023
1 parent 9f2f5b5 commit 0e26712
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions src/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
},
}
)
Expand Down Expand Up @@ -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)

Expand All @@ -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).
Expand Down

0 comments on commit 0e26712

Please sign in to comment.