openshift / machine-api-provider-ibmcloud

Apache License 2.0
0 stars 12 forks source link

Error When Using MAPI on a VPC With Greater Than 50 Subnets #39

Open jmkanz opened 1 month ago

jmkanz commented 1 month ago

ISSUE:

Currently, the IBM Cloud VPC API sets a default to return only 50 subnets per page on an API call if an option is not set on the API call to return more. However, a single VPC can have up to a maximum of 100 subnets.

If a user configures their machine provider config to look for a subnet that is greater than 50 in the returned list, the MAPI will return an error since it's using the default value of 50 provided by the VPC API.

POSSIBLE SOLUTIONS:

  1. When using the IBM Cloud VPC API to return a subnet list, set the default limit to 100 so that all possible subnets are returned for the VPC. Such as: subnetOption.SetLimit=100 https://cloud.ibm.com/apidocs/vpc/latest#list-subnets

  2. Support pagination if we choose to only return 50 results with the default setting

Additional Information: Here is the code where I believe we could set subnetOption.SetLimit=100 to return the full result. This is also the code where the error is thrown if a subnet name provided in the machine provider config is over 50 in the returned list:

func (c *ibmCloudClient) GetSubnetIDbyName(subnetName string, resourceGroupID string) (string, error) {
    // Initialize List Subnets Options
    subnetOption := c.vpcService.NewListSubnetsOptions()

    // Set Resource Group ID
    subnetOption.SetResourceGroupID(resourceGroupID)

    // Set Limit to 100, ibmcloud limits 100 subnets per vpc <======.  add these 2 lines is my guess
    subnetOption.SetLimit(100)

    // Get a list of all subnets
    subnetList, _, err := c.vpcService.ListSubnets(subnetOption)
    if err != nil {
        return "", err
    }

    if subnetList != nil {
        for _, eachSubnet := range subnetList.Subnets {
            if *eachSubnet.Name == subnetName {
                // Return Subnet ID
                return *eachSubnet.ID, nil
            }
        }
    }
    return "", fmt.Errorf("could not retrieve subnet id of name: %v", subnetName)
}

Link: https://github.com/openshift/machine-api-provider-ibmcloud/blob/8c9ac909b36e619d75f59b073b4b056e5270ec54/pkg/actuators/client/client.go#L531

cjschaef commented 1 month ago

Thanks for the details, I will see about getting a Openshift Jira bug open to resolve this issue.

cjschaef commented 1 month ago

Jira has been opened to track and resolve this issue. https://issues.redhat.com/browse/OCPBUGS-36185

I think this issue can be closed (cannot do so myself) in favor of the Jira.