Skip to content

EAS api implentation#1411

Open
seanpang-vmware wants to merge 1 commit into
vmware-tanzu:mainfrom
seanpang-vmware:topic/sp024667/easimp1
Open

EAS api implentation#1411
seanpang-vmware wants to merge 1 commit into
vmware-tanzu:mainfrom
seanpang-vmware:topic/sp024667/easimp1

Conversation

@seanpang-vmware
Copy link
Copy Markdown
Contributor

@seanpang-vmware seanpang-vmware commented Apr 16, 2026

add EAS api implementation

Testing Done:

  1. kubectl get apiservice v1alpha1.eas.nsx.vmware.com : verify EAS APIService is registered and available
NAME                          SERVICE                     AVAILABLE   AGE
v1alpha1.eas.nsx.vmware.com   vmware-system-nsx/nsx-eas   True        2d21h
  1. kubectl get vpcipaddressusage sean-ns_2oq3d -n sean-ns -o yaml : GET VPCIPAddressUsage by VPC name, shows IP block allocation per VPC
root@421682aeb7744f9b840c79d3baa023a1 [ /tmp ]# k get vpcipaddressusage sean-ns_2oq3d -n sean-ns -o yaml
apiVersion: eas.nsx.vmware.com/v1alpha1
ipBlocks:
- allocatedByVPC:
    accessMode: Public
    count: 65
    ipAddresses:
    - address: 192.168.0.64/26
      subnetName: subnet-sample-a_2oq3d
    - address: 192.168.0.7
      ipAddressAllocationName: _DEFAULT--VPC_SERVICE_IP
    percentageUsed: "0.1"
  available: 65437
  cidr: 192.168.0.0/16
  cidrs:
  - 192.168.0.0/16
  ipBlockName: ipblock-192.168.0.0-netmask-16
  percentageUsed: "0.14648438"
  total: 65536
  visibility: External
kind: VPCIPAddressUsage
metadata:
  name: sean-ns_2oq3d
  namespace: sean-ns

  1. kubectl get ipblockusage ipblock-192.168.0.0-netmask-16 -n sean-ns -o yaml : GET IPBlockUsage by NSX block ID (extracted from Step 2), shows per-CIDR used/available ranges
root@421682aeb7744f9b840c79d3baa023a1 [ /tmp ]# k get ipblockusage ipblock-192.168.0.0-netmask-16 -n sean-ns -o yaml
apiVersion: eas.nsx.vmware.com/v1alpha1
availableIPRanges:
- 192.168.0.17-192.168.0.31
- 192.168.0.48-192.168.0.63
- 192.168.0.128-192.168.250.0
- 192.168.250.2-192.168.255.254
availableIPsCount: "65437"
cidrUsages:
- cidr: 192.168.0.0/16
  usageDetails:
    availableIPRanges:
    - 192.168.0.17-192.168.0.31
    - 192.168.0.48-192.168.0.63
    - 192.168.0.128-192.168.250.0
    - 192.168.250.2-192.168.255.254
    availableIPsCount: "65437"
    overallUsedIPRanges:
    - 192.168.0.0-192.168.0.0
    - 192.168.0.1-192.168.0.1
    - 192.168.0.2-192.168.0.2
    - 192.168.0.3-192.168.0.3
    - 192.168.0.4-192.168.0.4
    - 192.168.0.5-192.168.0.5
    - 192.168.0.6-192.168.0.6
    - 192.168.0.7-192.168.0.7
    - 192.168.0.8-192.168.0.15
    - 192.168.0.16-192.168.0.16
    - 192.168.0.32-192.168.0.47
    - 192.168.0.64-192.168.0.127
    - 192.168.250.1-192.168.250.1
    - 192.168.255.255-192.168.255.255
    overallUsedIPsCount: "99"
    usedIPRanges:
    - 192.168.0.0-192.168.0.0
    - 192.168.0.1-192.168.0.1
    - 192.168.0.2-192.168.0.2
    - 192.168.0.3-192.168.0.3
    - 192.168.0.4-192.168.0.4
    - 192.168.0.5-192.168.0.5
    - 192.168.0.6-192.168.0.6
    - 192.168.0.7-192.168.0.7
    - 192.168.0.8-192.168.0.15
    - 192.168.0.16-192.168.0.16
    - 192.168.0.32-192.168.0.47
    - 192.168.0.64-192.168.0.127
    - 192.168.250.1-192.168.250.1
    - 192.168.255.255-192.168.255.255
    usedIPsCount: "99"
