kubernetes-sigs / cluster-api-provider-ibmcloud

Cluster API Provider for IBM Cloud
https://cluster-api-ibmcloud.sigs.k8s.io
Apache License 2.0
62 stars 79 forks source link

Multiple subnet creation fails when zone is not specified #1779

Open Amulyam24 opened 4 months ago

Amulyam24 commented 4 months ago

/kind bug /area provider/ibmcloud

What steps did you take and what happened: If zone it not specified while creating multiple subnets, second subnet creation will fail as the default address prefix is already assigned to the first subnet. Spec:

apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
kind: IBMPowerVSCluster
metadata:
  annotations:
    powervs.cluster.x-k8s.io/create-infra: "true"
  labels:
    cluster.x-k8s.io/cluster-name: capi-test-amulya
  name: capi-test-amulya
  namespace: default
spec:
  loadBalancers:
  - name: capi-test-amulya-loadbalancer
  - name: capi-test-amulya-loadbalancer-1
  resourceGroup:
    name: ibm-hypershift-dev
  serviceInstance:
    name: capi-test-amulya-serviceInstance
  transitGateway:
    name: capi-test-amulya-transitgateway
  vpc:
    name: capi-test-amulya-vpc
    region: eu-es
  vpcSubnets:
  - name: capi-test-amulya-vpcsubnet
  - name: capi-test-amulya-vpcsubnet-1
  zone: mad02

Creation fails with

"error creating vpc subnet" err="Subnet CIDR 10.251.0.0/18 conflicts with existing subnet: 02w7-c247a3e9-c9d0-4717-a878-96edd68059c4

What did you expect to happen: While creating multiple subnets, if subnet zone is missing from spec, don't proceed and instead throw an error.

Anything else you would like to add: We can add a check to validate the spec before proceeding with cluster creation.

Environment:

Amulyam24 commented 4 months ago

/good-first-issue

k8s-ci-robot commented 4 months ago

@Amulyam24: This request has been marked as suitable for new contributors.

Guidelines

Please ensure that the issue body includes answers to the following questions:

For more details on the requirements of such an issue, please see here and ensure that they are met.

If this request no longer meets these requirements, the label can be removed by commenting with the /remove-good-first-issue command.

In response to [this](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/issues/1779): >/good-first-issue Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
mkumatag commented 4 months ago

but how are we handling that for the first subnet when user didn't supply the zone?

While creating multiple subnets, if subnet zone is missing from spec, don't proceed and instead throw an error.

Amulyam24 commented 4 months ago

but how are we handling that for the first subnet when user didn't supply the zone?

While creating multiple subnets, if subnet zone is missing from spec, don't proceed and instead throw an error.

We are fetching the zone from PowerVS zone - https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/cloud/scope/powervs_cluster.go#L1113-L1130

Shilpa-Gokul commented 4 months ago

@Amulyam24 I would like to work on this issue

Shilpa-Gokul commented 4 months ago

/assign @Shilpa-Gokul

mkumatag commented 4 months ago

but how are we handling that for the first subnet when user didn't supply the zone?

While creating multiple subnets, if subnet zone is missing from spec, don't proceed and instead throw an error.

We are fetching the zone from PowerVS zone - https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/cloud/scope/powervs_cluster.go#L1113-L1130

There is logic written to use always the first one here -

// TODO(karthik-k-n): Decide on using all zones or using one zone
        if len(vpcZones) == 0 {
            return nil, fmt.Errorf("error getting vpc zones error: %v", err)
        }
        zone = vpcZones[0]

wondering if we need a logic to use the subsequent vpc zone for the next subnet?!

Amulyam24 commented 4 months ago

but how are we handling that for the first subnet when user didn't supply the zone?

While creating multiple subnets, if subnet zone is missing from spec, don't proceed and instead throw an error.

We are fetching the zone from PowerVS zone - https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/cloud/scope/powervs_cluster.go#L1113-L1130

There is logic written to use always the first one here -

// TODO(karthik-k-n): Decide on using all zones or using one zone
      if len(vpcZones) == 0 {
          return nil, fmt.Errorf("error getting vpc zones error: %v", err)
      }
      zone = vpcZones[0]

wondering if we need a logic to use the subsequent vpc zone for the next subnet?!

yes, we can try that out.

Karthik-K-N commented 2 weeks ago

We had a discussion regarding this issue and couple things decided are as follows

  1. Continue with existing flow when no subnets are set that is create subnet in each available zone for VPC.

  2. For selecting subnet CIDR, Use the field AddressPrefix.HasSubnets to identify whether to use the CIDR for subnet

    
    addressPrefixCollection, _, err := vpcService.ListVPCAddressPrefixes(options)

addressPrefixCollection.AddressPrefixes[].HasSubnets


3. For now allow only one subnet per VPC zone, If user specifies more subnets error out.
Karthik-K-N commented 1 week ago

Also we can avoid fetching CIDR and use total ip while creating subnet, For more reference see vpc subnet code and discussion