Skip to content

Support SubnetIPReservations with reservedIPs#1395

Open
yanjunz97 wants to merge 1 commit intovmware-tanzu:mainfrom
yanjunz97:static-ip-reservation
Open

Support SubnetIPReservations with reservedIPs#1395
yanjunz97 wants to merge 1 commit intovmware-tanzu:mainfrom
yanjunz97:static-ip-reservation

Conversation

@yanjunz97
Copy link
Contributor

This PR

  • adds a new field reservedIPs to SubnetIPReservation CRD, and supported with NSX Subnet StaticIPReservation
  • supports backup/restore for SubnetIPReservation

Testing done:

  • Created a SubnetIPReservation CR with single IP, IP ranges and IP CIDRs in reservedIPs, observed the NSX Subnet StaticIPReservation is realized and CR status is updated
kubectl get subnetipreservation -n ns-1 subnet-ipr-2 -o yaml
apiVersion: crd.nsx.vmware.com/v1alpha1
kind: SubnetIPReservation
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"crd.nsx.vmware.com/v1alpha1","kind":"SubnetIPReservation","metadata":{"annotations":{},"name":"subnet-ipr-2","namespace":"ns-1"},"spec":{"reservedIPs":["192.168.0.38","192.168.0.39-192.168.0.41","192.168.0.42/31"],"subnet":"subnet-1"}}
  creationTimestamp: "2026-03-17T04:24:46Z"
  generation: 2
  name: subnet-ipr-2
  namespace: ns-1
  resourceVersion: "3272641"
  uid: 3da62e70-e10c-4990-a09d-a9934c1d99d7
spec:
  reservedIPs:
  - 192.168.0.38
  - 192.168.0.39-192.168.0.41
  - 192.168.0.42/31
  subnet: subnet-1
status:
  conditions:
  - lastTransitionTime: "2026-03-17T04:24:47Z"
    message: NSX SubnetIPReservation has been successfully created/updated
    reason: SubnetIPReservationReady
    status: "True"
    type: Ready
  ips:
  - 192.168.0.38
  - 192.168.0.39-192.168.0.41
  - 192.168.0.42/31
  • Updated the SubnetIPReservation by changing reservedIPs also works
apiVersion: crd.nsx.vmware.com/v1alpha1
kind: SubnetIPReservation
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"crd.nsx.vmware.com/v1alpha1","kind":"SubnetIPReservation","metadata":{"annotations":{},"name":"subnet-ipr-2","namespace":"ns-1"},"spec":{"reservedIPs":["192.168.0.38","192.168.0.39","192.168.0.42/31"],"subnet":"subnet-1"}}
  creationTimestamp: "2026-03-17T04:24:46Z"
  generation: 3
  name: subnet-ipr-2
  namespace: ns-1
  resourceVersion: "3273091"
  uid: 3da62e70-e10c-4990-a09d-a9934c1d99d7
spec:
  reservedIPs:
  - 192.168.0.38
  - 192.168.0.39
  - 192.168.0.42/31
  subnet: subnet-1
status:
  conditions:
  - lastTransitionTime: "2026-03-17T04:24:47Z"
    message: NSX SubnetIPReservation has been successfully created/updated
    reason: SubnetIPReservationReady
    status: "True"
    type: Ready
  ips:
  - 192.168.0.38
  - 192.168.0.39
  - 192.168.0.42/31
  • Changed reservedIPs to numberOfIPs will be block
apiVersion: crd.nsx.vmware.com/v1alpha1
kind: SubnetIPReservation
metadata:
  name: subnet-ipr-2
spec:
  numberOfIPs: 3
  subnet: subnet-1

kubectl apply -f ipreservation.yaml -n ns-1
The SubnetIPReservation "subnet-ipr-2" is invalid: spec: Invalid value: "object": reservedIPs cannot be unset once set
  • Created a SubnetIPReservation CR with both numberOfIP and reservedIPs will be blocked
The SubnetIPReservation "subnet-ipr-2" is invalid: spec: Invalid value: "object": Only one of numberOfIPs or reservedIPs can be specified
  • Backup/Restore case: created a SubnetIPReservation with numberOfIPs and another with reservedIPs
kubectl get subnetipreservation -n ns-1                     
NAME           SUBNET     NUMBEROFIPS   IPS
subnet-ipr-1   subnet-1   3             192.168.0.35-192.168.0.37
subnet-ipr-2   subnet-1                 192.168.0.38

Stopped ncp, deleted the Subnet Dynamic/Static IPReservation from NSX side, forced ncp to restore mode, observed both SubnetIPReservations are restored with NSX Subnet Static IPReservation.

Signed-off-by: Yanjun Zhou <yanjun.zhou@broadcom.com>
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 77.25753% with 68 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.74%. Comparing base (1e42bf1) to head (87341a9).

Files with missing lines Patch % Lines
...ervices/subnetipreservation/subnetipreservation.go 70.19% 19 Missing and 12 partials ⚠️
pkg/nsx/services/common/wrap.go 0.00% 11 Missing ⚠️
pkg/nsx/services/subnetipreservation/cleanup.go 68.75% 7 Missing and 3 partials ⚠️
pkg/nsx/services/subnetipreservation/store.go 89.04% 6 Missing and 2 partials ⚠️
...netipreservation/subnetipreservation_controller.go 91.66% 1 Missing and 2 partials ⚠️
pkg/nsx/cluster.go 0.00% 3 Missing ⚠️
pkg/nsx/services/common/policy_tree.go 75.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1395      +/-   ##
==========================================
- Coverage   76.76%   76.74%   -0.02%     
==========================================
  Files         151      152       +1     
  Lines       21313    21556     +243     
==========================================
+ Hits        16360    16544     +184     
- Misses       3784     3826      +42     
- Partials     1169     1186      +17     
Flag Coverage Δ
unit-tests 76.74% <77.25%> (-0.02%) ⬇️
Files with missing lines Coverage Δ
pkg/nsx/client.go 94.95% <100.00%> (+0.04%) ⬆️
pkg/nsx/services/common/types.go 100.00% <ø> (ø)
pkg/nsx/services/subnetipreservation/builder.go 100.00% <100.00%> (ø)
pkg/nsx/services/subnetipreservation/compare.go 100.00% <100.00%> (ø)
pkg/nsx/services/common/policy_tree.go 86.23% <75.00%> (-0.22%) ⬇️
...netipreservation/subnetipreservation_controller.go 76.09% <91.66%> (+3.28%) ⬆️
pkg/nsx/cluster.go 59.02% <0.00%> (-0.52%) ⬇️
pkg/nsx/services/subnetipreservation/store.go 85.29% <89.04%> (+3.96%) ⬆️
pkg/nsx/services/subnetipreservation/cleanup.go 68.18% <68.75%> (-1.82%) ⬇️
pkg/nsx/services/common/wrap.go 75.51% <0.00%> (-3.55%) ⬇️
... and 1 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yanjunz97 yanjunz97 requested review from TaoZou1 and heypnus March 19, 2026 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants