Skip to content

Commit 642da0f

Browse files
zhengxiexieoz-agent
andcommitted
EAS: add Extension API Server with multi-active HA
Add NSX Extension API Server (EAS) as a sidecar in the nsx-ncp pod, exposing NSX IP usage data via Kubernetes aggregated API (eas.nsx.vmware.com/v1alpha1). Resources: VPCIPAddressUsage, IPBlockUsage, SubnetIPPools, SubnetDHCPServerConfigStats. Supports JSON and Table output formats. Server architecture: - pkg/eas/server/ package with generic map-based resource dispatch - controller-runtime Runnable lifecycle (context-aware shutdown) - HTTP method gating (GET/HEAD only), StatusError responses - Multi-active mode: all replicas serve concurrently (no leader election needed since EAS is read-only) Co-Authored-By: Oz <oz-agent@warp.dev> Change-Id: I13fd15caf6e03cb4c5dc777716cf97ee99b35373
1 parent b153b78 commit 642da0f

33 files changed

Lines changed: 3267 additions & 1 deletion

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ changecrd: manifests generate generate-api-docs
4646
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
4747
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="github.com/vmware-tanzu/nsx-operator/pkg/apis/legacy/v1alpha1" output:crd:artifacts:config=build/yaml/crd/legacy/
4848
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="github.com/vmware-tanzu/nsx-operator/pkg/apis/vpc/v1alpha1" output:crd:artifacts:config=build/yaml/crd/vpc/
49+
# EAS CRDs are for schema validation and kubectl explain only; do not apply to cluster.
50+
# EAS resources are served by the aggregated API server via APIService, not by CRDs.
51+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="github.com/vmware-tanzu/nsx-operator/pkg/apis/eas/v1alpha1" output:crd:artifacts:config=build/yaml/crd/eas/
4952

5053
.PHONY: generate
5154
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
@@ -96,6 +99,11 @@ build-clean: generate fmt vet ## Build clean binary.
9699
@mkdir -p $(BINDIR)
97100
GOOS=linux go build -o $(BINDIR)/clean $(GOFLAGS) -ldflags '$(LDFLAGS)' cmd_clean/main.go
98101

