7384d4
From 9bffb4630b2fc026fe32ddcb2674499c863aac32 Mon Sep 17 00:00:00 2001
7384d4
From: =?UTF-8?q?Ond=C5=99ej=20M=C3=ADchal?= <harrymichal@seznam.cz>
7384d4
Date: Sat, 8 Jan 2022 19:53:53 +0200
7384d4
Subject: [PATCH 1/3] pkg/utils: Use new UBI toolbox image
7384d4
7384d4
Red Hat has published a new UBI image made specificaly for Toolbx.
7384d4
Make use of it from now on.
7384d4
7384d4
Fixes: https://github.com/containers/toolbox/issues/961
7384d4
7384d4
https://github.com/containers/toolbox/issues/976
7384d4
(cherry picked from commit f456c173b6fd69ad390a419d23dafcf3f25b15a8)
7384d4
---
7384d4
 src/pkg/utils/utils.go        | 2 +-
7384d4
 test/system/libs/helpers.bash | 2 +-
7384d4
 2 files changed, 2 insertions(+), 2 deletions(-)
7384d4
7384d4
diff --git a/src/pkg/utils/utils.go b/src/pkg/utils/utils.go
7384d4
index ab59afc22283..3119fee74375 100644
7384d4
--- a/src/pkg/utils/utils.go
7384d4
+++ b/src/pkg/utils/utils.go
7384d4
@@ -104,7 +104,7 @@ var (
7384d4
 		},
7384d4
 		"rhel": {
7384d4
 			"rhel-toolbox",
7384d4
-			"ubi",
7384d4
+			"toolbox",
7384d4
 			parseReleaseRHEL,
7384d4
 			"registry.access.redhat.com",
7384d4
 			"ubi8",
7384d4
diff --git a/test/system/libs/helpers.bash b/test/system/libs/helpers.bash
7384d4
index 548c4c0e745f..e29273a644dd 100644
7384d4
--- a/test/system/libs/helpers.bash
7384d4
+++ b/test/system/libs/helpers.bash
7384d4
@@ -18,7 +18,7 @@ readonly SKOPEO=$(command -v skopeo)
7384d4
 # Images
7384d4
 declare -Ag IMAGES=([busybox]="quay.io/toolbox_tests/busybox" \
7384d4
                    [fedora]="registry.fedoraproject.org/fedora-toolbox" \
7384d4
-                   [rhel]="registry.access.redhat.com/ubi8")
7384d4
+                   [rhel]="registry.access.redhat.com/ubi8/toolbox")
7384d4
 
7384d4
 
7384d4
 function cleanup_all() {
7384d4
-- 
7384d4
2.39.1
7384d4
7384d4
7384d4
From 643384caf11050a1e8d694176a6e09d732461975 Mon Sep 17 00:00:00 2001
7384d4
From: Debarshi Ray <rishi@fedoraproject.org>
7384d4
Date: Sun, 29 Jan 2023 09:41:16 +0100
7384d4
Subject: [PATCH 2/3] pkg/utils: Be more strict about what is acceptable
7384d4
7384d4
https://github.com/containers/toolbox/issues/1065
7384d4
(cherry picked from commit 262c90e06fdb91e0b693fae33a519eb2756de75b)
7384d4
---
7384d4
 src/pkg/utils/utils.go | 15 ++++++++++++++-
7384d4
 1 file changed, 14 insertions(+), 1 deletion(-)
7384d4
7384d4
diff --git a/src/pkg/utils/utils.go b/src/pkg/utils/utils.go
7384d4
index 3119fee74375..b4c012e8fe3a 100644
7384d4
--- a/src/pkg/utils/utils.go
7384d4
+++ b/src/pkg/utils/utils.go
7384d4
@@ -1,5 +1,5 @@
7384d4
 /*
7384d4
- * Copyright © 2019 – 2021 Red Hat Inc.
7384d4
+ * Copyright © 2019 – 2023 Red Hat Inc.
7384d4
  *
7384d4
  * Licensed under the Apache License, Version 2.0 (the "License");
7384d4
  * you may not use this file except in compliance with the License.
7384d4
@@ -278,6 +278,19 @@ func GetEnvOptionsForPreservedVariables() []string {
7384d4
 func GetFullyQualifiedImageFromDistros(image, release string) (string, error) {
7384d4
 	logrus.Debugf("Resolving fully qualified name for image %s from known registries", image)
7384d4
 
7384d4
+	if image == "" {
7384d4
+		panic("image not specified")
7384d4
+	}
7384d4
+
7384d4
+	if release == "" {
7384d4
+		panic("release not specified")
7384d4
+	}
7384d4
+
7384d4
+	if tag := ImageReferenceGetTag(image); tag != "" && release != tag {
7384d4
+		panicMsg := fmt.Sprintf("image %s does not match release %s", image, release)
7384d4
+		panic(panicMsg)
7384d4
+	}
7384d4
+
7384d4
 	if ImageReferenceHasDomain(image) {
7384d4
 		return image, nil
7384d4
 	}
7384d4
-- 
7384d4
2.39.1
7384d4
7384d4
7384d4
From 1ce213fabb3321937421404350e57f376cb9134d Mon Sep 17 00:00:00 2001
7384d4
From: Debarshi Ray <rishi@fedoraproject.org>
7384d4
Date: Sun, 29 Jan 2023 09:47:13 +0100
7384d4
Subject: [PATCH 3/3] pkg/utils: Support RHEL 9 Toolbx containers
7384d4
7384d4
The URLs for the RHEL Toolbx images based on the Red Hat Universal Base
7384d4
Images (or UBI) are a bit more complicated to construct, in comparison
7384d4
to the URLs for Fedora's fedora-toolbox images.  It's not enough to just
7384d4
concatenate the registry, the image's basename and the release.  Some
7384d4
parts of the URL depend on the release's major number, which requires
7384d4
custom code.
7384d4
7384d4
So far, the release's major number was hard coded to 8 since only RHEL 8
7384d4
Toolbx containers were supported.
7384d4
7384d4
To support other RHEL major releases, it's necessary to have custom code
7384d4
to construct the URLs for the Toolbx images.
7384d4
7384d4
https://github.com/containers/toolbox/issues/1065
7384d4
(cherry picked from commit 0a29b374e649437126d8bbe12707fb44d20073d3)
7384d4
---
7384d4
 src/pkg/utils/utils.go | 47 +++++++++++++++++++++---------------------
7384d4
 1 file changed, 23 insertions(+), 24 deletions(-)
7384d4
7384d4
diff --git a/src/pkg/utils/utils.go b/src/pkg/utils/utils.go
7384d4
index b4c012e8fe3a..4e4abeca4817 100644
7384d4
--- a/src/pkg/utils/utils.go
7384d4
+++ b/src/pkg/utils/utils.go
7384d4
@@ -38,15 +38,14 @@ import (
7384d4
 	"golang.org/x/sys/unix"
7384d4
 )
7384d4
 
7384d4
+type GetFullyQualifiedImageFunc func(string, string) string
7384d4
 type ParseReleaseFunc func(string) (string, error)
7384d4
 
7384d4
 type Distro struct {
7384d4
 	ContainerNamePrefix    string
7384d4
 	ImageBasename          string
7384d4
+	GetFullyQualifiedImage GetFullyQualifiedImageFunc
7384d4
 	ParseRelease           ParseReleaseFunc
7384d4
-	Registry               string
7384d4
-	Repository             string
7384d4
-	RepositoryNeedsRelease bool
7384d4
 }
7384d4
 
7384d4
 const (
7384d4
@@ -97,18 +96,14 @@ var (
7384d4
 		"fedora": {
7384d4
 			"fedora-toolbox",
7384d4
 			"fedora-toolbox",
7384d4
+			getFullyQualifiedImageFedora,
7384d4
 			parseReleaseFedora,
7384d4
-			"registry.fedoraproject.org",
7384d4
-			"",
7384d4
-			false,
7384d4
 		},
7384d4
 		"rhel": {
7384d4
 			"rhel-toolbox",
7384d4
 			"toolbox",
7384d4
+			getFullyQualifiedImageRHEL,
7384d4
 			parseReleaseRHEL,
7384d4
-			"registry.access.redhat.com",
7384d4
-			"ubi8",
7384d4
-			false,
7384d4
 		},
7384d4
 	}
7384d4
 )
7384d4
@@ -305,21 +300,8 @@ func GetFullyQualifiedImageFromDistros(image, release string) (string, error) {
7384d4
 			continue
7384d4
 		}
7384d4
 
7384d4
-		var repository string
7384d4
-
7384d4
-		if distroObj.RepositoryNeedsRelease {
7384d4
-			repository = fmt.Sprintf(distroObj.Repository, release)
7384d4
-		} else {
7384d4
-			repository = distroObj.Repository
7384d4
-		}
7384d4
-
7384d4
-		imageFull := distroObj.Registry
7384d4
-
7384d4
-		if repository != "" {
7384d4
-			imageFull = imageFull + "/" + repository
7384d4
-		}
7384d4
-
7384d4
-		imageFull = imageFull + "/" + image
7384d4
+		getFullyQualifiedImageImpl := distroObj.GetFullyQualifiedImage
7384d4
+		imageFull := getFullyQualifiedImageImpl(image, release)
7384d4
 
7384d4
 		logrus.Debugf("Resolved image %s to %s", image, imageFull)
7384d4
 
7384d4
@@ -329,6 +311,23 @@ func GetFullyQualifiedImageFromDistros(image, release string) (string, error) {
7384d4
 	return "", fmt.Errorf("failed to resolve image %s", image)
7384d4
 }
7384d4
 
7384d4
+func getFullyQualifiedImageFedora(image, release string) string {
7384d4
+	imageFull := "registry.fedoraproject.org/" + image
7384d4
+	return imageFull
7384d4
+}
7384d4
+
7384d4
+func getFullyQualifiedImageRHEL(image, release string) string {
7384d4
+	i := strings.IndexRune(release, '.')
7384d4
+	if i == -1 {
7384d4
+		panicMsg := fmt.Sprintf("release %s not in '<major>.<minor>' format", release)
7384d4
+		panic(panicMsg)
7384d4
+	}
7384d4
+
7384d4
+	releaseMajor := release[:i]
7384d4
+	imageFull := "registry.access.redhat.com/ubi" + releaseMajor + "/" + image
7384d4
+	return imageFull
7384d4
+}
7384d4
+
7384d4
 // GetGroupForSudo returns the name of the sudoers group.
7384d4
 //
7384d4
 // Some distros call it 'sudo' (eg. Ubuntu) and some call it 'wheel' (eg. Fedora).
7384d4
-- 
7384d4
2.39.1
7384d4