kind: IPBlockUsage
metadata:
  name: ipblock-192.168.0.0-netmask-16
  namespace: sean-ns
overallIPsCount: "65536"
usedIPRanges:
- 192.168.0.0-192.168.0.0
- 192.168.0.1-192.168.0.1
- 192.168.0.2-192.168.0.2
- 192.168.0.3-192.168.0.3
- 192.168.0.4-192.168.0.4
- 192.168.0.5-192.168.0.5
- 192.168.0.6-192.168.0.6
- 192.168.0.7-192.168.0.7
- 192.168.0.8-192.168.0.15
- 192.168.0.16-192.168.0.16
- 192.168.0.32-192.168.0.47
- 192.168.0.64-192.168.0.127
- 192.168.250.1-192.168.250.1
- 192.168.255.255-192.168.255.255
usedIPsCount: "99"
visibility: External

  1. k get ipblockusage project-quality:project-quality-ipblock-10.246.0.0-netmask-16 -n sean-ns -o yaml : test ipblock usage with input format project-id:ipblock-id
apiVersion: eas.nsx.vmware.com/v1alpha1
availableIPRanges:
- 10.246.0.16-10.246.255.255
availableIPsCount: "65520"
cidrUsages:
- cidr: 10.246.0.0/16
  usageDetails:
    availableIPRanges:
    - 10.246.0.16-10.246.255.255
    availableIPsCount: "65520"
    overallUsedIPRanges:
    - 10.246.0.0-10.246.0.15
    overallUsedIPsCount: "16"
    usedIPRanges:
    - 10.246.0.0-10.246.0.15
    usedIPsCount: "16"
kind: IPBlockUsage
metadata:
  name: project-quality:project-quality-ipblock-10.246.0.0-netmask-16
  namespace: sean-ns
overallIPsCount: "65536"
usedIPRanges:
- 10.246.0.0-10.246.0.15
usedIPsCount: "16"
visibility: Private
  1. kubectl get subnetdhcpserverstats _services -n sean-ns -o yaml : GET SubnetDHCPServerStats by subnet name, shows DHCP pool sizes
apiVersion: eas.nsx.vmware.com/v1alpha1
kind: SubnetDHCPServerStats
metadata:
  name: _services
  namespace: sean-ns
ipPoolStats:
- poolSize: 248
  1. kubectl get subnetippools vm-default-1c718744_9dzaq -n kube-system -o yaml : GET SubnetIPPools by subnet name, shows IP allocation pool usage
apiVersion: eas.nsx.vmware.com/v1alpha1
kind: SubnetIPPools
metadata:
  name: vm-default-1c718744_9dzaq
  namespace: kube-system
ipAddressType: IPV4
poolUsage:
  totalIPs: 5
  availableIPs: 4
  allocatedIPAllocations: 1
  requestedIPAllocations: 1

