Skip to content

Add IPv6 support for IPAddressAllocation CRD and NSX payload#1436

Open
poojav25 wants to merge 3 commits into
vmware-tanzu:mainfrom
poojav25:ipallocation
Open

Add IPv6 support for IPAddressAllocation CRD and NSX payload#1436
poojav25 wants to merge 3 commits into
vmware-tanzu:mainfrom
poojav25:ipallocation

Conversation

@poojav25
Copy link
Copy Markdown

@poojav25 poojav25 commented May 18, 2026

Add ipAddressType (IPv4/IPv6) and ipv6AllocationPrefixLength handling

  • Map CRD enum values to NSX SDK values and populate NSX IpAddressType
    and Ipv6AllocationPrefixLength on the VpcIpAddressAllocation payload
  • Add ipAddressType field (IPv4/IPv6, default IPv4) and
    ipv6AllocationPrefixLength field (range 64–128) to IPAddressAllocationSpec
  • Disallow ipAddressBlockVisibility when ipAddressType=IPv6 via CRD XValidation
  • Disallow allocationSize when ipAddressType=IPv6 via CRD XValidation
  • Disallow ipv6AllocationPrefixLength when ipAddressType=IPv4 via CRD XValidation
  • ipAddressType and ipv6AllocationPrefixLength are immutable once set
  • Omit IpAddressBlockVisibility for IPv6 payloads in builder; keep IPv4
    default behavior unchanged
  • Default ipv6AllocationPrefixLength to 64 in builder when field is omitted
  • Update compare logic to include IpAddressType and Ipv6AllocationPrefixLength
  • Update webhook to reflect new field constraints
  • Add/adjust unit tests and stabilize store initialization stubs

Fixes: RBAC marker plural form on SubnetIPReservation controller

Testing done:

-> Create IPv4 Private allocation (regression check)

apiVersion: crd.nsx.vmware.com/v1alpha1
kind: IPAddressAllocation
metadata:
  name: test-ipv4-private
  namespace: svc-tkg-38ilo
spec:
  ipAddressBlockVisibility: Private
  allocationSize: 16
  ipAddressType: IPv4

Result: ALLOCATIONIPS=172.26.0.0/28. IPv4 path unaffected by IPv6 changes.

-> Create IPv6 allocation with explicit prefix length

apiVersion: crd.nsx.vmware.com/v1alpha1
kind: IPAddressAllocation
metadata:
  name: test-ipv6-prefix64
  namespace: test-ipv6-ns
spec:
  ipAddressType: IPv6
  ipv6AllocationPrefixLength: 64

Result: ALLOCATIONIPS=2001:db8::/64, IPV6ALLOCATIONPREFIXLENGTH=64. NSX allocated a /64 from the 2001:db8::/48 external IPv6 block.

-> Create IPv6 allocation with omitted prefix (default /64 via builder)

apiVersion: crd.nsx.vmware.com/v1alpha1
kind: IPAddressAllocation
metadata:
  name: test-ipv6-default-prefix
  namespace: test-ipv6-ns
spec:
  ipAddressType: IPv6

Result: ALLOCATIONIPS=2001:db8:0:1::/64. Builder defaulted to 64 when field was omitted; NSX allocated the next /64 from the block.

-> Deny: IPv6 + ipAddressBlockVisibility (CEL validation)

apiVersion: crd.nsx.vmware.com/v1alpha1
kind: IPAddressAllocation
metadata:
  name: test-invalid-ipv6-visibility
  namespace: test-ipv6-ns
spec:
  ipAddressType: IPv6
  ipv6AllocationPrefixLength: 64
  ipAddressBlockVisibility: Private

Result: API server rejected with ipAddressBlockVisibility cannot be set when ipAddressType is IPv6. No NSX call made.

-> Deny: IPv6 + allocationSize (CEL validation)

apiVersion: crd.nsx.vmware.com/v1alpha1
kind: IPAddressAllocation
metadata:
  name: test-invalid-ipv6-size
  namespace: test-ipv6-ns
spec:
  ipAddressType: IPv6
  allocationSize: 16

Result: API server rejected with allocationSize can only be set when ipAddressType is IPv4.

-> Deny: allocationSize + allocationIPs together (CEL validation)

apiVersion: crd.nsx.vmware.com/v1alpha1
kind: IPAddressAllocation
metadata:
  name: test-both-invalid
  namespace: test-ipv6-ns
spec:
  ipAddressType: IPv4
  allocationSize: 16
  allocationIPs: "10.0.0.0/28"

Result: API server rejected with Only one of allocationSize or allocationIPs can be specified.

-> Deny: ipAddressType immutability

# Create with IPv4 then attempt patch to IPv6
kubectl patch ipaddressallocation test-immutable -n test-ipv6-ns \
  --type=merge -p '{"spec":{"ipAddressType":"IPv6"}}'

Result: Rejected with spec.ipAddressType: Invalid value: "IPv6": Value is immutable.

@dantingl
Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

poojav25 added 2 commits May 19, 2026 15:29
…name

Kubernetes RBAC rules require the plural form of the resource name.
The marker used "subnetipreservation" (singular) which would generate
broken ClusterRole rules. Changed to "subnetipreservations" to match
the CRD plural name and align with all other controllers in the codebase.
…fixLength

Removing +kubebuilder:default=64 from IPv6AllocationPrefixLength prevents
the API server from injecting the value for IPv4 allocations, which caused
the CEL rule "ipv6AllocationPrefixLength can only be set when ipAddressType
is IPv6" to reject all IPv4 IPAddressAllocation objects.
The default of 64 is moved into the builder so IPv6 allocations that omit
the field still get a /64 sent to NSX, preserving the original intent.
@poojav25 poojav25 changed the title [WIP] Add IPv6 support for IPAddressAllocation CRD and NSX payload Add IPv6 support for IPAddressAllocation CRD and NSX payload May 19, 2026
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