102+
.PHONY: build-eas
103+
build-eas: generate fmt vet ## Build EAS (Extension API Server) binary.
104+
@mkdir -p $(BINDIR)
105+
GOOS=linux go build -o $(BINDIR)/nsx-eas $(GOFLAGS) -ldflags '$(LDFLAGS)' cmd_eas/main.go
106+
99107
.PHONY: run
100108
run: manifests generate fmt vet ## Run a controller from your host.
101109
go run ./cmd/main.go
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.16.5
7+
name: ipblockusages.eas.nsx.vmware.com
8+
spec:
9+
group: eas.nsx.vmware.com
10+
names:
11+
kind: IPBlockUsage
12+
listKind: IPBlockUsageList
13+
plural: ipblockusages
14+
singular: ipblockusage
15+
scope: Namespaced
16+
versions:
17+
- additionalPrinterColumns:
18+
- description: IP block visibility
19+
jsonPath: .spec.visibility
20+
name: Visibility
21+
type: string
22+
- description: Used IP count
23+
jsonPath: .spec.usedIpsCount
24+
name: UsedIPs
25+
type: string
26+
- description: Available IP count
27+
jsonPath: .spec.availableIpsCount
28+
name: AvailableIPs
29+
type: string
30+
name: v1alpha1
31+
schema:
32+
openAPIV3Schema:
33+
description: IPBlockUsage is the Schema for the IP block usage API.
34+
properties:
35+
apiVersion:
36+
description: |-
37+
APIVersion defines the versioned schema of this representation of an object.
38+
Servers should convert recognized schemas to the latest internal value, and
39+
may reject unrecognized values.
40+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
41+
type: string
42+
kind:
43+
description: |-
44+
Kind is a string value representing the REST resource this object represents.
45+
Servers may infer this from the endpoint the client submits requests to.
46+
Cannot be updated.
47+
In CamelCase.
48+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
49+
type: string
50+
metadata:
51+
type: object
52+
spec:
53+
description: IPBlockUsageSpec represents the usage of an IP Address Block.
54+
properties:
55+
addressType:
56+
description: Address type (IPV4 or IPV6).
57+
type: string
58+
availableIpRanges:
59+
description: Available IP ranges.
60+
items:
61+
type: string
62+
type: array
63+
availableIpsCount:
64+
description: Total count of available IPs.
65+
type: string
66+
cidrUsage:
67+
description: Usage details for each CIDR.
68+
items:
69+
description: CidrUsageDetails represents usage details for a CIDR
70+
of IpAddressBlock.
71+
properties:
72+
availableIpRanges:
73+
description: Available IP ranges.
74+
items:
75+
type: string
76+
type: array
77+
availableIpsCount:
78+
description: Available IP count.
79+
type: string
80+
cidr:
81+
description: CIDR notation.
82+
type: string
83+
overallUsedIpsCount:
84+
description: Overall used IP count (not limited to user's scope).
85+
type: string
86+
usedIpRanges:
87+
description: Used IP ranges in the user's scope.
88+
items:
89+
type: string
90+
type: array
91+
usedIpsCount:
92+
description: Used IP count in the user's scope.
93+
type: string
94+
type: object
95+
type: array
96+
description:
97+
description: Description of the IP block.
98+
type: string
99+
displayName:
100+
description: Display name of the IP block.
101+
type: string
102+
intentPath:
103+
description: Policy path of IpAddressBlock.
104+
type: string
105+
overallIpsCount:
106+
description: Total count of IPs in this block.
107+
type: string
108+
rangeUsage:
109+
description: Usage details for each IP range.
110+
items:
111+
description: RangeUsageDetails represents usage details for an IP
112+
range of IpAddressBlock.
113+
properties:
114+
availableIpRanges:
115+
description: Available IP ranges.
116+
items:
117+
type: string
118+
type: array
119+
availableIpsCount:
120+
description: Available IP count.
121+
type: string
122+
overallUsedIpsCount:
123+
description: Overall used IP count (not limited to user's scope).
124+
type: string
125+
start:
126+
description: The IP range from RangeList in IpAddressBlock.
127+
type: string
128+
usedIpRanges:
129+
description: Used IP ranges in the user's scope.
130+
items:
131+
type: string
132+
type: array
133+
usedIpsCount:
134+
description: Used IP count in the user's scope.
135+
type: string
136+
type: object
137+
type: array
138+
usedIpRanges:
139+
description: Used IP ranges.
140+
items:
141+
type: string
142+
type: array
143+
usedIpsCount:
144+
description: Total count of used IPs.
145+
type: string
146+
visibility:
147+
description: Visibility (PRIVATE or EXTERNAL).
148+
type: string
149+
type: object
150+
required:
151+
- spec
152+
type: object
153+
served: true
154+
storage: true
155+
subresources: {}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.16.5
7+
name: subnetdhcpserverconfigstats.eas.nsx.vmware.com
8+
spec:
9+
group: eas.nsx.vmware.com
10+
names:
11+
kind: SubnetDHCPServerConfigStats
12+
listKind: SubnetDHCPServerConfigStatsList
13+
plural: subnetdhcpserverconfigstats
14+
singular: subnetdhcpserverconfigstats
15+
scope: Namespaced
16+
versions:
17+
- additionalPrinterColumns:
18+
- description: DHCP server UUID
19+
jsonPath: .spec.dhcpServerId
20+
name: DHCPServerID
21+
type: string
22+
name: v1alpha1
23+
schema:
24+
openAPIV3Schema:
25+
description: SubnetDHCPServerConfigStats is the Schema for the subnet DHCP
26+
server config stats API.
27+
properties:
28+
apiVersion:
29+
description: |-
30+
APIVersion defines the versioned schema of this representation of an object.
31+
Servers should convert recognized schemas to the latest internal value, and
32+
may reject unrecognized values.
33+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
34+
type: string
35+
kind:
36+
description: |-
37+
Kind is a string value representing the REST resource this object represents.
38+
Servers may infer this from the endpoint the client submits requests to.
39+
Cannot be updated.
40+
In CamelCase.
41+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
42+
type: string
43+
metadata:
44+
type: object
45+
spec:
46+
description: SubnetDHCPServerConfigStatsSpec represents the DHCP server
47+
statistics for a subnet.
48+
properties:
49+
acks:
50+
description: Total number of DHCP ACK packets.
51+
format: int64
52+
type: integer
53+
declines:
54+
description: Total number of DHCP DECLINE packets.
55+
format: int64
56+
type: integer
57+
dhcpServerId:
58+
description: DHCP server UUID.
59+
type: string
60+
discovers:
61+
description: Total number of DHCP DISCOVER packets.
62+
format: int64
63+
type: integer
64+
errors:
65+
description: Total number of DHCP errors.
66+
format: int64
67+
type: integer
68+
informs:
69+
description: Total number of DHCP INFORM packets.
70+
format: int64
71+
type: integer
72+
ipPoolStats:
73+
description: DHCP IP pool usage statistics.
74+
items:
75+
description: DhcpIpPoolUsage represents DHCP IP pool usage statistics.
76+
properties:
77+
allocatedNumber:
78+
description: Allocated number (reference only).
79+
format: int64
80+
type: integer
81+
allocatedPercentage:
82+
description: Allocated percentage (reference only).
83+
format: int64
84+
type: integer
85+
consumedNumber:
86+
description: Total number of IP addresses consumed by DHCP clients.
87+
format: int64
88+
type: integer
89+
dhcpIpPoolId:
90+
description: UUID of DHCP IP pool.
91+
type: string
92+
poolSize:
93+
description: Pool size.
94+
format: int64
95+
type: integer
96+
type: object
97+
type: array
98+
nacks:
99+
description: Total number of DHCP NACK packets.
100+
format: int64
101+
type: integer
102+
offers:
103+
description: Total number of DHCP OFFER packets.
104+
format: int64
105+
type: integer
106+
releases:
107+
description: Total number of DHCP RELEASE packets.
108+
format: int64
109+
type: integer
110+
type: object
111+
required:
112+
- spec
113+
type: object
114+
served: true
115+
storage: true
116+
subresources: {}

0 commit comments

Comments
 (0)