@seanpang-vmware seanpang-vmware force-pushed the topic/sp024667/easimp1 branch 3 times, most recently from 122a630 to 75a5c7a Compare April 27, 2026 03:11
@seanpang-vmware seanpang-vmware changed the title Topic/sp024667/easimp1 EAS api implentation Apr 27, 2026
@seanpang-vmware seanpang-vmware force-pushed the topic/sp024667/easimp1 branch 2 times, most recently from b07abca to fdceca9 Compare April 28, 2026 07:25
@seanpang-vmware seanpang-vmware force-pushed the topic/sp024667/easimp1 branch 2 times, most recently from f740a67 to 99c39b7 Compare May 6, 2026 10:02
@vmware-tanzu vmware-tanzu deleted a comment from codecov-commenter May 6, 2026
@seanpang-vmware seanpang-vmware force-pushed the topic/sp024667/easimp1 branch 2 times, most recently from b16b2e0 to 476c66d Compare May 7, 2026 09:29
Comment thread pkg/eas/server/apiservice_register.go
Comment thread pkg/eas/server/apiservice_register.go Outdated
Comment thread pkg/eas/server/response.go Outdated
Comment thread pkg/eas/server/table.go Outdated
Comment thread pkg/eas/vpcprovider.go
@seanpang-vmware seanpang-vmware force-pushed the topic/sp024667/easimp1 branch 9 times, most recently from de62c72 to e668134 Compare May 12, 2026 02:57
Comment thread build/yaml/eas/clusterrole.yaml Outdated
Comment thread build/yaml/eas/clusterrole.yaml Outdated
Comment thread Makefile
Comment thread pkg/config/config.go
Comment thread pkg/config/config.go Outdated
@seanpang-vmware seanpang-vmware force-pushed the topic/sp024667/easimp1 branch from e668134 to f35c674 Compare May 12, 2026 05:56
Comment thread pkg/apis/eas/v1alpha1/vpcipaddressusage_types.go Outdated
@seanpang-vmware seanpang-vmware force-pushed the topic/sp024667/easimp1 branch 2 times, most recently from 7335184 to 59a983e Compare May 12, 2026 08:38
Comment thread pkg/eas/vpcprovider.go
Comment thread pkg/eas/vpcprovider.go
Comment thread pkg/apis/eas/v1alpha1/vpcipaddressusage_types.go Outdated
Comment thread pkg/apis/eas/v1alpha1/vpcipaddressusage_types.go Outdated
@seanpang-vmware seanpang-vmware force-pushed the topic/sp024667/easimp1 branch 3 times, most recently from 06895a8 to e3746a6 Compare May 13, 2026 08:38
@seanpang-vmware seanpang-vmware force-pushed the topic/sp024667/easimp1 branch 3 times, most recently from 5d72928 to 2aa5983 Compare May 13, 2026 10:03
Comment thread pkg/apis/eas/v1alpha1/vpcipaddressusage_types.go Outdated
Comment thread pkg/eas/vpcprovider.go
@seanpang-vmware seanpang-vmware force-pushed the topic/sp024667/easimp1 branch 9 times, most recently from 3ed236e to 941fd6e Compare May 18, 2026 08:47
@seanpang-vmware seanpang-vmware force-pushed the topic/sp024667/easimp1 branch from 941fd6e to 8f5de94 Compare May 18, 2026 09:11
@seanpang-vmware
Copy link
Copy Markdown
Contributor Author

seanpang-vmware commented May 18, 2026

