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