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