@jianjuns @dantingl
const (
annotationVPCNetworkConfig = "nsx.vmware.com/vpc_network_config"
annotationDefaultConfig = "nsx.vmware.com/default"

this 2 values are used to get values from vpc network config CR, the tags are used in previous release to set values between wcp svc and nsx-operator reconciler. i am not using this value to add annotation to CR, so this tag could not be changed, that would involve code change on both wcpsvc side and nsx-operator side and not related to this feature.

@seanpang-vmware seanpang-vmware force-pushed the topic/sp024667/easimp1 branch 2 times, most recently from 3a295fb to a2e948a Compare May 18, 2026 10:11
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.56436% with 166 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.47%. Comparing base (ff79596) to head (a2e948a).

Files with missing lines Patch % Lines
cmd_eas/main.go 0.00% 55 Missing ⚠️
pkg/eas/server/server.go 52.38% 38 Missing and 2 partials ⚠️
pkg/util/cert.go 80.12% 23 Missing and 8 partials ⚠️
pkg/eas/server/apiservice_register.go 77.65% 15 Missing and 6 partials ⚠️
pkg/eas/converter/converter.go 96.00% 8 Missing ⚠️
pkg/eas/vpcprovider.go 91.52% 3 Missing and 2 partials ⚠️
pkg/eas/storage/subnetipppols.go 94.66% 2 Missing and 2 partials ⚠️
pkg/eas/storage/ipblokusage.go 96.22% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1411      +/-   ##
==========================================
+ Coverage   77.02%   77.47%   +0.44%     
==========================================
  Files         156      168      +12     
  Lines       22048    23046     +998     
==========================================
+ Hits        16983    17854     +871     
- Misses       3859     3976     +117     
- Partials     1206     1216      +10     
Flag Coverage Δ
unit-tests 77.47% <83.56%> (+0.44%) ⬆️
Files with missing lines Coverage Δ
pkg/config/config.go 72.27% <ø> (ø)
pkg/eas/server/rest_storage.go 100.00% <100.00%> (ø)
pkg/eas/server/scheme.go 100.00% <100.00%> (ø)
pkg/eas/server/table.go 100.00% <100.00%> (ø)
pkg/eas/storage/subnetdhcpstats.go 100.00% <100.00%> (ø)
pkg/eas/storage/vpcipaddressusage.go 100.00% <100.00%> (ø)
pkg/nsx/client.go 93.53% <100.00%> (+0.23%) ⬆️
pkg/eas/storage/ipblokusage.go 96.22% <96.22%> (ø)
pkg/eas/storage/subnetipppols.go 94.66% <94.66%> (ø)
pkg/eas/vpcprovider.go 91.52% <91.52%> (ø)
... and 5 more

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- ipblockusages
- subnetippools
- subnetdhcpserverstats
verbs: ["get", "list"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These APIs should only have GET

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

per one pager, ipblockusage and vpcipaddressusage support list.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If that, you should add ipblockusage and vpcipaddressusage for get/list
and move subnetippools and subnetdhcpserverstats for get

Comment thread pkg/apis/eas/v1alpha1/ipblockusage_types.go
Comment thread pkg/apis/eas/v1alpha1/subnetdhcpstats_types.go
Comment thread pkg/apis/eas/v1alpha1/vpcipaddressusage_types.go
Comment thread pkg/eas/server/rest_storage.go
"github.com/vmware-tanzu/nsx-operator/pkg/eas/storage"
)

// ── VPCIPAddressUsage ────────────────────────────────────────────────────────
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it's better to move each api to an individual file

Comment thread pkg/eas/server/apiservice_register.go
Comment thread pkg/eas/server/server.go
Comment thread cmd_eas/main.go Outdated
@jianjuns
Copy link
Copy Markdown

@jianjuns @dantingl const ( annotationVPCNetworkConfig = "nsx.vmware.com/vpc_network_config" annotationDefaultConfig = "nsx.vmware.com/default"

this 2 values are used to get values from vpc network config CR, the tags are used in previous release to set values between wcp svc and nsx-operator reconciler. i am not using this value to add annotation to CR, so this tag could not be changed, that would involve code change on both wcpsvc side and nsx-operator side and not related to this feature.

They are annotations on VPCNetworkConfig CR or not? Could you add some code comments before each to explain how they are used?

@seanpang-vmware
Copy link
Copy Markdown
Contributor Author

seanpang-vmware commented May 19, 2026

nsx.vmware.com/default

The full resolution chain for any namespace is:

Namespace has annotation vpc_network_config=?
YES → use VPCNetworkConfiguration CR named
NO → scan all VPCNetworkConfiguration CRs for nsx.vmware.com/default=true → use that one

this logic is defined from the init version to scan VPCNetworkConfiguration.

will add comments on function to explain how this annotation is used.

@seanpang-vmware seanpang-vmware force-pushed the topic/sp024667/easimp1 branch 3 times, most recently from 1d8d813 to 79da0ff Compare May 19, 2026 08:20
1. add a new eas service in nsx-operator
2. register eas service to k8s api server
3. start a http service on 9553 port
4. add eas service implentations for ip usages api yamls
@seanpang-vmware seanpang-vmware force-pushed the topic/sp024667/easimp1 branch from 79da0ff to 47fed3d Compare May 19, 2026 09:03
Comment thread pkg/eas/server/table.go

// Per-resource table column definitions for kubectl Table format.
var (
vpcIPUsageColumns = []metav1.TableColumnDefinition{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please also move table to the corresponding API file and merge the logic in one file

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.

5 participants