-
Notifications
You must be signed in to change notification settings - Fork 1.5k
MULTIARCH-6014: PowerVS: Use PowerVS Stock Catalogue Images #10647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package powervs | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/IBM-Cloud/power-go-client/clients/instance" | ||
| "github.com/IBM-Cloud/power-go-client/ibmpisession" | ||
| "github.com/IBM/go-sdk-core/v5/core" | ||
| "github.com/sirupsen/logrus" | ||
|
|
||
| powervsconfig "github.com/openshift/installer/pkg/asset/installconfig/powervs" | ||
| ) | ||
|
|
||
| // GetBootImageFromWorkspace retrieves a boot image from the PowerVS workspace. | ||
| // If an active image is found in the workspace, it returns that image name. | ||
| // If no images are found, it returns a default name in the format "rhcos-{clusterID}". | ||
| func GetBootImageFromWorkspace(ctx context.Context, serviceInstanceGUID string, zone string, clusterID string) (string, error) { | ||
| // Create a new PowerVS client | ||
| client, err := powervsconfig.NewClient() | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to create PowerVS client: %w", err) | ||
| } | ||
|
|
||
| // Create authenticator | ||
| authenticator := &core.IamAuthenticator{ | ||
| ApiKey: client.GetAPIKey(), | ||
| } | ||
|
|
||
| // Create PI session | ||
| piSession, err := ibmpisession.NewIBMPISession(&ibmpisession.IBMPIOptions{ | ||
| Authenticator: authenticator, | ||
| UserAccount: client.BXCli.User.Account, | ||
| Zone: zone, | ||
| Debug: false, | ||
| }) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to create PowerVS session: %w", err) | ||
| } | ||
|
|
||
| // Create image client | ||
| imageClient := instance.NewIBMPIImageClient(ctx, piSession, serviceInstanceGUID) | ||
| if imageClient == nil { | ||
| return "", fmt.Errorf("failed to create PowerVS image client") | ||
| } | ||
|
|
||
| // Get all images from the workspace | ||
| images, err := imageClient.GetAll() | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to list images from PowerVS workspace: %w", err) | ||
| } | ||
|
|
||
| // If no images found in workspace, use default naming pattern | ||
| if images == nil || len(images.Images) == 0 { | ||
| defaultImage := fmt.Sprintf("rhcos-%s", clusterID) | ||
| logrus.Infof("No images found in PowerVS workspace, using default image name: %s", defaultImage) | ||
| return defaultImage, nil | ||
| } | ||
|
|
||
| // Find the first active image | ||
| for _, image := range images.Images { | ||
| if image.State != nil && *image.State == "active" && image.Name != nil { | ||
| logrus.Infof("Selected PowerVS boot image from workspace: %s", *image.Name) | ||
| return *image.Name, nil | ||
| } | ||
|
Comment on lines
+61
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Selection predicate is too broad for boot image resolution. At Line 61-64, the code returns the first active image regardless of OS/image intent. In workspaces with multiple active images, this can pick a non-RHCOS image and break node boot compatibility. Filter explicitly for the expected RHCOS image naming/metadata and require non-empty names. 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| // If no active images found, use default naming pattern | ||
| defaultImage := fmt.Sprintf("rhcos-%s", clusterID) | ||
| logrus.Infof("No active images found in PowerVS workspace, using default image name: %s", defaultImage) | ||
| return defaultImage, nil | ||
| } | ||
|
AshwinHIBM marked this conversation as resolved.
|
||
|
|
||
| // Made with Bob | ||
Uh oh!
There was an error while loading. Please reload this page.