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