From 2da86df7ecfc4ecff0478232f44698f4e6c0337d Mon Sep 17 00:00:00 2001 From: Paul Maidment Date: Sun, 5 May 2024 18:59:32 +0300 Subject: [PATCH] MGMT-16242: Enumerate valid release images in error message to user. It is desired that we should be able to see a list of valid image URLs in the error message in the AgentClusterInstall when a release image could not be located. This PR addresses that by enumerating the URLs in the message. --- internal/versions/common.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/versions/common.go b/internal/versions/common.go index bfa3e1725a0..56fc314f47e 100644 --- a/internal/versions/common.go +++ b/internal/versions/common.go @@ -4,6 +4,7 @@ import ( context "context" "encoding/json" "fmt" + "strings" "sync" "github.com/go-openapi/strfmt" @@ -128,7 +129,7 @@ func validateReleaseImageForRHCOS( ) error { // Multi is not a valid RHCOS CPU architecture, its sub-architectures are if cpuArchitecture == common.MultiCPUArchitecture { - return errors.Errorf("The requested RHCOS version (%s, arch: %s) does not have a matching OpenShift release image", rhcosVersion, cpuArchitecture) + return errors.Errorf("The requested RHCOS version (%s, arch: %s) does not have a matching OpenShift release image, %s is not a valid architecture", rhcosVersion, cpuArchitecture, common.MultiCPUArchitecture) } rhcosVersionPtr, err := common.GetMajorMinorVersion(rhcosVersion) @@ -141,6 +142,8 @@ func validateReleaseImageForRHCOS( cpuArchitecture = common.DefaultCPUArchitecture } + uniqueRHCOSVersions := map[string]bool{} + rhcosVersionSummary := "" for _, releaseImage := range releaseImages { minorVersion, err := common.GetMajorMinorVersion(*releaseImage.OpenshiftVersion) if err != nil { @@ -158,11 +161,16 @@ func validateReleaseImageForRHCOS( log.Debugf("Validator for the architecture %s found the following OCP version: %s", cpuArchitecture, *releaseImage.Version) return nil } + // Build up a unique list of qualifying Openshift versions for the architecture so that we may return a summary. + if _, ok := uniqueRHCOSVersions[*minorVersion]; !ok { + rhcosVersionSummary += fmt.Sprintf("%s%s\n", rhcosVersionSummary, *minorVersion) + uniqueRHCOSVersions[*minorVersion] = true + } } } } - return errors.Errorf("The requested RHCOS version (%s, arch: %s) does not have a matching OpenShift release image", *rhcosVersionPtr, cpuArchitecture) + return errors.Errorf("The requested RHCOS version (%s, arch: %s) does not have a matching OpenShift release image\nUse one of the following Openshift versions for your architecture:\n%s", *rhcosVersionPtr, cpuArchitecture, rhcosVersionSummary) } func AddReleaseImagesToDBIfNeeded(