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

Update subnet CIDRs when reconciling existing vnet #2339

Merged

Conversation

CecileRobertMichon
Copy link
Contributor

What type of PR is this?
/kind bug

What this PR does / why we need it: This fixes an edge case scenario where the user specifies an existing BYO vnet along with subnets without specifying CIDR ranges. CAPZ will fill out the details in the controller when doing a GET of the existing vnet/subnet. However, in the case that the controller returns in between those reconciling the vnet and the subnets, which it often does as we reconcile resources async, it will attempt to patch the object with the updated vnet CIDR but the wrong defaulted subnet CIDRs, which results in a validation error similar to: "validation.azurecluster.infrastructure.cluster.x-k8s.io" denied the request: AzureCluster.infrastructure.cluster.x-k8s.io "efreed-workload1" is invalid: [spec.networkSpec.subnets[0].cidrBlocks: Invalid value: "10.0.0.0/16": subnet CIDR not in vnet address space: [10.22.128.0/22], .

This updates the reconciler code to update both vnet and subnet CIDR ranges together when an existing VNet with subnets matching the defined subnet names is found.

Thanks @evanfreed for reporting the issue.

slack thread: https://kubernetes.slack.com/archives/CEX9HENG7/p1653600096205839

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests

Release note:

Update subnet CIDRs when reconciling existing vnet

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 27, 2022
@k8s-ci-robot k8s-ci-robot requested review from Jont828 and mboersma May 27, 2022 22:41
@CecileRobertMichon
Copy link
Contributor Author

/hold for confirmation from @evanfreed that this fixes the issue

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 27, 2022
@evanfreed
Copy link
Contributor

@CecileRobertMichon I can confirm your fix seems to work!

Example spec used

apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: AzureCluster
metadata:
  name: ${CLUSTER_NAME}
  namespace: default
spec:
  location: ${AZURE_LOCATION}
  networkSpec:
    vnet:
      resourceGroup: ${AZURE_RESOURCE_GROUP}
      name: ${AZURE_VNET_NAME}
    subnets:
      - name: control_plane
        role: control-plane
        #cidrBlocks:
          #- 10.22.128.128/25
      - name: worker_nodes
        role: node
        #cidrBlocks:
          #- 10.22.130.0/23
  resourceGroup: ${AZURE_RESOURCE_GROUP}

The machine provisioned in the pre-created CIDR range that we self manage without needing to define it in the spec 🎉 thanks for the help!

/lgtm

@k8s-ci-robot
Copy link
Contributor

@evanfreed: changing LGTM is restricted to collaborators

In response to this:

@CecileRobertMichon I can confirm your fix seems to work!

Example spec used

apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: AzureCluster
metadata:
 name: ${CLUSTER_NAME}
 namespace: default
spec:
 location: ${AZURE_LOCATION}
 networkSpec:
   vnet:
     resourceGroup: ${AZURE_RESOURCE_GROUP}
     name: ${AZURE_VNET_NAME}
   subnets:
     - name: control_plane
       role: control-plane
       #cidrBlocks:
         #- 10.22.128.128/25
     - name: worker_nodes
       role: node
       #cidrBlocks:
         #- 10.22.130.0/23
 resourceGroup: ${AZURE_RESOURCE_GROUP}

The machine provisioned in the pre-created CIDR range that we self manage without needing to define it in the spec 🎉 thanks for the help!

/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@jackfrancis
Copy link
Contributor

/retest

@jackfrancis
Copy link
Contributor

wow gfmt is picky

image

Copy link
Contributor

@jackfrancis jackfrancis left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 31, 2022
@jackfrancis
Copy link
Contributor

/assign @mboersma

for final review and approval/merge

@CecileRobertMichon
Copy link
Contributor Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 31, 2022
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 2, 2022
@CecileRobertMichon
Copy link
Contributor Author

2022-06-02T15:30:11.515802566Z stderr F E0602 15:30:11.515601 1 controller.go:317] controller/azuremachine "msg"="Reconciler error" "error"="failed to reconcile AzureMachine: failed to reconcile AzureMachine service virtualmachine: failed checking if the operation was complete: failed checking if the operation was complete: Code="ZonalAllocationFailed" Message="Allocation failed. We do not have sufficient capacity for the requested VM size in this zone. Read more about improving likelihood of allocation success at http://aka.ms/allocation-guidance\"" "name"="capz-pbacet-control-plane-dljw7" "namespace"="default" "reconciler group"="infrastructure.cluster.x-k8s.io" "reconciler kind"="AzureMachine"

/retest

@CecileRobertMichon
Copy link
Contributor Author

/retest

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jun 2, 2022

@CecileRobertMichon: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-provider-azure-apidiff 29c9dc5 link false /test pull-cluster-api-provider-azure-apidiff

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@Jont828
Copy link
Contributor

Jont828 commented Jun 2, 2022

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 2, 2022
@CecileRobertMichon
Copy link
Contributor Author

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CecileRobertMichon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 2, 2022
@k8s-ci-robot k8s-ci-robot merged commit 9e793b4 into kubernetes-sigs:main Jun 2, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.4 milestone Jun 2, 2022
@CecileRobertMichon CecileRobertMichon deleted the subnets-cidrs branch February 17, 2023 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants