Skip to content

Commit

Permalink
MGMT-16242: Enumerate valid release images in error message to user.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
paul-maidment committed May 5, 2024
1 parent 75eedfc commit 2da86df
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/versions/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
context "context"
"encoding/json"
"fmt"
"strings"
"sync"

"github.com/go-openapi/strfmt"
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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(
Expand Down

0 comments on commit 2da86df

Please sign in to comment.