Skip to content
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

OCPBUGS-25482: Adding PER check for BYO workspace on PowerVS #7841

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/asset/installconfig/powervs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/IBM-Cloud/bluemix-go/crn"
"github.com/IBM-Cloud/power-go-client/power/client/datacenters"
"github.com/IBM-Cloud/power-go-client/power/client/workspaces"
"github.com/IBM/go-sdk-core/v5/core"
"github.com/IBM/networking-go-sdk/dnsrecordsv1"
"github.com/IBM/networking-go-sdk/dnssvcsv1"
Expand Down Expand Up @@ -44,6 +45,7 @@ type API interface {
ListServiceInstances(ctx context.Context) ([]string, error)
ServiceInstanceGUIDToName(ctx context.Context, id string) (string, error)
GetDatacenterCapabilities(ctx context.Context, region string) (map[string]bool, error)
GetWorkspaceCapabilities(ctx context.Context, svcInsID string) (map[string]bool, error)
GetAttachedTransitGateway(ctx context.Context, svcInsID string) (string, error)
GetTGConnectionVPC(ctx context.Context, gatewayID string, vpcSubnetID string) (string, error)
}
Expand Down Expand Up @@ -782,6 +784,16 @@ func (c *Client) GetDatacenterCapabilities(ctx context.Context, region string) (
return getOk.Payload.Capabilities, nil
}

// GetWorkspaceCapabilities retrieves the capabilities of the specified workspace.
func (c *Client) GetWorkspaceCapabilities(ctx context.Context, svcInsID string) (map[string]bool, error) {
params := workspaces.NewV1WorkspacesGetParamsWithContext(ctx).WithWorkspaceID(svcInsID)
getOk, err := c.BXCli.PISession.Power.Workspaces.V1WorkspacesGet(params, c.BXCli.PISession.AuthInfo(svcInsID))
if err != nil {
return nil, fmt.Errorf("failed to get workspace capabilities: %w", err)
}
return getOk.Payload.Capabilities, nil
}

// GetAttachedTransitGateway finds an existing Transit Gateway attached to the provided PowerVS cloud instance.
func (c *Client) GetAttachedTransitGateway(ctx context.Context, svcInsID string) (string, error) {
var (
Expand Down
15 changes: 15 additions & 0 deletions pkg/asset/installconfig/powervs/mock/powervsclient_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion pkg/asset/installconfig/powervs/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func validateMachinePool(fldPath *field.Path, machinePool *types.MachinePool) fi
return allErrs
}

// ValidatePERAvailability ensures the target datacenter has PER enabled.
// ValidatePERAvailability ensures the target datacenter has PER enabled, and in BYO workspace case, the workspace also has PER available.
func ValidatePERAvailability(client API, ic *types.InstallConfig) error {
capabilities, err := client.GetDatacenterCapabilities(context.TODO(), ic.PowerVS.Zone)
if err != nil {
Expand All @@ -64,6 +64,17 @@ func ValidatePERAvailability(client API, ic *types.InstallConfig) error {
return fmt.Errorf("%s is not available at: %s", per, ic.PowerVS.Zone)
}

svcInsID := ic.PowerVS.ServiceInstanceGUID
if svcInsID != "" {
capabilities, err = client.GetWorkspaceCapabilities(context.TODO(), svcInsID)
if err != nil {
return err
}
if !capabilities[per] {
return fmt.Errorf("%s is not available in workspace: %s", per, svcInsID)
}
}

return nil
}

Expand Down
34 changes: 32 additions & 2 deletions pkg/asset/installconfig/powervs/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ var (
newSysType = "s1022"
invalidRegion = "foo"
validServiceInstanceGUID = ""
bogusServiceInstanceGUID = "bogus-workspace-guid"
validByoWorkspaceGUID = "valid-workspace-guid"
)

func validInstallConfig() *types.InstallConfig {
Expand Down Expand Up @@ -509,7 +511,7 @@ func TestValidatePERAvailability(t *testing.T) {
errorMsg: fmt.Sprintf("power-edge-router is not available at: %s", regionWithoutPER),
},
{
name: "Region with PER",
name: "Region with PER and no BYO Workspace",
edits: editFunctions{
func(ic *types.InstallConfig) {
ic.Platform.PowerVS.Zone = regionWithPER
Expand All @@ -526,6 +528,26 @@ func TestValidatePERAvailability(t *testing.T) {
},
errorMsg: fmt.Sprintf("power-edge-router capability unknown at: %s", regionPERUnknown),
},
{
name: "Region with PER, but with invalid Workspace ID",
edits: editFunctions{
func(ic *types.InstallConfig) {
ic.Platform.PowerVS.Zone = regionWithPER
ic.Platform.PowerVS.ServiceInstanceGUID = bogusServiceInstanceGUID
},
},
errorMsg: fmt.Sprintf("power-edge-router is not available in workspace: %s", bogusServiceInstanceGUID),
},
{
name: "Region with PER and valid BYO Workspace",
edits: editFunctions{
func(ic *types.InstallConfig) {
ic.Platform.PowerVS.Zone = regionWithPER
ic.Platform.PowerVS.ServiceInstanceGUID = validByoWorkspaceGUID
},
},
errorMsg: "",
},
}
setMockEnvVars()

Expand All @@ -537,12 +559,20 @@ func TestValidatePERAvailability(t *testing.T) {
// Mocks: PER-absent region results in false
powervsClient.EXPECT().GetDatacenterCapabilities(gomock.Any(), regionWithoutPER).Return(mapWithPERFalse, nil)

// Mocks: PER-enabled region results in true
// Mocks: PER-enabled region with no BYO workspace results in true
powervsClient.EXPECT().GetDatacenterCapabilities(gomock.Any(), regionWithPER).Return(mapWithPERTrue, nil)

// Mocks: PER-unknown region results in false
powervsClient.EXPECT().GetDatacenterCapabilities(gomock.Any(), regionPERUnknown).Return(mapPERUnknown, nil)

// Mocks: PER-enabled region, but bogus Service Instance results in false
powervsClient.EXPECT().GetDatacenterCapabilities(gomock.Any(), regionWithPER).Return(mapWithPERTrue, nil)
powervsClient.EXPECT().GetWorkspaceCapabilities(gomock.Any(), bogusServiceInstanceGUID).Return(mapWithPERFalse, nil)

// Mocks: PER-enabled region with valid BYO workspace results in false
powervsClient.EXPECT().GetDatacenterCapabilities(gomock.Any(), regionWithPER).Return(mapWithPERTrue, nil)
powervsClient.EXPECT().GetWorkspaceCapabilities(gomock.Any(), validByoWorkspaceGUID).Return(mapWithPERTrue, nil)

// Run tests
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
Expand Down