diff --git a/src/pkg/utils/utils.go b/src/pkg/utils/utils.go index 1931aff5c..f33d0db53 100644 --- a/src/pkg/utils/utils.go +++ b/src/pkg/utils/utils.go @@ -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 '.' 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).