Skip to content
Open
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
2 changes: 2 additions & 0 deletions pkg/asset/manifests/cloudproviderconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ func (cpc *CloudProviderConfig) Generate(ctx context.Context, dependencies asset
vpcExists = true
} else if vpc, err = client.GetVPCByName(ctx, vpcNameOrID); err == nil {
vpcExists = true
} else {
return err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only ever return the error from the else-if directly above. This may take some reworking to get this to where the functionality is correct.

if vpcNameOrID == "" {
	vpcNameOrID = fmt.Sprintf("vpc-%s", clusterID.InfraID)
} else {
    if vpc, err = client.GetVPCByID(ctx, vpcNameOrID, vpcRegion); err == nil {
			vpcNameOrID = *vpc.Name
			vpcExists = true
	} else {
            return err << maybe want to override or add to the error here with fmt.Errorf
    }

    if vpc, err = client.GetVPCByName(ctx, vpcNameOrID); err == nil {
			vpcExists = true
	} else {
            return err << add to error for more info with fmt.Errorf
    }
} 

Logically it could be something like that but there is probably a cleaner way of doing this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetVPCByID() errors out if there's no VPC with an ID with the value in vpcNameOrID. But vpcNameOrID could be the VPC's name so we can't exit out if GetVPCByID() returns an error since we need to check whether vpcNameOrID is a valid, existing VPC's name. And if GetVPCByName() fails too, I think it's fine to cascade the error returned by GetVPCByName() which is "failed to find VPC vpcNameOrID. Available VPCs: list of available VPC names in the resource group".
Hopefully that makes sense. Please let me know if it's still a concern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Make sense to me. I guess we can further refactor (if you'd like later on) this chain of if into a function like GetVPCByIDOrName as the same chain is being used in other places.

}

vpcSubnets := installConfig.Config.PowerVS.VPCSubnets
Expand Down