From aeac2de9d7a9512b2941fd5c558b628e130da0d2 Mon Sep 17 00:00:00 2001 From: Mengdie Song Date: Fri, 23 Feb 2024 16:20:26 +0800 Subject: [PATCH] Unify IPPool subnet and ExternalIPPool definitions 1. Make IPPoolSpec of IPPool use the same way to define IP ranges and subnet as ExternalIPPool. 2. Promote IPPool CRD to v1beta1 Fixes:#5961 Signed-off-by: Mengdie Song --- build/charts/antrea/crds/ippool.yaml | 120 ++++++- build/yamls/antrea-aks.yml | 120 ++++++- build/yamls/antrea-crds.yml | 120 ++++++- build/yamls/antrea-eks.yml | 120 ++++++- build/yamls/antrea-gke.yml | 120 ++++++- build/yamls/antrea-ipsec.yml | 120 ++++++- build/yamls/antrea.yml | 120 ++++++- cmd/antrea-agent/agent.go | 2 +- cmd/antrea-controller/controller.go | 2 +- docs/antrea-ipam.md | 9 +- docs/api.md | 49 +-- pkg/agent/cniserver/ipam/antrea_ipam.go | 32 +- .../cniserver/ipam/antrea_ipam_controller.go | 22 +- pkg/agent/ipassigner/ip_assigner_linux.go | 10 +- .../secondarynetwork/podwatch/controller.go | 10 +- .../podwatch/testing/mock_podwatch.go | 8 +- pkg/apis/crd/v1beta1/register.go | 2 + pkg/apis/crd/v1beta1/types.go | 92 ++++- pkg/apis/crd/v1beta1/zz_generated.deepcopy.go | 188 +++++++++- pkg/apiserver/openapi/zz_generated.openapi.go | 327 +++++++++++++++++- .../versioned/typed/crd/v1beta1/crd_client.go | 7 +- .../typed/crd/v1beta1/fake/fake_crd_client.go | 6 +- .../typed/crd/v1beta1/fake/fake_ippool.go | 131 +++++++ .../typed/crd/v1beta1/generated_expansion.go | 4 +- .../versioned/typed/crd/v1beta1/ippool.go | 182 ++++++++++ .../externalversions/crd/v1beta1/interface.go | 9 +- .../externalversions/crd/v1beta1/ippool.go | 87 +++++ .../informers/externalversions/generic.go | 4 +- .../crd/v1beta1/expansion_generated.go | 6 +- pkg/client/listers/crd/v1beta1/ippool.go | 66 ++++ pkg/controller/ipam/antrea_ipam_controller.go | 20 +- pkg/ipam/poolallocator/allocator.go | 88 ++--- pkg/ipam/poolallocator/allocator_test.go | 144 ++++---- pkg/ipam/poolallocator/testing/fake_client.go | 6 +- 34 files changed, 2125 insertions(+), 228 deletions(-) create mode 100644 pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_ippool.go create mode 100644 pkg/client/clientset/versioned/typed/crd/v1beta1/ippool.go create mode 100644 pkg/client/informers/externalversions/crd/v1beta1/ippool.go create mode 100644 pkg/client/listers/crd/v1beta1/ippool.go diff --git a/build/charts/antrea/crds/ippool.yaml b/build/charts/antrea/crds/ippool.yaml index ff1f3a4af0f..ea126b75a47 100644 --- a/build/charts/antrea/crds/ippool.yaml +++ b/build/charts/antrea/crds/ippool.yaml @@ -9,7 +9,7 @@ spec: versions: - name: v1alpha2 served: true - storage: true + storage: false schema: openAPIV3Schema: type: object @@ -122,6 +122,124 @@ spec: type: date subresources: status: {} + - name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + required: + - ipVersion + - ipRanges + - subnetInfo + type: object + properties: + ipVersion: + type: integer + enum: [ 4, 6 ] + ipRanges: + items: + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + format: cidr + type: string + start: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + end: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + type: object + type: array + subnetInfo: + type: object + required: + - gateway + - prefixLength + properties: + gateway: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + prefixLength: + type: integer + minimum: 1 + maximum: 127 + vlan: + type: integer + minimum: 0 + maximum: 4094 + status: + properties: + ipAddresses: + items: + properties: + ipAddress: + type: string + owner: + properties: + pod: + properties: + name: + type: string + namespace: + type: string + containerID: + type: string + ifName: + type: string + type: object + statefulSet: + properties: + name: + type: string + namespace: + type: string + index: + type: integer + type: object + type: object + phase: + type: string + type: object + type: array + usage: + properties: + used: + type: integer + total: + type: integer + type: object + type: object + additionalPrinterColumns: + - description: The number of total IPs + jsonPath: .status.usage.total + name: Total + type: integer + - description: The number of allocated IPs + jsonPath: .status.usage.used + name: Used + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + subresources: + status: {} scope: Cluster names: plural: ippools diff --git a/build/yamls/antrea-aks.yml b/build/yamls/antrea-aks.yml index 155d2016690..b8aefab7371 100644 --- a/build/yamls/antrea-aks.yml +++ b/build/yamls/antrea-aks.yml @@ -3042,7 +3042,7 @@ spec: versions: - name: v1alpha2 served: true - storage: true + storage: false schema: openAPIV3Schema: type: object @@ -3155,6 +3155,124 @@ spec: type: date subresources: status: {} + - name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + required: + - ipVersion + - ipRanges + - subnetInfo + type: object + properties: + ipVersion: + type: integer + enum: [ 4, 6 ] + ipRanges: + items: + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + format: cidr + type: string + start: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + end: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + type: object + type: array + subnetInfo: + type: object + required: + - gateway + - prefixLength + properties: + gateway: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + prefixLength: + type: integer + minimum: 1 + maximum: 127 + vlan: + type: integer + minimum: 0 + maximum: 4094 + status: + properties: + ipAddresses: + items: + properties: + ipAddress: + type: string + owner: + properties: + pod: + properties: + name: + type: string + namespace: + type: string + containerID: + type: string + ifName: + type: string + type: object + statefulSet: + properties: + name: + type: string + namespace: + type: string + index: + type: integer + type: object + type: object + phase: + type: string + type: object + type: array + usage: + properties: + used: + type: integer + total: + type: integer + type: object + type: object + additionalPrinterColumns: + - description: The number of total IPs + jsonPath: .status.usage.total + name: Total + type: integer + - description: The number of allocated IPs + jsonPath: .status.usage.used + name: Used + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + subresources: + status: {} scope: Cluster names: plural: ippools diff --git a/build/yamls/antrea-crds.yml b/build/yamls/antrea-crds.yml index 7439bdf964d..b5c071db1bf 100644 --- a/build/yamls/antrea-crds.yml +++ b/build/yamls/antrea-crds.yml @@ -3023,7 +3023,7 @@ spec: versions: - name: v1alpha2 served: true - storage: true + storage: false schema: openAPIV3Schema: type: object @@ -3136,6 +3136,124 @@ spec: type: date subresources: status: {} + - name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + required: + - ipVersion + - ipRanges + - subnetInfo + type: object + properties: + ipVersion: + type: integer + enum: [ 4, 6 ] + ipRanges: + items: + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + format: cidr + type: string + start: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + end: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + type: object + type: array + subnetInfo: + type: object + required: + - gateway + - prefixLength + properties: + gateway: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + prefixLength: + type: integer + minimum: 1 + maximum: 127 + vlan: + type: integer + minimum: 0 + maximum: 4094 + status: + properties: + ipAddresses: + items: + properties: + ipAddress: + type: string + owner: + properties: + pod: + properties: + name: + type: string + namespace: + type: string + containerID: + type: string + ifName: + type: string + type: object + statefulSet: + properties: + name: + type: string + namespace: + type: string + index: + type: integer + type: object + type: object + phase: + type: string + type: object + type: array + usage: + properties: + used: + type: integer + total: + type: integer + type: object + type: object + additionalPrinterColumns: + - description: The number of total IPs + jsonPath: .status.usage.total + name: Total + type: integer + - description: The number of allocated IPs + jsonPath: .status.usage.used + name: Used + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + subresources: + status: {} scope: Cluster names: plural: ippools diff --git a/build/yamls/antrea-eks.yml b/build/yamls/antrea-eks.yml index 3775ab5a638..bcd07e08d23 100644 --- a/build/yamls/antrea-eks.yml +++ b/build/yamls/antrea-eks.yml @@ -3042,7 +3042,7 @@ spec: versions: - name: v1alpha2 served: true - storage: true + storage: false schema: openAPIV3Schema: type: object @@ -3155,6 +3155,124 @@ spec: type: date subresources: status: {} + - name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + required: + - ipVersion + - ipRanges + - subnetInfo + type: object + properties: + ipVersion: + type: integer + enum: [ 4, 6 ] + ipRanges: + items: + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + format: cidr + type: string + start: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + end: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + type: object + type: array + subnetInfo: + type: object + required: + - gateway + - prefixLength + properties: + gateway: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + prefixLength: + type: integer + minimum: 1 + maximum: 127 + vlan: + type: integer + minimum: 0 + maximum: 4094 + status: + properties: + ipAddresses: + items: + properties: + ipAddress: + type: string + owner: + properties: + pod: + properties: + name: + type: string + namespace: + type: string + containerID: + type: string + ifName: + type: string + type: object + statefulSet: + properties: + name: + type: string + namespace: + type: string + index: + type: integer + type: object + type: object + phase: + type: string + type: object + type: array + usage: + properties: + used: + type: integer + total: + type: integer + type: object + type: object + additionalPrinterColumns: + - description: The number of total IPs + jsonPath: .status.usage.total + name: Total + type: integer + - description: The number of allocated IPs + jsonPath: .status.usage.used + name: Used + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + subresources: + status: {} scope: Cluster names: plural: ippools diff --git a/build/yamls/antrea-gke.yml b/build/yamls/antrea-gke.yml index d8be7ff47f5..0a55c531727 100644 --- a/build/yamls/antrea-gke.yml +++ b/build/yamls/antrea-gke.yml @@ -3042,7 +3042,7 @@ spec: versions: - name: v1alpha2 served: true - storage: true + storage: false schema: openAPIV3Schema: type: object @@ -3155,6 +3155,124 @@ spec: type: date subresources: status: {} + - name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + required: + - ipVersion + - ipRanges + - subnetInfo + type: object + properties: + ipVersion: + type: integer + enum: [ 4, 6 ] + ipRanges: + items: + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + format: cidr + type: string + start: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + end: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + type: object + type: array + subnetInfo: + type: object + required: + - gateway + - prefixLength + properties: + gateway: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + prefixLength: + type: integer + minimum: 1 + maximum: 127 + vlan: + type: integer + minimum: 0 + maximum: 4094 + status: + properties: + ipAddresses: + items: + properties: + ipAddress: + type: string + owner: + properties: + pod: + properties: + name: + type: string + namespace: + type: string + containerID: + type: string + ifName: + type: string + type: object + statefulSet: + properties: + name: + type: string + namespace: + type: string + index: + type: integer + type: object + type: object + phase: + type: string + type: object + type: array + usage: + properties: + used: + type: integer + total: + type: integer + type: object + type: object + additionalPrinterColumns: + - description: The number of total IPs + jsonPath: .status.usage.total + name: Total + type: integer + - description: The number of allocated IPs + jsonPath: .status.usage.used + name: Used + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + subresources: + status: {} scope: Cluster names: plural: ippools diff --git a/build/yamls/antrea-ipsec.yml b/build/yamls/antrea-ipsec.yml index 5d77441ce72..2c99a35f752 100644 --- a/build/yamls/antrea-ipsec.yml +++ b/build/yamls/antrea-ipsec.yml @@ -3042,7 +3042,7 @@ spec: versions: - name: v1alpha2 served: true - storage: true + storage: false schema: openAPIV3Schema: type: object @@ -3155,6 +3155,124 @@ spec: type: date subresources: status: {} + - name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + required: + - ipVersion + - ipRanges + - subnetInfo + type: object + properties: + ipVersion: + type: integer + enum: [ 4, 6 ] + ipRanges: + items: + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + format: cidr + type: string + start: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + end: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + type: object + type: array + subnetInfo: + type: object + required: + - gateway + - prefixLength + properties: + gateway: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + prefixLength: + type: integer + minimum: 1 + maximum: 127 + vlan: + type: integer + minimum: 0 + maximum: 4094 + status: + properties: + ipAddresses: + items: + properties: + ipAddress: + type: string + owner: + properties: + pod: + properties: + name: + type: string + namespace: + type: string + containerID: + type: string + ifName: + type: string + type: object + statefulSet: + properties: + name: + type: string + namespace: + type: string + index: + type: integer + type: object + type: object + phase: + type: string + type: object + type: array + usage: + properties: + used: + type: integer + total: + type: integer + type: object + type: object + additionalPrinterColumns: + - description: The number of total IPs + jsonPath: .status.usage.total + name: Total + type: integer + - description: The number of allocated IPs + jsonPath: .status.usage.used + name: Used + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + subresources: + status: {} scope: Cluster names: plural: ippools diff --git a/build/yamls/antrea.yml b/build/yamls/antrea.yml index 411ec97391f..e79d60e0337 100644 --- a/build/yamls/antrea.yml +++ b/build/yamls/antrea.yml @@ -3042,7 +3042,7 @@ spec: versions: - name: v1alpha2 served: true - storage: true + storage: false schema: openAPIV3Schema: type: object @@ -3155,6 +3155,124 @@ spec: type: date subresources: status: {} + - name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + required: + - ipVersion + - ipRanges + - subnetInfo + type: object + properties: + ipVersion: + type: integer + enum: [ 4, 6 ] + ipRanges: + items: + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + format: cidr + type: string + start: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + end: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + type: object + type: array + subnetInfo: + type: object + required: + - gateway + - prefixLength + properties: + gateway: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + prefixLength: + type: integer + minimum: 1 + maximum: 127 + vlan: + type: integer + minimum: 0 + maximum: 4094 + status: + properties: + ipAddresses: + items: + properties: + ipAddress: + type: string + owner: + properties: + pod: + properties: + name: + type: string + namespace: + type: string + containerID: + type: string + ifName: + type: string + type: object + statefulSet: + properties: + name: + type: string + namespace: + type: string + index: + type: integer + type: object + type: object + phase: + type: string + type: object + type: array + usage: + properties: + used: + type: integer + total: + type: integer + type: object + type: object + additionalPrinterColumns: + - description: The number of total IPs + jsonPath: .status.usage.total + name: Total + type: integer + - description: The number of allocated IPs + jsonPath: .status.usage.used + name: Used + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + subresources: + status: {} scope: Cluster names: plural: ippools diff --git a/cmd/antrea-agent/agent.go b/cmd/antrea-agent/agent.go index dbefa8530ba..751a04f192b 100644 --- a/cmd/antrea-agent/agent.go +++ b/cmd/antrea-agent/agent.go @@ -116,7 +116,7 @@ func run(o *Options) error { egressInformer := crdInformerFactory.Crd().V1beta1().Egresses() externalIPPoolInformer := crdInformerFactory.Crd().V1beta1().ExternalIPPools() trafficControlInformer := crdInformerFactory.Crd().V1alpha2().TrafficControls() - ipPoolInformer := crdInformerFactory.Crd().V1alpha2().IPPools() + ipPoolInformer := crdInformerFactory.Crd().V1beta1().IPPools() nodeInformer := informerFactory.Core().V1().Nodes() serviceInformer := informerFactory.Core().V1().Services() endpointsInformer := informerFactory.Core().V1().Endpoints() diff --git a/cmd/antrea-controller/controller.go b/cmd/antrea-controller/controller.go index 36390568d09..da9577bf35d 100644 --- a/cmd/antrea-controller/controller.go +++ b/cmd/antrea-controller/controller.go @@ -149,7 +149,7 @@ func run(o *Options) error { egressInformer := crdInformerFactory.Crd().V1beta1().Egresses() externalIPPoolInformer := crdInformerFactory.Crd().V1beta1().ExternalIPPools() externalNodeInformer := crdInformerFactory.Crd().V1alpha1().ExternalNodes() - ipPoolInformer := crdInformerFactory.Crd().V1alpha2().IPPools() + ipPoolInformer := crdInformerFactory.Crd().V1beta1().IPPools() adminNPInformer := policyInformerFactory.Policy().V1alpha1().AdminNetworkPolicies() banpInformer := policyInformerFactory.Policy().V1alpha1().BaselineAdminNetworkPolicies() diff --git a/docs/antrea-ipam.md b/docs/antrea-ipam.md index 8b96136d4f9..43ff608b796 100644 --- a/docs/antrea-ipam.md +++ b/docs/antrea-ipam.md @@ -160,7 +160,7 @@ enableBridgingMode=true,featureGates.AntreaIPAM=true,trafficEncapMode=noEncap,no The following example YAML manifest creates an IPPool CR. ```yaml -apiVersion: "crd.antrea.io/v1alpha2" +apiVersion: "crd.antrea.io/v1beta1" kind: IPPool metadata: name: pool1 @@ -169,6 +169,7 @@ spec: ipRanges: - start: "10.2.0.12" end: "10.2.0.20" + subnetInfo: gateway: "10.2.0.1" prefixLength: 24 vlan: 2 # Default is 0 (untagged). Valid value is 0~4095. @@ -442,7 +443,7 @@ Antrea IP pools are defined with the `IPPool` CRD. The following two examples define an IPv4 and an IPv6 IP pool respectively. ```yaml -apiVersion: "crd.antrea.io/v1alpha2" +apiVersion: "crd.antrea.io/v1beta1" kind: IPPool metadata: name: ipv4-pool-1 @@ -450,12 +451,13 @@ spec: ipVersion: 4 ipRanges: - cidr: "10.10.1.0/26" + subnetInfo: gateway: "10.10.1.1" prefixLength: 24 ``` ```yaml -apiVersion: "crd.antrea.io/v1alpha2" +apiVersion: "crd.antrea.io/v1beta1" kind: IPPool metadata: name: ipv6-pool-1 @@ -464,6 +466,7 @@ spec: ipRanges: - start: "3ffe:ffff:1:01ff::0100" end: "3ffe:ffff:1:01ff::0200" + subnetInfo: gateway: "3ffe:ffff:1:01ff::1" prefixLength: 64 ``` diff --git a/docs/api.md b/docs/api.md index b0eceb221f5..42592786f1c 100644 --- a/docs/api.md +++ b/docs/api.md @@ -25,30 +25,31 @@ For information about the Antrea API versioning policy, please refer to this These are the CRDs currently available in `crd.antrea.io`. | CRD | CRD version | Introduced in | Deprecated in / Planned Deprecation | Planned Removal | -|---|---|---|---|---| -| `AntreaAgentInfo` | v1beta1 | v1.0.0 | N/A | N/A | -| `AntreaControllerInfo` | v1beta1 | v1.0.0 | N/A | N/A | -| `ClusterGroup` | v1alpha2 | v1.0.0 | v1.1.0 | v2.0.0 | -| `ClusterGroup` | v1alpha3 | v1.1.0 | v1.13.0 | N/A | -| `ClusterGroup` | v1beta1 | v1.13.0 | N/A | N/A | -| `ClusterNetworkPolicy` | v1alpha1 | v1.0.0 | v1.13.0 | N/A | -| `ClusterNetworkPolicy` | v1beta1 | v1.13.0 | N/A | N/A | -| `Egress` | v1alpha2 | v1.0.0 | N/A | N/A | -| `Egress` | v1beta1 | v1.13.0 | N/A | N/A | -| `ExternalEntity` | v1alpha2 | v1.0.0 | N/A | N/A | -| `ExternalIPPool` | v1alpha2 | v1.2.0 | v1.13.0 | N/A | -| `ExternalIPPool` | v1beta1 | v1.13.0 | N/A | N/A | -| `ExternalNode` | v1alpha1 | v1.8.0 | N/A | N/A | -| `IPPool`| v1alpha2 | v1.4.0 | N/A | N/A | -| `Group` | v1alpha3 | v1.8.0 | v1.13.0 | N/A | -| `Group` | v1beta1 | v1.13.0 | N/A | N/A | -| `NetworkPolicy` | v1alpha1 | v1.0.0 | v1.13.0 | N/A | -| `NetworkPolicy` | v1beta1 | v1.13.0 | N/A | N/A | -| `SupportBundleCollection` | v1alpha1 | v1.10.0 | N/A | N/A | -| `Tier` | v1alpha1 | v1.0.0 | v1.13.0 | v2.0.0 | -| `Tier` | v1beta1 | v1.13.0 | N/A | N/A | -| `Traceflow` | v1alpha1 | v1.0.0 | v1.13.0 | N/A | -| `Traceflow` | v1beta1 | v1.13.0 | N/A | N/A | +|---|-------------|---------------|---|---| +| `AntreaAgentInfo` | v1beta1 | v1.0.0 | N/A | N/A | +| `AntreaControllerInfo` | v1beta1 | v1.0.0 | N/A | N/A | +| `ClusterGroup` | v1alpha2 | v1.0.0 | v1.1.0 | v2.0.0 | +| `ClusterGroup` | v1alpha3 | v1.1.0 | v1.13.0 | N/A | +| `ClusterGroup` | v1beta1 | v1.13.0 | N/A | N/A | +| `ClusterNetworkPolicy` | v1alpha1 | v1.0.0 | v1.13.0 | N/A | +| `ClusterNetworkPolicy` | v1beta1 | v1.13.0 | N/A | N/A | +| `Egress` | v1alpha2 | v1.0.0 | N/A | N/A | +| `Egress` | v1beta1 | v1.13.0 | N/A | N/A | +| `ExternalEntity` | v1alpha2 | v1.0.0 | N/A | N/A | +| `ExternalIPPool` | v1alpha2 | v1.2.0 | v1.13.0 | N/A | +| `ExternalIPPool` | v1beta1 | v1.13.0 | N/A | N/A | +| `ExternalNode` | v1alpha1 | v1.8.0 | N/A | N/A | +| `IPPool`| v1alpha2 | v1.4.0 | N/A | N/A | +| `IPPool`| v1beta1 | v2.0.0 | N/A | N/A | +| `Group` | v1alpha3 | v1.8.0 | v1.13.0 | N/A | +| `Group` | v1beta1 | v1.13.0 | N/A | N/A | +| `NetworkPolicy` | v1alpha1 | v1.0.0 | v1.13.0 | N/A | +| `NetworkPolicy` | v1beta1 | v1.13.0 | N/A | N/A | +| `SupportBundleCollection` | v1alpha1 | v1.10.0 | N/A | N/A | +| `Tier` | v1alpha1 | v1.0.0 | v1.13.0 | v2.0.0 | +| `Tier` | v1beta1 | v1.13.0 | N/A | N/A | +| `Traceflow` | v1alpha1 | v1.0.0 | v1.13.0 | N/A | +| `Traceflow` | v1beta1 | v1.13.0 | N/A | N/A | ### Other API groups diff --git a/pkg/agent/cniserver/ipam/antrea_ipam.go b/pkg/agent/cniserver/ipam/antrea_ipam.go index 3aa3cfc1298..8c4686b8ae8 100644 --- a/pkg/agent/cniserver/ipam/antrea_ipam.go +++ b/pkg/agent/cniserver/ipam/antrea_ipam.go @@ -27,7 +27,7 @@ import ( "k8s.io/klog/v2" "antrea.io/antrea/pkg/agent/cniserver/types" - crdv1a2 "antrea.io/antrea/pkg/apis/crd/v1alpha2" + crdv1b1 "antrea.io/antrea/pkg/apis/crd/v1beta1" "antrea.io/antrea/pkg/ipam/poolallocator" ) @@ -58,8 +58,8 @@ const ( // Resource needs to be unique since it is used as identifier in Del. // Therefore Container ID is used, while Pod/Namespace are shown for visibility. -func getAllocationPodOwner(args *invoke.Args, k8sArgs *types.K8sArgs, reservedOwner *crdv1a2.IPAddressOwner, secondary bool) *crdv1a2.PodOwner { - podOwner := crdv1a2.PodOwner{ +func getAllocationPodOwner(args *invoke.Args, k8sArgs *types.K8sArgs, reservedOwner *crdv1b1.IPAddressOwner, secondary bool) *crdv1b1.PodOwner { + podOwner := crdv1b1.PodOwner{ Name: string(k8sArgs.K8S_POD_NAME), Namespace: string(k8sArgs.K8S_POD_NAMESPACE), ContainerID: args.ContainerID, @@ -72,14 +72,14 @@ func getAllocationPodOwner(args *invoke.Args, k8sArgs *types.K8sArgs, reservedOw return &podOwner } -func getAllocationOwner(args *invoke.Args, k8sArgs *types.K8sArgs, reservedOwner *crdv1a2.IPAddressOwner, secondary bool) *crdv1a2.IPAddressOwner { +func getAllocationOwner(args *invoke.Args, k8sArgs *types.K8sArgs, reservedOwner *crdv1b1.IPAddressOwner, secondary bool) *crdv1b1.IPAddressOwner { podOwner := getAllocationPodOwner(args, k8sArgs, nil, secondary) if reservedOwner != nil { owner := *reservedOwner owner.Pod = podOwner return &owner } - return &crdv1a2.IPAddressOwner{Pod: podOwner} + return &crdv1b1.IPAddressOwner{Pod: podOwner} } // Helper to generate IP config and default route, taking IP version into account @@ -148,14 +148,14 @@ func (d *AntreaIPAM) Add(args *invoke.Args, k8sArgs *types.K8sArgs, networkConfi owner := *getAllocationOwner(args, k8sArgs, reservedOwner, false) var ip net.IP - var subnetInfo *crdv1a2.SubnetInfo + var subnetInfo *crdv1b1.SubnetInfo if reservedOwner != nil { - ip, subnetInfo, err = allocator.AllocateReservedOrNext(crdv1a2.IPAddressPhaseAllocated, owner) + ip, subnetInfo, err = allocator.AllocateReservedOrNext(crdv1b1.IPAddressPhaseAllocated, owner) } else if len(ips) == 0 { - ip, subnetInfo, err = allocator.AllocateNext(crdv1a2.IPAddressPhaseAllocated, owner) + ip, subnetInfo, err = allocator.AllocateNext(crdv1b1.IPAddressPhaseAllocated, owner) } else { ip = ips[0] - subnetInfo, err = allocator.AllocateIP(ip, crdv1a2.IPAddressPhaseAllocated, owner) + subnetInfo, err = allocator.AllocateIP(ip, crdv1b1.IPAddressPhaseAllocated, owner) } if err != nil { return true, nil, err @@ -212,7 +212,7 @@ func (d *AntreaIPAM) Check(args *invoke.Args, k8sArgs *types.K8sArgs, networkCon // the IPAM configuration of the passed CNI network configuration. // It supports IPAM for both Antrea-managed secondary networks and Multus-managed secondary // networks. -func (d *AntreaIPAM) SecondaryNetworkAllocate(podOwner *crdv1a2.PodOwner, networkConfig *types.NetworkConfig) (*IPAMResult, error) { +func (d *AntreaIPAM) SecondaryNetworkAllocate(podOwner *crdv1b1.PodOwner, networkConfig *types.NetworkConfig) (*IPAMResult, error) { ipamConf := networkConfig.IPAM numPools := len(ipamConf.IPPools) @@ -245,9 +245,9 @@ func (d *AntreaIPAM) SecondaryNetworkAllocate(podOwner *crdv1a2.PodOwner, networ } var ip net.IP - var subnetInfo *crdv1a2.SubnetInfo - owner := crdv1a2.IPAddressOwner{Pod: podOwner} - ip, subnetInfo, err = allocator.AllocateNext(crdv1a2.IPAddressPhaseAllocated, owner) + var subnetInfo *crdv1b1.SubnetInfo + owner := crdv1b1.IPAddressOwner{Pod: podOwner} + ip, subnetInfo, err = allocator.AllocateNext(crdv1b1.IPAddressPhaseAllocated, owner) if err != nil { return nil, err } @@ -284,7 +284,7 @@ func (d *AntreaIPAM) SecondaryNetworkAllocate(podOwner *crdv1a2.PodOwner, networ } // SecondaryNetworkRelease releases the IP addresses allocated for a Pod secondary network interface. -func (d *AntreaIPAM) SecondaryNetworkRelease(owner *crdv1a2.PodOwner) error { +func (d *AntreaIPAM) SecondaryNetworkRelease(owner *crdv1b1.PodOwner) error { _, err := d.del(owner) return err } @@ -301,7 +301,7 @@ func (d *AntreaIPAM) secondaryNetworkCheck(args *invoke.Args, k8sArgs *types.K8s return fmt.Errorf("CNI CHECK is not implemented for secondary network") } -func (d *AntreaIPAM) del(podOwner *crdv1a2.PodOwner) (foundAllocation bool, err error) { +func (d *AntreaIPAM) del(podOwner *crdv1b1.PodOwner) (foundAllocation bool, err error) { if err := d.waitForControllerReady(); err != nil { // Return error to let the invoker retry. return false, err @@ -339,7 +339,7 @@ func (d *AntreaIPAM) del(podOwner *crdv1a2.PodOwner) (foundAllocation bool, err // mineTrue + timeout error // mineTrue + IPPoolNotFound error // mineTrue + nil error -func (d *AntreaIPAM) owns(k8sArgs *types.K8sArgs) (mineType, *poolallocator.IPPoolAllocator, []net.IP, *crdv1a2.IPAddressOwner, error) { +func (d *AntreaIPAM) owns(k8sArgs *types.K8sArgs) (mineType, *poolallocator.IPPoolAllocator, []net.IP, *crdv1b1.IPAddressOwner, error) { // Wait controller ready to avoid inappropriate behaviors on the CNI request. if err := d.waitForControllerReady(); err != nil { // Return mineTrue to make this request fail and kubelet will retry. diff --git a/pkg/agent/cniserver/ipam/antrea_ipam_controller.go b/pkg/agent/cniserver/ipam/antrea_ipam_controller.go index 7cc2d7502a4..b2a29db9ce9 100644 --- a/pkg/agent/cniserver/ipam/antrea_ipam_controller.go +++ b/pkg/agent/cniserver/ipam/antrea_ipam_controller.go @@ -26,10 +26,10 @@ import ( "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" - crdv1a2 "antrea.io/antrea/pkg/apis/crd/v1alpha2" + crdv1b1 "antrea.io/antrea/pkg/apis/crd/v1beta1" clientsetversioned "antrea.io/antrea/pkg/client/clientset/versioned" - crdinformers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1alpha2" - crdlisters "antrea.io/antrea/pkg/client/listers/crd/v1alpha2" + crdinformers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1beta1" + crdlisters "antrea.io/antrea/pkg/client/listers/crd/v1beta1" annotation "antrea.io/antrea/pkg/ipam" "antrea.io/antrea/pkg/ipam/poolallocator" "antrea.io/antrea/pkg/util/k8s" @@ -56,7 +56,7 @@ type AntreaIPAMController struct { } func podIndexFunc(obj interface{}) ([]string, error) { - ipPool, ok := obj.(*crdv1a2.IPPool) + ipPool, ok := obj.(*crdv1b1.IPPool) if !ok { return nil, fmt.Errorf("obj is not IPPool: %+v", obj) } @@ -126,9 +126,9 @@ func (c *AntreaIPAMController) Run(stopCh <-chan struct{}) { } // Look up IPPools from the Pod annotation. -func (c *AntreaIPAMController) getIPPoolsByPod(namespace, name string) ([]string, []net.IP, *crdv1a2.IPAddressOwner, error) { +func (c *AntreaIPAMController) getIPPoolsByPod(namespace, name string) ([]string, []net.IP, *crdv1b1.IPAddressOwner, error) { var ips []net.IP - var reservedOwner *crdv1a2.IPAddressOwner + var reservedOwner *crdv1b1.IPAddressOwner pod, err := c.podLister.Pods(namespace).Get(name) if err != nil { return nil, nil, nil, err @@ -176,7 +176,7 @@ ownerReferenceLoop: klog.Warningf("Invalid StatefulSet name: %s", name) break ownerReferenceLoop } - reservedOwner = &crdv1a2.IPAddressOwner{StatefulSet: &crdv1a2.StatefulSetOwner{ + reservedOwner = &crdv1b1.IPAddressOwner{StatefulSet: &crdv1b1.StatefulSetOwner{ Name: statefulSetName, Namespace: namespace, Index: index, @@ -190,7 +190,7 @@ ownerReferenceLoop: } // Look up IPPools from the Pod annotation. -func (c *AntreaIPAMController) getPoolAllocatorByPod(namespace, podName string) (mineType, *poolallocator.IPPoolAllocator, []net.IP, *crdv1a2.IPAddressOwner, error) { +func (c *AntreaIPAMController) getPoolAllocatorByPod(namespace, podName string) (mineType, *poolallocator.IPPoolAllocator, []net.IP, *crdv1b1.IPAddressOwner, error) { poolNames, ips, reservedOwner, err := c.getIPPoolsByPod(namespace, podName) if err != nil { return mineUnknown, nil, nil, nil, err @@ -208,7 +208,7 @@ func (c *AntreaIPAMController) getPoolAllocatorByPod(namespace, podName string) } klog.InfoS("IPPool not found", "pool", p) err = nil - } else if allocator.IPVersion == crdv1a2.IPv4 { + } else if allocator.IPVersion == crdv1b1.IPv4 { // Support IPv6 / dual stack in future. break } @@ -221,12 +221,12 @@ func (c *AntreaIPAMController) getPoolAllocatorByPod(namespace, podName string) } // Look up IPPools by matching PodOwnder. -func (c *AntreaIPAMController) getPoolAllocatorsByOwner(podOwner *crdv1a2.PodOwner) ([]*poolallocator.IPPoolAllocator, error) { +func (c *AntreaIPAMController) getPoolAllocatorsByOwner(podOwner *crdv1b1.PodOwner) ([]*poolallocator.IPPoolAllocator, error) { var allocators []*poolallocator.IPPoolAllocator ipPools, _ := c.ipPoolInformer.Informer().GetIndexer().ByIndex(podIndex, k8s.NamespacedName(podOwner.Namespace, podOwner.Name)) for _, item := range ipPools { - ipPool := item.(*crdv1a2.IPPool) + ipPool := item.(*crdv1b1.IPPool) for _, ipAddress := range ipPool.Status.IPAddresses { savedPod := ipAddress.Owner.Pod if savedPod != nil && savedPod.ContainerID == podOwner.ContainerID && savedPod.IFName == podOwner.IFName { diff --git a/pkg/agent/ipassigner/ip_assigner_linux.go b/pkg/agent/ipassigner/ip_assigner_linux.go index 6256bae61b2..36091d70500 100644 --- a/pkg/agent/ipassigner/ip_assigner_linux.go +++ b/pkg/agent/ipassigner/ip_assigner_linux.go @@ -185,7 +185,7 @@ func (as *assignee) loadIPAddresses() (map[string]*crdv1b1.SubnetInfo, error) { prefixLength, _ := address.Mask.Size() subnetInfo = &crdv1b1.SubnetInfo{ PrefixLength: int32(prefixLength), - VLAN: int32(vlanID), + VLAN: uint16(vlanID), } } assignedIPs[address.IP.String()] = subnetInfo @@ -208,7 +208,7 @@ type ipAssigner struct { // defaultAssignee is the assignee that IPs without VLAN tag will be assigned to. defaultAssignee *assignee // vlanAssignees contains the vlan-based assignees that IPs with VLAN tag will be assigned to, keyed by VLAN ID. - vlanAssignees map[int32]*assignee + vlanAssignees map[uint16]*assignee // assignIPs caches the IPs that have been assigned. // TODO: Add a goroutine to ensure that the cache is in sync with the IPs assigned to the dummy device in case the // IPs are removed by users accidentally. @@ -229,7 +229,7 @@ func NewIPAssigner(nodeTransportInterface string, dummyDeviceName string) (IPAss logicalInterface: externalInterface, ips: sets.New[string](), }, - vlanAssignees: map[int32]*assignee{}, + vlanAssignees: map[uint16]*assignee{}, } if ipv4 != nil { // For the Egress scenario, the external IPs should always be present on the dummy @@ -265,7 +265,7 @@ func NewIPAssigner(nodeTransportInterface string, dummyDeviceName string) (IPAss return nil, fmt.Errorf("error when getting vlan devices: %w", err) } for _, vlan := range vlans { - a.addVLANAssignee(vlan, int32(vlan.VlanId)) + a.addVLANAssignee(vlan, uint16(vlan.VlanId)) } return a, nil } @@ -515,7 +515,7 @@ func (a *ipAssigner) getAssignee(subnetInfo *crdv1b1.SubnetInfo, createIfNotExis return as, nil } -func (a *ipAssigner) addVLANAssignee(link netlink.Link, vlan int32) (*assignee, error) { +func (a *ipAssigner) addVLANAssignee(link netlink.Link, vlan uint16) (*assignee, error) { if err := netlink.LinkSetUp(link); err != nil { return nil, fmt.Errorf("error setting up interface %v", link) } diff --git a/pkg/agent/secondarynetwork/podwatch/controller.go b/pkg/agent/secondarynetwork/podwatch/controller.go index fd6d9f8c500..05ad9024355 100644 --- a/pkg/agent/secondarynetwork/podwatch/controller.go +++ b/pkg/agent/secondarynetwork/podwatch/controller.go @@ -40,7 +40,7 @@ import ( cnitypes "antrea.io/antrea/pkg/agent/cniserver/types" cnipodcache "antrea.io/antrea/pkg/agent/secondarynetwork/cnipodcache" "antrea.io/antrea/pkg/agent/types" - crdv1a2 "antrea.io/antrea/pkg/apis/crd/v1alpha2" + crdv1b1 "antrea.io/antrea/pkg/apis/crd/v1beta1" "antrea.io/antrea/pkg/ovs/ovsconfig" "antrea.io/antrea/pkg/util/channel" ) @@ -72,8 +72,8 @@ type InterfaceConfigurator interface { } type IPAMAllocator interface { - SecondaryNetworkAllocate(podOwner *crdv1a2.PodOwner, networkConfig *cnitypes.NetworkConfig) (*ipam.IPAMResult, error) - SecondaryNetworkRelease(podOwner *crdv1a2.PodOwner) error + SecondaryNetworkAllocate(podOwner *crdv1b1.PodOwner, networkConfig *cnitypes.NetworkConfig) (*ipam.IPAMResult, error) + SecondaryNetworkRelease(podOwner *crdv1b1.PodOwner) error } type PodController struct { @@ -165,7 +165,7 @@ func (pc *PodController) deletePodSecondaryNetwork(podCNIInfo *cnipodcache.CNICo } } - podOwner := &crdv1a2.PodOwner{ + podOwner := &crdv1b1.PodOwner{ Name: podCNIInfo.PodName, Namespace: podCNIInfo.PodNamespace, ContainerID: podCNIInfo.ContainerID, @@ -344,7 +344,7 @@ func (pc *PodController) configureSecondaryInterface( var vlanID uint16 var ifConfigErr error if networkConfig.IPAM != nil { - podOwner := &crdv1a2.PodOwner{ + podOwner := &crdv1b1.PodOwner{ Name: pod.Name, Namespace: pod.Namespace, ContainerID: podCNIInfo.ContainerID, diff --git a/pkg/agent/secondarynetwork/podwatch/testing/mock_podwatch.go b/pkg/agent/secondarynetwork/podwatch/testing/mock_podwatch.go index 149efe2dff6..2ae9be06715 100644 --- a/pkg/agent/secondarynetwork/podwatch/testing/mock_podwatch.go +++ b/pkg/agent/secondarynetwork/podwatch/testing/mock_podwatch.go @@ -1,4 +1,4 @@ -// Copyright 2023 Antrea Authors +// Copyright 2024 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import ( ipam "antrea.io/antrea/pkg/agent/cniserver/ipam" types "antrea.io/antrea/pkg/agent/cniserver/types" - v1alpha2 "antrea.io/antrea/pkg/apis/crd/v1alpha2" + v1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" types100 "github.com/containernetworking/cni/pkg/types/100" gomock "go.uber.org/mock/gomock" ) @@ -123,7 +123,7 @@ func (m *MockIPAMAllocator) EXPECT() *MockIPAMAllocatorMockRecorder { } // SecondaryNetworkAllocate mocks base method. -func (m *MockIPAMAllocator) SecondaryNetworkAllocate(arg0 *v1alpha2.PodOwner, arg1 *types.NetworkConfig) (*ipam.IPAMResult, error) { +func (m *MockIPAMAllocator) SecondaryNetworkAllocate(arg0 *v1beta1.PodOwner, arg1 *types.NetworkConfig) (*ipam.IPAMResult, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SecondaryNetworkAllocate", arg0, arg1) ret0, _ := ret[0].(*ipam.IPAMResult) @@ -138,7 +138,7 @@ func (mr *MockIPAMAllocatorMockRecorder) SecondaryNetworkAllocate(arg0, arg1 any } // SecondaryNetworkRelease mocks base method. -func (m *MockIPAMAllocator) SecondaryNetworkRelease(arg0 *v1alpha2.PodOwner) error { +func (m *MockIPAMAllocator) SecondaryNetworkRelease(arg0 *v1beta1.PodOwner) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SecondaryNetworkRelease", arg0) ret0, _ := ret[0].(error) diff --git a/pkg/apis/crd/v1beta1/register.go b/pkg/apis/crd/v1beta1/register.go index a877e443a7e..a5625a76335 100644 --- a/pkg/apis/crd/v1beta1/register.go +++ b/pkg/apis/crd/v1beta1/register.go @@ -62,6 +62,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &EgressList{}, &Traceflow{}, &TraceflowList{}, + &IPPool{}, + &IPPoolList{}, ) metav1.AddToGroupVersion( diff --git a/pkg/apis/crd/v1beta1/types.go b/pkg/apis/crd/v1beta1/types.go index 46c1280d883..6c09355786a 100644 --- a/pkg/apis/crd/v1beta1/types.go +++ b/pkg/apis/crd/v1beta1/types.go @@ -201,6 +201,7 @@ type ExternalIPPool struct { metav1.ObjectMeta `json:"metadata,omitempty"` // Specification of the ExternalIPPool. + Spec ExternalIPPoolSpec `json:"spec"` // The current status of the ExternalIPPool. @@ -234,7 +235,7 @@ type SubnetInfo struct { // Prefix length for the subnet, e.g. 24. PrefixLength int32 `json:"prefixLength"` // VLAN ID for this subnet. Default is 0. Valid value is 0~4094. - VLAN int32 `json:"vlan,omitempty"` + VLAN uint16 `json:"vlan,omitempty"` } type ExternalIPPoolStatus struct { @@ -262,6 +263,95 @@ type IPPoolUsage struct { // +genclient:nonNamespaced // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// IPPool defines one or multiple IP sets that can be used for flexible IPAM feature. For instance, the IPs can be +// allocated to Pods according to IP pool specified in Deployment annotation. +type IPPool struct { + metav1.TypeMeta `json:",inline"` + // Standard metadata of the object. + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Specification of the IPPool. + Spec IPPoolSpec `json:"spec"` + + // Most recently observed status of the pool. + Status IPPoolStatus `json:"status"` +} + +type IPVersion int + +const ( + IPv4 = IPVersion(4) + IPv6 = IPVersion(6) +) + +type IPPoolSpec struct { + // IP Version for this IP pool - either 4 or 6 + IPVersion IPVersion `json:"ipVersion"` + // The IP ranges of this IP pool, e.g. 10.10.0.0/24, 10.10.10.2-10.10.10.20, 10.10.10.30-10.10.10.30. + IPRanges []IPRange `json:"ipRanges"` + // The Subnet info of this IP pool. If set, all IP ranges in the IP pool should share the same subnet attributes. + SubnetInfo *SubnetInfo `json:"subnetInfo,omitempty"` +} + +type IPPoolStatus struct { + IPAddresses []IPAddressState `json:"ipAddresses,omitempty"` + Usage IPPoolUsage `json:"usage,omitempty"` +} + +type IPAddressPhase string + +const ( + IPAddressPhaseAllocated IPAddressPhase = "Allocated" + IPAddressPhasePreallocated IPAddressPhase = "Preallocated" + IPAddressPhaseReserved IPAddressPhase = "Reserved" +) + +type IPAddressState struct { + // IP Address this entry is tracking + IPAddress string `json:"ipAddress"` + // Allocation state - either Allocated or Preallocated + Phase IPAddressPhase `json:"phase"` + // Owner this IP Address is allocated to + Owner IPAddressOwner `json:"owner"` + // TODO: add usage statistics (consistent with ExternalIPPool status) +} + +type IPAddressOwner struct { + Pod *PodOwner `json:"pod,omitempty"` + StatefulSet *StatefulSetOwner `json:"statefulSet,omitempty"` +} + +// Pod owner +type PodOwner struct { + Name string `json:"name"` + Namespace string `json:"namespace"` + ContainerID string `json:"containerID"` + // Network interface name. Used when the IP is allocated for a secondary network interface + // of the Pod. + IFName string `json:"ifName,omitempty"` +} + +// StatefulSet owner +type StatefulSetOwner struct { + Name string `json:"name"` + Namespace string `json:"namespace"` + Index int `json:"index"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type IPPoolList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata,omitempty"` + + Items []IPPool `json:"items"` +} + +// +genclient +// +genclient:nonNamespaced +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + type ClusterGroup struct { metav1.TypeMeta `json:",inline"` // Standard metadata of the object. diff --git a/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go b/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go index 7cde65971e8..d9c28d700d5 100644 --- a/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Copyright 2023 Antrea Authors +// Copyright 2024 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -911,6 +911,49 @@ func (in *IGMPProtocol) DeepCopy() *IGMPProtocol { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPAddressOwner) DeepCopyInto(out *IPAddressOwner) { + *out = *in + if in.Pod != nil { + in, out := &in.Pod, &out.Pod + *out = new(PodOwner) + **out = **in + } + if in.StatefulSet != nil { + in, out := &in.StatefulSet, &out.StatefulSet + *out = new(StatefulSetOwner) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPAddressOwner. +func (in *IPAddressOwner) DeepCopy() *IPAddressOwner { + if in == nil { + return nil + } + out := new(IPAddressOwner) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPAddressState) DeepCopyInto(out *IPAddressState) { + *out = *in + in.Owner.DeepCopyInto(&out.Owner) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPAddressState. +func (in *IPAddressState) DeepCopy() *IPAddressState { + if in == nil { + return nil + } + out := new(IPAddressState) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *IPBlock) DeepCopyInto(out *IPBlock) { *out = *in @@ -943,6 +986,117 @@ func (in *IPHeader) DeepCopy() *IPHeader { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPPool) DeepCopyInto(out *IPPool) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPPool. +func (in *IPPool) DeepCopy() *IPPool { + if in == nil { + return nil + } + out := new(IPPool) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *IPPool) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPPoolList) DeepCopyInto(out *IPPoolList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]IPPool, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPPoolList. +func (in *IPPoolList) DeepCopy() *IPPoolList { + if in == nil { + return nil + } + out := new(IPPoolList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *IPPoolList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPPoolSpec) DeepCopyInto(out *IPPoolSpec) { + *out = *in + if in.IPRanges != nil { + in, out := &in.IPRanges, &out.IPRanges + *out = make([]IPRange, len(*in)) + copy(*out, *in) + } + if in.SubnetInfo != nil { + in, out := &in.SubnetInfo, &out.SubnetInfo + *out = new(SubnetInfo) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPPoolSpec. +func (in *IPPoolSpec) DeepCopy() *IPPoolSpec { + if in == nil { + return nil + } + out := new(IPPoolSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPPoolStatus) DeepCopyInto(out *IPPoolStatus) { + *out = *in + if in.IPAddresses != nil { + in, out := &in.IPAddresses, &out.IPAddresses + *out = make([]IPAddressState, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + out.Usage = in.Usage + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPPoolStatus. +func (in *IPPoolStatus) DeepCopy() *IPPoolStatus { + if in == nil { + return nil + } + out := new(IPPoolStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *IPPoolUsage) DeepCopyInto(out *IPPoolUsage) { *out = *in @@ -1429,6 +1583,22 @@ func (in *PeerService) DeepCopy() *PeerService { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PodOwner) DeepCopyInto(out *PodOwner) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodOwner. +func (in *PodOwner) DeepCopy() *PodOwner { + if in == nil { + return nil + } + out := new(PodOwner) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Rule) DeepCopyInto(out *Rule) { *out = *in @@ -1513,6 +1683,22 @@ func (in *Source) DeepCopy() *Source { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *StatefulSetOwner) DeepCopyInto(out *StatefulSetOwner) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StatefulSetOwner. +func (in *StatefulSetOwner) DeepCopy() *StatefulSetOwner { + if in == nil { + return nil + } + out := new(StatefulSetOwner) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SubnetInfo) DeepCopyInto(out *SubnetInfo) { *out = *in diff --git a/pkg/apiserver/openapi/zz_generated.openapi.go b/pkg/apiserver/openapi/zz_generated.openapi.go index 398e4641bd8..fdfcafe189a 100644 --- a/pkg/apiserver/openapi/zz_generated.openapi.go +++ b/pkg/apiserver/openapi/zz_generated.openapi.go @@ -106,8 +106,14 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "antrea.io/antrea/pkg/apis/crd/v1beta1.ICMPEchoRequestHeader": schema_pkg_apis_crd_v1beta1_ICMPEchoRequestHeader(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.ICMPProtocol": schema_pkg_apis_crd_v1beta1_ICMPProtocol(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.IGMPProtocol": schema_pkg_apis_crd_v1beta1_IGMPProtocol(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.IPAddressOwner": schema_pkg_apis_crd_v1beta1_IPAddressOwner(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.IPAddressState": schema_pkg_apis_crd_v1beta1_IPAddressState(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.IPBlock": schema_pkg_apis_crd_v1beta1_IPBlock(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.IPHeader": schema_pkg_apis_crd_v1beta1_IPHeader(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.IPPool": schema_pkg_apis_crd_v1beta1_IPPool(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.IPPoolList": schema_pkg_apis_crd_v1beta1_IPPoolList(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.IPPoolSpec": schema_pkg_apis_crd_v1beta1_IPPoolSpec(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.IPPoolStatus": schema_pkg_apis_crd_v1beta1_IPPoolStatus(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.IPPoolUsage": schema_pkg_apis_crd_v1beta1_IPPoolUsage(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.IPRange": schema_pkg_apis_crd_v1beta1_IPRange(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.IPv6Header": schema_pkg_apis_crd_v1beta1_IPv6Header(ref), @@ -128,8 +134,10 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "antrea.io/antrea/pkg/apis/crd/v1beta1.Packet": schema_pkg_apis_crd_v1beta1_Packet(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.PeerNamespaces": schema_pkg_apis_crd_v1beta1_PeerNamespaces(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.PeerService": schema_pkg_apis_crd_v1beta1_PeerService(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.PodOwner": schema_pkg_apis_crd_v1beta1_PodOwner(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.Rule": schema_pkg_apis_crd_v1beta1_Rule(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.Source": schema_pkg_apis_crd_v1beta1_Source(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.StatefulSetOwner": schema_pkg_apis_crd_v1beta1_StatefulSetOwner(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.SubnetInfo": schema_pkg_apis_crd_v1beta1_SubnetInfo(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.TCPHeader": schema_pkg_apis_crd_v1beta1_TCPHeader(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.TLSProtocol": schema_pkg_apis_crd_v1beta1_TLSProtocol(ref), @@ -3678,9 +3686,8 @@ func schema_pkg_apis_crd_v1beta1_ExternalIPPool(ref common.ReferenceCallback) co }, "spec": { SchemaProps: spec.SchemaProps{ - Description: "Specification of the ExternalIPPool.", - Default: map[string]interface{}{}, - Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.ExternalIPPoolSpec"), + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.ExternalIPPoolSpec"), }, }, "status": { @@ -4148,6 +4155,68 @@ func schema_pkg_apis_crd_v1beta1_IGMPProtocol(ref common.ReferenceCallback) comm } } +func schema_pkg_apis_crd_v1beta1_IPAddressOwner(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "pod": { + SchemaProps: spec.SchemaProps{ + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.PodOwner"), + }, + }, + "statefulSet": { + SchemaProps: spec.SchemaProps{ + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.StatefulSetOwner"), + }, + }, + }, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.PodOwner", "antrea.io/antrea/pkg/apis/crd/v1beta1.StatefulSetOwner"}, + } +} + +func schema_pkg_apis_crd_v1beta1_IPAddressState(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "ipAddress": { + SchemaProps: spec.SchemaProps{ + Description: "IP Address this entry is tracking", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "phase": { + SchemaProps: spec.SchemaProps{ + Description: "Allocation state - either Allocated or Preallocated", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "owner": { + SchemaProps: spec.SchemaProps{ + Description: "Owner this IP Address is allocated to", + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.IPAddressOwner"), + }, + }, + }, + Required: []string{"ipAddress", "phase", "owner"}, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.IPAddressOwner"}, + } +} + func schema_pkg_apis_crd_v1beta1_IPBlock(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -4204,6 +4273,181 @@ func schema_pkg_apis_crd_v1beta1_IPHeader(ref common.ReferenceCallback) common.O } } +func schema_pkg_apis_crd_v1beta1_IPPool(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "IPPool defines one or multiple IP sets that can be used for flexible IPAM feature. For instance, the IPs can be allocated to Pods according to IP pool specified in Deployment annotation.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Description: "Standard metadata of the object.", + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), + }, + }, + "spec": { + SchemaProps: spec.SchemaProps{ + Description: "Specification of the IPPool.", + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.IPPoolSpec"), + }, + }, + "status": { + SchemaProps: spec.SchemaProps{ + Description: "Most recently observed status of the pool.", + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.IPPoolStatus"), + }, + }, + }, + Required: []string{"spec", "status"}, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.IPPoolSpec", "antrea.io/antrea/pkg/apis/crd/v1beta1.IPPoolStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, + } +} + +func schema_pkg_apis_crd_v1beta1_IPPoolList(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), + }, + }, + "items": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.IPPool"), + }, + }, + }, + }, + }, + }, + Required: []string{"items"}, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.IPPool", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, + } +} + +func schema_pkg_apis_crd_v1beta1_IPPoolSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "ipVersion": { + SchemaProps: spec.SchemaProps{ + Description: "IP Version for this IP pool - either 4 or 6", + Default: 0, + Type: []string{"integer"}, + Format: "int32", + }, + }, + "ipRanges": { + SchemaProps: spec.SchemaProps{ + Description: "The IP ranges of this IP pool, e.g. 10.10.0.0/24, 10.10.10.2-10.10.10.20, 10.10.10.30-10.10.10.30.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.IPRange"), + }, + }, + }, + }, + }, + "subnetInfo": { + SchemaProps: spec.SchemaProps{ + Description: "The Subnet info of this IP pool. If set, all IP ranges in the IP pool should share the same subnet attributes.", + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.SubnetInfo"), + }, + }, + }, + Required: []string{"ipVersion", "ipRanges"}, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.IPRange", "antrea.io/antrea/pkg/apis/crd/v1beta1.SubnetInfo"}, + } +} + +func schema_pkg_apis_crd_v1beta1_IPPoolStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "ipAddresses": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.IPAddressState"), + }, + }, + }, + }, + }, + "usage": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.IPPoolUsage"), + }, + }, + }, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.IPAddressState", "antrea.io/antrea/pkg/apis/crd/v1beta1.IPPoolUsage"}, + } +} + func schema_pkg_apis_crd_v1beta1_IPPoolUsage(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -5109,6 +5353,48 @@ func schema_pkg_apis_crd_v1beta1_PeerService(ref common.ReferenceCallback) commo } } +func schema_pkg_apis_crd_v1beta1_PodOwner(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Pod owner", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "name": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "namespace": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "containerID": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "ifName": { + SchemaProps: spec.SchemaProps{ + Description: "Network interface name. Used when the IP is allocated for a secondary network interface of the Pod.", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"name", "namespace", "containerID"}, + }, + }, + } +} + func schema_pkg_apis_crd_v1beta1_Rule(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -5286,6 +5572,41 @@ func schema_pkg_apis_crd_v1beta1_Source(ref common.ReferenceCallback) common.Ope } } +func schema_pkg_apis_crd_v1beta1_StatefulSetOwner(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "StatefulSet owner", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "name": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "namespace": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "index": { + SchemaProps: spec.SchemaProps{ + Default: 0, + Type: []string{"integer"}, + Format: "int32", + }, + }, + }, + Required: []string{"name", "namespace", "index"}, + }, + }, + } +} + func schema_pkg_apis_crd_v1beta1_SubnetInfo(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/crd_client.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/crd_client.go index 3f2acf2865a..5fc932db09e 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1beta1/crd_client.go +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/crd_client.go @@ -1,4 +1,4 @@ -// Copyright 2023 Antrea Authors +// Copyright 2024 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ type CrdV1beta1Interface interface { EgressesGetter ExternalIPPoolsGetter GroupsGetter + IPPoolsGetter NetworkPoliciesGetter TiersGetter TraceflowsGetter @@ -71,6 +72,10 @@ func (c *CrdV1beta1Client) Groups(namespace string) GroupInterface { return newGroups(c, namespace) } +func (c *CrdV1beta1Client) IPPools() IPPoolInterface { + return newIPPools(c) +} + func (c *CrdV1beta1Client) NetworkPolicies(namespace string) NetworkPolicyInterface { return newNetworkPolicies(c, namespace) } diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_crd_client.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_crd_client.go index d0f2bc6465c..a4de04a1e63 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_crd_client.go +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_crd_client.go @@ -1,4 +1,4 @@ -// Copyright 2023 Antrea Authors +// Copyright 2024 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -54,6 +54,10 @@ func (c *FakeCrdV1beta1) Groups(namespace string) v1beta1.GroupInterface { return &FakeGroups{c, namespace} } +func (c *FakeCrdV1beta1) IPPools() v1beta1.IPPoolInterface { + return &FakeIPPools{c} +} + func (c *FakeCrdV1beta1) NetworkPolicies(namespace string) v1beta1.NetworkPolicyInterface { return &FakeNetworkPolicies{c, namespace} } diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_ippool.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_ippool.go new file mode 100644 index 00000000000..bc894bf81cc --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_ippool.go @@ -0,0 +1,131 @@ +// Copyright 2024 Antrea Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeIPPools implements IPPoolInterface +type FakeIPPools struct { + Fake *FakeCrdV1beta1 +} + +var ippoolsResource = schema.GroupVersionResource{Group: "crd.antrea.io", Version: "v1beta1", Resource: "ippools"} + +var ippoolsKind = schema.GroupVersionKind{Group: "crd.antrea.io", Version: "v1beta1", Kind: "IPPool"} + +// Get takes name of the iPPool, and returns the corresponding iPPool object, and an error if there is any. +func (c *FakeIPPools) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.IPPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(ippoolsResource, name), &v1beta1.IPPool{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.IPPool), err +} + +// List takes label and field selectors, and returns the list of IPPools that match those selectors. +func (c *FakeIPPools) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.IPPoolList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(ippoolsResource, ippoolsKind, opts), &v1beta1.IPPoolList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1beta1.IPPoolList{ListMeta: obj.(*v1beta1.IPPoolList).ListMeta} + for _, item := range obj.(*v1beta1.IPPoolList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested iPPools. +func (c *FakeIPPools) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(ippoolsResource, opts)) +} + +// Create takes the representation of a iPPool and creates it. Returns the server's representation of the iPPool, and an error, if there is any. +func (c *FakeIPPools) Create(ctx context.Context, iPPool *v1beta1.IPPool, opts v1.CreateOptions) (result *v1beta1.IPPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(ippoolsResource, iPPool), &v1beta1.IPPool{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.IPPool), err +} + +// Update takes the representation of a iPPool and updates it. Returns the server's representation of the iPPool, and an error, if there is any. +func (c *FakeIPPools) Update(ctx context.Context, iPPool *v1beta1.IPPool, opts v1.UpdateOptions) (result *v1beta1.IPPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(ippoolsResource, iPPool), &v1beta1.IPPool{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.IPPool), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeIPPools) UpdateStatus(ctx context.Context, iPPool *v1beta1.IPPool, opts v1.UpdateOptions) (*v1beta1.IPPool, error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceAction(ippoolsResource, "status", iPPool), &v1beta1.IPPool{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.IPPool), err +} + +// Delete takes name of the iPPool and deletes it. Returns an error if one occurs. +func (c *FakeIPPools) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteActionWithOptions(ippoolsResource, name, opts), &v1beta1.IPPool{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeIPPools) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(ippoolsResource, listOpts) + + _, err := c.Fake.Invokes(action, &v1beta1.IPPoolList{}) + return err +} + +// Patch applies the patch and returns the patched iPPool. +func (c *FakeIPPools) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.IPPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(ippoolsResource, name, pt, data, subresources...), &v1beta1.IPPool{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.IPPool), err +} diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/generated_expansion.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/generated_expansion.go index 1f342dbf880..d28257ca7bc 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1beta1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/generated_expansion.go @@ -1,4 +1,4 @@ -// Copyright 2023 Antrea Authors +// Copyright 2024 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -30,6 +30,8 @@ type ExternalIPPoolExpansion interface{} type GroupExpansion interface{} +type IPPoolExpansion interface{} + type NetworkPolicyExpansion interface{} type TierExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/ippool.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/ippool.go new file mode 100644 index 00000000000..d1e241ec286 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/ippool.go @@ -0,0 +1,182 @@ +// Copyright 2024 Antrea Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + "time" + + v1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" + scheme "antrea.io/antrea/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// IPPoolsGetter has a method to return a IPPoolInterface. +// A group's client should implement this interface. +type IPPoolsGetter interface { + IPPools() IPPoolInterface +} + +// IPPoolInterface has methods to work with IPPool resources. +type IPPoolInterface interface { + Create(ctx context.Context, iPPool *v1beta1.IPPool, opts v1.CreateOptions) (*v1beta1.IPPool, error) + Update(ctx context.Context, iPPool *v1beta1.IPPool, opts v1.UpdateOptions) (*v1beta1.IPPool, error) + UpdateStatus(ctx context.Context, iPPool *v1beta1.IPPool, opts v1.UpdateOptions) (*v1beta1.IPPool, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.IPPool, error) + List(ctx context.Context, opts v1.ListOptions) (*v1beta1.IPPoolList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.IPPool, err error) + IPPoolExpansion +} + +// iPPools implements IPPoolInterface +type iPPools struct { + client rest.Interface +} + +// newIPPools returns a IPPools +func newIPPools(c *CrdV1beta1Client) *iPPools { + return &iPPools{ + client: c.RESTClient(), + } +} + +// Get takes name of the iPPool, and returns the corresponding iPPool object, and an error if there is any. +func (c *iPPools) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.IPPool, err error) { + result = &v1beta1.IPPool{} + err = c.client.Get(). + Resource("ippools"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of IPPools that match those selectors. +func (c *iPPools) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.IPPoolList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1beta1.IPPoolList{} + err = c.client.Get(). + Resource("ippools"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested iPPools. +func (c *iPPools) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Resource("ippools"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a iPPool and creates it. Returns the server's representation of the iPPool, and an error, if there is any. +func (c *iPPools) Create(ctx context.Context, iPPool *v1beta1.IPPool, opts v1.CreateOptions) (result *v1beta1.IPPool, err error) { + result = &v1beta1.IPPool{} + err = c.client.Post(). + Resource("ippools"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(iPPool). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a iPPool and updates it. Returns the server's representation of the iPPool, and an error, if there is any. +func (c *iPPools) Update(ctx context.Context, iPPool *v1beta1.IPPool, opts v1.UpdateOptions) (result *v1beta1.IPPool, err error) { + result = &v1beta1.IPPool{} + err = c.client.Put(). + Resource("ippools"). + Name(iPPool.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(iPPool). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *iPPools) UpdateStatus(ctx context.Context, iPPool *v1beta1.IPPool, opts v1.UpdateOptions) (result *v1beta1.IPPool, err error) { + result = &v1beta1.IPPool{} + err = c.client.Put(). + Resource("ippools"). + Name(iPPool.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(iPPool). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the iPPool and deletes it. Returns an error if one occurs. +func (c *iPPools) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Resource("ippools"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *iPPools) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Resource("ippools"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched iPPool. +func (c *iPPools) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.IPPool, err error) { + result = &v1beta1.IPPool{} + err = c.client.Patch(pt). + Resource("ippools"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/client/informers/externalversions/crd/v1beta1/interface.go b/pkg/client/informers/externalversions/crd/v1beta1/interface.go index 04d14abffbd..565b52aa2f3 100644 --- a/pkg/client/informers/externalversions/crd/v1beta1/interface.go +++ b/pkg/client/informers/externalversions/crd/v1beta1/interface.go @@ -1,4 +1,4 @@ -// Copyright 2023 Antrea Authors +// Copyright 2024 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -36,6 +36,8 @@ type Interface interface { ExternalIPPools() ExternalIPPoolInformer // Groups returns a GroupInformer. Groups() GroupInformer + // IPPools returns a IPPoolInformer. + IPPools() IPPoolInformer // NetworkPolicies returns a NetworkPolicyInformer. NetworkPolicies() NetworkPolicyInformer // Tiers returns a TierInformer. @@ -90,6 +92,11 @@ func (v *version) Groups() GroupInformer { return &groupInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } +// IPPools returns a IPPoolInformer. +func (v *version) IPPools() IPPoolInformer { + return &iPPoolInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + // NetworkPolicies returns a NetworkPolicyInformer. func (v *version) NetworkPolicies() NetworkPolicyInformer { return &networkPolicyInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} diff --git a/pkg/client/informers/externalversions/crd/v1beta1/ippool.go b/pkg/client/informers/externalversions/crd/v1beta1/ippool.go new file mode 100644 index 00000000000..d9d53317d31 --- /dev/null +++ b/pkg/client/informers/externalversions/crd/v1beta1/ippool.go @@ -0,0 +1,87 @@ +// Copyright 2024 Antrea Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by informer-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + time "time" + + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" + versioned "antrea.io/antrea/pkg/client/clientset/versioned" + internalinterfaces "antrea.io/antrea/pkg/client/informers/externalversions/internalinterfaces" + v1beta1 "antrea.io/antrea/pkg/client/listers/crd/v1beta1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// IPPoolInformer provides access to a shared informer and lister for +// IPPools. +type IPPoolInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1beta1.IPPoolLister +} + +type iPPoolInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewIPPoolInformer constructs a new informer for IPPool type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewIPPoolInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredIPPoolInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredIPPoolInformer constructs a new informer for IPPool type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredIPPoolInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CrdV1beta1().IPPools().List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CrdV1beta1().IPPools().Watch(context.TODO(), options) + }, + }, + &crdv1beta1.IPPool{}, + resyncPeriod, + indexers, + ) +} + +func (f *iPPoolInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredIPPoolInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *iPPoolInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&crdv1beta1.IPPool{}, f.defaultInformer) +} + +func (f *iPPoolInformer) Lister() v1beta1.IPPoolLister { + return v1beta1.NewIPPoolLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index b5e7ce3c762..adb56d4a901 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -1,4 +1,4 @@ -// Copyright 2023 Antrea Authors +// Copyright 2024 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -102,6 +102,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1beta1().ExternalIPPools().Informer()}, nil case v1beta1.SchemeGroupVersion.WithResource("groups"): return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1beta1().Groups().Informer()}, nil + case v1beta1.SchemeGroupVersion.WithResource("ippools"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1beta1().IPPools().Informer()}, nil case v1beta1.SchemeGroupVersion.WithResource("networkpolicies"): return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1beta1().NetworkPolicies().Informer()}, nil case v1beta1.SchemeGroupVersion.WithResource("tiers"): diff --git a/pkg/client/listers/crd/v1beta1/expansion_generated.go b/pkg/client/listers/crd/v1beta1/expansion_generated.go index 2c926b25b79..4cc93607b0b 100644 --- a/pkg/client/listers/crd/v1beta1/expansion_generated.go +++ b/pkg/client/listers/crd/v1beta1/expansion_generated.go @@ -1,4 +1,4 @@ -// Copyright 2023 Antrea Authors +// Copyright 2024 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -48,6 +48,10 @@ type GroupListerExpansion interface{} // GroupNamespaceLister. type GroupNamespaceListerExpansion interface{} +// IPPoolListerExpansion allows custom methods to be added to +// IPPoolLister. +type IPPoolListerExpansion interface{} + // NetworkPolicyListerExpansion allows custom methods to be added to // NetworkPolicyLister. type NetworkPolicyListerExpansion interface{} diff --git a/pkg/client/listers/crd/v1beta1/ippool.go b/pkg/client/listers/crd/v1beta1/ippool.go new file mode 100644 index 00000000000..e060d0634ef --- /dev/null +++ b/pkg/client/listers/crd/v1beta1/ippool.go @@ -0,0 +1,66 @@ +// Copyright 2024 Antrea Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by lister-gen. DO NOT EDIT. + +package v1beta1 + +import ( + v1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// IPPoolLister helps list IPPools. +// All objects returned here must be treated as read-only. +type IPPoolLister interface { + // List lists all IPPools in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1beta1.IPPool, err error) + // Get retrieves the IPPool from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1beta1.IPPool, error) + IPPoolListerExpansion +} + +// iPPoolLister implements the IPPoolLister interface. +type iPPoolLister struct { + indexer cache.Indexer +} + +// NewIPPoolLister returns a new IPPoolLister. +func NewIPPoolLister(indexer cache.Indexer) IPPoolLister { + return &iPPoolLister{indexer: indexer} +} + +// List lists all IPPools in the indexer. +func (s *iPPoolLister) List(selector labels.Selector) (ret []*v1beta1.IPPool, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1beta1.IPPool)) + }) + return ret, err +} + +// Get retrieves the IPPool from the index for a given name. +func (s *iPPoolLister) Get(name string) (*v1beta1.IPPool, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1beta1.Resource("ippool"), name) + } + return obj.(*v1beta1.IPPool), nil +} diff --git a/pkg/controller/ipam/antrea_ipam_controller.go b/pkg/controller/ipam/antrea_ipam_controller.go index cba3abcf078..8f8e0fa9935 100644 --- a/pkg/controller/ipam/antrea_ipam_controller.go +++ b/pkg/controller/ipam/antrea_ipam_controller.go @@ -36,10 +36,10 @@ import ( "k8s.io/client-go/util/workqueue" "k8s.io/klog/v2" - crdv1a2 "antrea.io/antrea/pkg/apis/crd/v1alpha2" + crdv1b1 "antrea.io/antrea/pkg/apis/crd/v1beta1" "antrea.io/antrea/pkg/client/clientset/versioned" - crdinformers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1alpha2" - crdlisters "antrea.io/antrea/pkg/client/listers/crd/v1alpha2" + crdinformers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1beta1" + crdlisters "antrea.io/antrea/pkg/client/listers/crd/v1beta1" annotation "antrea.io/antrea/pkg/ipam" "antrea.io/antrea/pkg/ipam/poolallocator" "antrea.io/antrea/pkg/util/k8s" @@ -92,7 +92,7 @@ type AntreaIPAMController struct { } func statefulSetIndexFunc(obj interface{}) ([]string, error) { - ipPool, ok := obj.(*crdv1a2.IPPool) + ipPool, ok := obj.(*crdv1b1.IPPool) if !ok { return nil, fmt.Errorf("obj is not IPPool: %+v", obj) } @@ -180,7 +180,7 @@ func (c *AntreaIPAMController) cleanupStaleAddresses() { for _, ipPool := range pools { updateNeeded := false ipPoolCopy := ipPool.DeepCopy() - var newList []crdv1a2.IPAddressState + var newList []crdv1b1.IPAddressState for _, address := range ipPoolCopy.Status.IPAddresses { // Cleanup reserved addresses if address.Owner.Pod != nil { @@ -189,7 +189,7 @@ func (c *AntreaIPAMController) cleanupStaleAddresses() { klog.InfoS("IPPool contains stale IPAddress for Pod that no longer exists", "IPPool", ipPool.Name, "Namespace", address.Owner.Pod.Namespace, "Pod", address.Owner.Pod.Name) address.Owner.Pod = nil if address.Owner.StatefulSet != nil { - address.Phase = crdv1a2.IPAddressPhaseReserved + address.Phase = crdv1b1.IPAddressPhaseReserved } updateNeeded = true } @@ -212,7 +212,7 @@ func (c *AntreaIPAMController) cleanupStaleAddresses() { if updateNeeded { ipPoolCopy.Status.IPAddresses = newList - _, err := c.crdClient.CrdV1alpha2().IPPools().UpdateStatus(context.TODO(), ipPoolCopy, metav1.UpdateOptions{}) + _, err := c.crdClient.CrdV1beta1().IPPools().UpdateStatus(context.TODO(), ipPoolCopy, metav1.UpdateOptions{}) if err != nil { // Next cleanup job will retry klog.ErrorS(err, "Updating IP Pool status failed", "IPPool", ipPool.Name) @@ -233,7 +233,7 @@ func (c *AntreaIPAMController) cleanIPPoolForStatefulSet(namespacedName string) ipPools, _ := c.ipPoolInformer.Informer().GetIndexer().ByIndex(statefulSetIndex, namespacedName) for _, item := range ipPools { - ipPool := item.(*crdv1a2.IPPool) + ipPool := item.(*crdv1b1.IPPool) allocator, err := poolallocator.NewIPPoolAllocator(ipPool.Name, c.crdClient, c.ipPoolLister) if err != nil { // This is not a transient error - log and forget @@ -429,12 +429,12 @@ func (c *AntreaIPAMController) updateIPPoolCounters(poolName string) error { } func (c *AntreaIPAMController) createHandler(obj interface{}) { - ipPool := obj.(*crdv1a2.IPPool) + ipPool := obj.(*crdv1b1.IPPool) c.statusQueue.Add(ipPool.Name) } func (c *AntreaIPAMController) updateHandler(oldObj, newObj interface{}) { - ipPool := newObj.(*crdv1a2.IPPool) + ipPool := newObj.(*crdv1b1.IPPool) c.statusQueue.Add(ipPool.Name) } diff --git a/pkg/ipam/poolallocator/allocator.go b/pkg/ipam/poolallocator/allocator.go index 3319722c21c..4d1dd65de68 100644 --- a/pkg/ipam/poolallocator/allocator.go +++ b/pkg/ipam/poolallocator/allocator.go @@ -20,9 +20,9 @@ import ( "net" "reflect" - "antrea.io/antrea/pkg/apis/crd/v1alpha2" + "antrea.io/antrea/pkg/apis/crd/v1beta1" crdclientset "antrea.io/antrea/pkg/client/clientset/versioned" - informers "antrea.io/antrea/pkg/client/listers/crd/v1alpha2" + informers "antrea.io/antrea/pkg/client/listers/crd/v1beta1" "antrea.io/antrea/pkg/ipam/ipallocator" iputil "antrea.io/antrea/pkg/util/ip" @@ -37,7 +37,7 @@ import ( // only be extended. type IPPoolAllocator struct { // IP version of the IPPool - IPVersion v1alpha2.IPVersion + IPVersion v1beta1.IPVersion // Name of IPPool custom resource ipPoolName string @@ -68,14 +68,14 @@ func NewIPPoolAllocator(poolName string, client crdclientset.Interface, poolList return allocator, nil } -func (a *IPPoolAllocator) getPool() (*v1alpha2.IPPool, error) { +func (a *IPPoolAllocator) getPool() (*v1beta1.IPPool, error) { pool, err := a.ipPoolLister.Get(a.ipPoolName) return pool, err } // initAllocatorList reads IP Pool status and initializes a list of allocators based on // IP Pool spec and state of allocation recorded in the status -func (a *IPPoolAllocator) initIPAllocators(ipPool *v1alpha2.IPPool) (ipallocator.MultiIPAllocator, error) { +func (a *IPPoolAllocator) initIPAllocators(ipPool *v1beta1.IPPool) (ipallocator.MultiIPAllocator, error) { var allocators ipallocator.MultiIPAllocator @@ -83,14 +83,14 @@ func (a *IPPoolAllocator) initIPAllocators(ipPool *v1alpha2.IPPool) (ipallocator for _, ipRange := range ipPool.Spec.IPRanges { if len(ipRange.CIDR) > 0 { // Reserve gateway address and broadcast address - reservedIPs := []net.IP{net.ParseIP(ipRange.SubnetInfo.Gateway)} + reservedIPs := []net.IP{net.ParseIP(ipPool.Spec.SubnetInfo.Gateway)} _, ipNet, err := net.ParseCIDR(ipRange.CIDR) if err != nil { return nil, err } size, bits := ipNet.Mask.Size() - if int32(size) == ipRange.SubnetInfo.PrefixLength && bits == 32 { + if int32(size) == ipPool.Spec.SubnetInfo.PrefixLength && bits == 32 { // Allocation CIDR covers entire subnet, thus we need // to reserve broadcast IP as well for IPv4 reservedIPs = append(reservedIPs, iputil.GetLocalBroadcastIP(ipNet)) @@ -122,7 +122,7 @@ func (a *IPPoolAllocator) initIPAllocators(ipPool *v1alpha2.IPPool) (ipallocator return allocators, nil } -func (a *IPPoolAllocator) getPoolAndInitIPAllocators() (*v1alpha2.IPPool, ipallocator.MultiIPAllocator, error) { +func (a *IPPoolAllocator) getPoolAndInitIPAllocators() (*v1beta1.IPPool, ipallocator.MultiIPAllocator, error) { ipPool, err := a.getPool() if err != nil { @@ -136,9 +136,9 @@ func (a *IPPoolAllocator) getPoolAndInitIPAllocators() (*v1alpha2.IPPool, ipallo return ipPool, allocators, nil } -func (a *IPPoolAllocator) appendPoolUsage(ipPool *v1alpha2.IPPool, ip net.IP, state v1alpha2.IPAddressPhase, owner v1alpha2.IPAddressOwner) error { +func (a *IPPoolAllocator) appendPoolUsage(ipPool *v1beta1.IPPool, ip net.IP, state v1beta1.IPAddressPhase, owner v1beta1.IPAddressOwner) error { newPool := ipPool.DeepCopy() - usageEntry := v1alpha2.IPAddressState{ + usageEntry := v1beta1.IPAddressState{ IPAddress: ip.String(), Phase: state, Owner: owner, @@ -146,7 +146,7 @@ func (a *IPPoolAllocator) appendPoolUsage(ipPool *v1alpha2.IPPool, ip net.IP, st newPool.Status.IPAddresses = append(newPool.Status.IPAddresses, usageEntry) a.updateUsage(newPool) - _, err := a.crdClient.CrdV1alpha2().IPPools().UpdateStatus(context.TODO(), newPool, metav1.UpdateOptions{}) + _, err := a.crdClient.CrdV1beta1().IPPools().UpdateStatus(context.TODO(), newPool, metav1.UpdateOptions{}) if err != nil { klog.Warningf("IP Pool %s update with status %+v failed: %+v", newPool.Name, newPool.Status, err) return err @@ -157,7 +157,7 @@ func (a *IPPoolAllocator) appendPoolUsage(ipPool *v1alpha2.IPPool, ip net.IP, st } // updateIPAddressState updates the status of the specified IP in the provided IPPool. It requires the IP is already in the IPAddresses list of the IPPool's status. -func (a *IPPoolAllocator) updateIPAddressState(ipPool *v1alpha2.IPPool, ip net.IP, state v1alpha2.IPAddressPhase, owner v1alpha2.IPAddressOwner) error { +func (a *IPPoolAllocator) updateIPAddressState(ipPool *v1beta1.IPPool, ip net.IP, state v1beta1.IPAddressPhase, owner v1beta1.IPAddressOwner) error { newPool := ipPool.DeepCopy() ipString := ip.String() found := false @@ -174,7 +174,7 @@ func (a *IPPoolAllocator) updateIPAddressState(ipPool *v1alpha2.IPPool, ip net.I return fmt.Errorf("ip %s usage not found in pool %s", ipString, newPool.Name) } - _, err := a.crdClient.CrdV1alpha2().IPPools().UpdateStatus(context.TODO(), newPool, metav1.UpdateOptions{}) + _, err := a.crdClient.CrdV1beta1().IPPools().UpdateStatus(context.TODO(), newPool, metav1.UpdateOptions{}) if err != nil { klog.Warningf("IP Pool %s update with status %+v failed: %+v", newPool.Name, newPool.Status, err) return err @@ -184,26 +184,26 @@ func (a *IPPoolAllocator) updateIPAddressState(ipPool *v1alpha2.IPPool, ip net.I } -func (a *IPPoolAllocator) appendPoolUsageForStatefulSet(ipPool *v1alpha2.IPPool, ips []net.IP, namespace, name string) error { +func (a *IPPoolAllocator) appendPoolUsageForStatefulSet(ipPool *v1beta1.IPPool, ips []net.IP, namespace, name string) error { newPool := ipPool.DeepCopy() for i, ip := range ips { - owner := v1alpha2.IPAddressOwner{ - StatefulSet: &v1alpha2.StatefulSetOwner{ + owner := v1beta1.IPAddressOwner{ + StatefulSet: &v1beta1.StatefulSetOwner{ Namespace: namespace, Name: name, Index: i, }, } - usageEntry := v1alpha2.IPAddressState{ + usageEntry := v1beta1.IPAddressState{ IPAddress: ip.String(), - Phase: v1alpha2.IPAddressPhaseReserved, + Phase: v1beta1.IPAddressPhaseReserved, Owner: owner, } newPool.Status.IPAddresses = append(newPool.Status.IPAddresses, usageEntry) } - _, err := a.crdClient.CrdV1alpha2().IPPools().UpdateStatus(context.TODO(), newPool, metav1.UpdateOptions{}) + _, err := a.crdClient.CrdV1beta1().IPPools().UpdateStatus(context.TODO(), newPool, metav1.UpdateOptions{}) if err != nil { klog.Warningf("IP Pool %s update with status %+v failed: %+v", newPool.Name, newPool.Status, err) return err @@ -214,11 +214,11 @@ func (a *IPPoolAllocator) appendPoolUsageForStatefulSet(ipPool *v1alpha2.IPPool, } // removeIPAddressState updates ipPool status to delete released IP allocation, and keeps preallocation information -func (a *IPPoolAllocator) removeIPAddressState(ipPool *v1alpha2.IPPool, ip net.IP) error { +func (a *IPPoolAllocator) removeIPAddressState(ipPool *v1beta1.IPPool, ip net.IP) error { ipString := ip.String() newPool := ipPool.DeepCopy() - var newList []v1alpha2.IPAddressState + var newList []v1beta1.IPAddressState allocated := false for i := range ipPool.Status.IPAddresses { entry := ipPool.Status.IPAddresses[i] @@ -229,7 +229,7 @@ func (a *IPPoolAllocator) removeIPAddressState(ipPool *v1alpha2.IPPool, ip net.I if entry.Owner.StatefulSet != nil { entry = *entry.DeepCopy() entry.Owner.Pod = nil - entry.Phase = v1alpha2.IPAddressPhaseReserved + entry.Phase = v1beta1.IPAddressPhaseReserved newList = append(newList, entry) } } @@ -242,7 +242,7 @@ func (a *IPPoolAllocator) removeIPAddressState(ipPool *v1alpha2.IPPool, ip net.I newPool.Status.IPAddresses = newList a.updateUsage(newPool) - _, err := a.crdClient.CrdV1alpha2().IPPools().UpdateStatus(context.TODO(), newPool, metav1.UpdateOptions{}) + _, err := a.crdClient.CrdV1beta1().IPPools().UpdateStatus(context.TODO(), newPool, metav1.UpdateOptions{}) if err != nil { klog.Warningf("IP Pool %s update failed: %+v", newPool.Name, err) return err @@ -254,7 +254,7 @@ func (a *IPPoolAllocator) removeIPAddressState(ipPool *v1alpha2.IPPool, ip net.I // getExistingAllocation looks up the existing IP allocation for a Pod network interface, and // returns the IP address and SubnetInfo if found. -func (a *IPPoolAllocator) getExistingAllocation(podOwner *v1alpha2.PodOwner) (net.IP, *v1alpha2.SubnetInfo, error) { +func (a *IPPoolAllocator) getExistingAllocation(podOwner *v1beta1.PodOwner) (net.IP, *v1beta1.SubnetInfo, error) { ip, err := a.GetContainerIP(podOwner.ContainerID, podOwner.IFName) if err != nil { return nil, nil, err @@ -278,15 +278,15 @@ func (a *IPPoolAllocator) getExistingAllocation(podOwner *v1alpha2.PodOwner) (ne if index == -1 { return nil, nil, fmt.Errorf("IP %v does not belong to IPPool %s", ip, a.ipPoolName) } - return ip, &ipPool.Spec.IPRanges[index].SubnetInfo, nil + return ip, ipPool.Spec.SubnetInfo, nil } // AllocateIP allocates the specified IP. It returns error if the IP is not in the range or already // allocated, or in case CRD failed to update its state. // In case of success, IP pool CRD status is updated with allocated IP/state/resource/container. // AllocateIP returns subnet details for the requested IP, as defined in IP pool spec. -func (a *IPPoolAllocator) AllocateIP(ip net.IP, state v1alpha2.IPAddressPhase, owner v1alpha2.IPAddressOwner) (*v1alpha2.SubnetInfo, error) { - var subnetSpec *v1alpha2.SubnetInfo +func (a *IPPoolAllocator) AllocateIP(ip net.IP, state v1beta1.IPAddressPhase, owner v1beta1.IPAddressOwner) (*v1beta1.SubnetInfo, error) { + var subnetInfo *v1beta1.SubnetInfo // Retry on CRD update conflict which is caused by multiple agents updating a pool at same time. err := retry.RetryOnConflict(retry.DefaultRetry, func() error { ipPool, allocators, err := a.getPoolAndInitIPAllocators() @@ -311,7 +311,7 @@ func (a *IPPoolAllocator) AllocateIP(ip net.IP, state v1alpha2.IPAddressPhase, o return fmt.Errorf("IP %v does not belong to IP pool %s", ip, a.ipPoolName) } - subnetSpec = &ipPool.Spec.IPRanges[index].SubnetInfo + subnetInfo = ipPool.Spec.SubnetInfo err = a.appendPoolUsage(ipPool, ip, state, owner) return err @@ -320,18 +320,18 @@ func (a *IPPoolAllocator) AllocateIP(ip net.IP, state v1alpha2.IPAddressPhase, o if err != nil { klog.Errorf("Failed to allocate IP address %s from pool %s: %+v", ip, a.ipPoolName, err) } - return subnetSpec, err + return subnetInfo, err } // AllocateNext allocates the next available IP. It returns error if pool is exausted, // or in case CRD failed to update its state. // In case of success, IPPool CRD status is updated with allocated IP/state/resource/container. // AllocateIP returns subnet details for the requested IP, as defined in IP pool spec. -func (a *IPPoolAllocator) AllocateNext(state v1alpha2.IPAddressPhase, owner v1alpha2.IPAddressOwner) (net.IP, *v1alpha2.SubnetInfo, error) { +func (a *IPPoolAllocator) AllocateNext(state v1beta1.IPAddressPhase, owner v1beta1.IPAddressOwner) (net.IP, *v1beta1.SubnetInfo, error) { podOwner := owner.Pod // Same resource can not ask for allocation twice without release. // This needs to be verified even at the expense of another API call. - ip, subnetSpec, err := a.getExistingAllocation(podOwner) + ip, subnetInfo, err := a.getExistingAllocation(podOwner) if err != nil { return nil, nil, err } @@ -340,7 +340,7 @@ func (a *IPPoolAllocator) AllocateNext(state v1alpha2.IPAddressPhase, owner v1al // allocation failure, not all allocated IPs were successfully released, and then // CNI ADD is retried. klog.InfoS("Container already has an IP allocated", "container", podOwner.ContainerID, "interface", podOwner.IFName, "IPPool", a.ipPoolName) - return ip, subnetSpec, err + return ip, subnetInfo, err } // Retry on CRD update conflict which is caused by multiple agents updating a pool at same time. @@ -365,21 +365,21 @@ func (a *IPPoolAllocator) AllocateNext(state v1alpha2.IPAddressPhase, owner v1al return fmt.Errorf("failed to allocate IP: Pool %s is exausted", a.ipPoolName) } - subnetSpec = &ipPool.Spec.IPRanges[index].SubnetInfo + subnetInfo = ipPool.Spec.SubnetInfo return a.appendPoolUsage(ipPool, ip, state, owner) }) if err != nil { klog.ErrorS(err, "Failed to allocate from IPPool", "IPPool", a.ipPoolName) } - return ip, subnetSpec, err + return ip, subnetInfo, err } // AllocateReservedOrNext allocates the reserved IP if it exists, else allocates next available IP. // It returns error if pool is exhausted, or in case it fails to update IPPool's state. In case of // success, IP pool status is updated with allocated IP/state/resource/container. // AllocateReservedOrNext returns subnet details for the requested IP, as defined in IP pool spec. -func (a *IPPoolAllocator) AllocateReservedOrNext(state v1alpha2.IPAddressPhase, owner v1alpha2.IPAddressOwner) (net.IP, *v1alpha2.SubnetInfo, error) { +func (a *IPPoolAllocator) AllocateReservedOrNext(state v1beta1.IPAddressPhase, owner v1beta1.IPAddressOwner) (net.IP, *v1beta1.SubnetInfo, error) { ip, err := a.getReservedIP(owner) if err != nil { return nil, nil, err @@ -390,15 +390,15 @@ func (a *IPPoolAllocator) AllocateReservedOrNext(state v1alpha2.IPAddressPhase, } var prevIP net.IP - var subnetSpec *v1alpha2.SubnetInfo + var subnetInfo *v1beta1.SubnetInfo podOwner := owner.Pod - prevIP, subnetSpec, err = a.getExistingAllocation(podOwner) + prevIP, subnetInfo, err = a.getExistingAllocation(podOwner) if err != nil { return nil, nil, err } if prevIP != nil { klog.InfoS("Container already has an IP allocated", "container", podOwner.ContainerID, "interface", podOwner.IFName, "IPPool", a.ipPoolName) - return prevIP, subnetSpec, err + return prevIP, subnetInfo, err } // Retry on CRD update conflict which is caused by multiple agents updating a pool at same time. @@ -421,14 +421,14 @@ func (a *IPPoolAllocator) AllocateReservedOrNext(state v1alpha2.IPAddressPhase, return fmt.Errorf("IP %v does not belong to IPPool %s", ip, a.ipPoolName) } - subnetSpec = &ipPool.Spec.IPRanges[index].SubnetInfo + subnetInfo = ipPool.Spec.SubnetInfo return a.updateIPAddressState(ipPool, ip, state, owner) }) if err != nil { klog.ErrorS(err, "Failed to allocate IP address", "ip", ip, "IPPool", a.ipPoolName) } - return ip, subnetSpec, err + return ip, subnetInfo, err } // AllocateStatefulSet pre-allocates continuous range of IPs for StatefulSet. @@ -511,7 +511,7 @@ func (a *IPPoolAllocator) ReleaseStatefulSet(namespace, name string) error { return err } - var updatedAdresses []v1alpha2.IPAddressState + var updatedAdresses []v1beta1.IPAddressState for _, ip := range ipPool.Status.IPAddresses { if ip.Owner.StatefulSet == nil || ip.Owner.StatefulSet.Namespace != namespace || ip.Owner.StatefulSet.Name != name { updatedAdresses = append(updatedAdresses, ip) @@ -527,7 +527,7 @@ func (a *IPPoolAllocator) ReleaseStatefulSet(namespace, name string) error { newPool := ipPool.DeepCopy() newPool.Status.IPAddresses = updatedAdresses - _, err = a.crdClient.CrdV1alpha2().IPPools().UpdateStatus(context.TODO(), newPool, metav1.UpdateOptions{}) + _, err = a.crdClient.CrdV1beta1().IPPools().UpdateStatus(context.TODO(), newPool, metav1.UpdateOptions{}) if err != nil { klog.Warningf("IP Pool %s update failed: %+v", newPool.Name, err) return err @@ -607,7 +607,7 @@ func (a *IPPoolAllocator) GetContainerIP(containerID, ifName string) (net.IP, er } // getReservedIP checks whether an IP was reserved with specified owner. It returns error if the resource crd fails to be retrieved. -func (a *IPPoolAllocator) getReservedIP(reservedOwner v1alpha2.IPAddressOwner) (net.IP, error) { +func (a *IPPoolAllocator) getReservedIP(reservedOwner v1beta1.IPAddressOwner) (net.IP, error) { ipPool, err := a.getPool() if err != nil { return nil, err @@ -631,7 +631,7 @@ func (a IPPoolAllocator) Total() int { return allocators.Total() } -func (a *IPPoolAllocator) updateUsage(ipPool *v1alpha2.IPPool) { +func (a *IPPoolAllocator) updateUsage(ipPool *v1beta1.IPPool) { ipPool.Status.Usage.Total = a.Total() ipPool.Status.Usage.Used = len(ipPool.Status.IPAddresses) } diff --git a/pkg/ipam/poolallocator/allocator_test.go b/pkg/ipam/poolallocator/allocator_test.go index 78faa87aab5..14c6a858e16 100644 --- a/pkg/ipam/poolallocator/allocator_test.go +++ b/pkg/ipam/poolallocator/allocator_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - crdv1a2 "antrea.io/antrea/pkg/apis/crd/v1alpha2" + crdv1b1 "antrea.io/antrea/pkg/apis/crd/v1beta1" informers "antrea.io/antrea/pkg/client/informers/externalversions" fakepoolclient "antrea.io/antrea/pkg/ipam/poolallocator/testing" @@ -37,20 +37,20 @@ import ( var testNamespace = "test" -var fakePodOwner = crdv1a2.IPAddressOwner{ - Pod: &crdv1a2.PodOwner{ +var fakePodOwner = crdv1b1.IPAddressOwner{ + Pod: &crdv1b1.PodOwner{ Name: "fakePod", Namespace: testNamespace, ContainerID: uuid.New().String(), }, } -func newTestIPPoolAllocator(pool *crdv1a2.IPPool, stopCh <-chan struct{}) *IPPoolAllocator { +func newTestIPPoolAllocator(pool *crdv1b1.IPPool, stopCh <-chan struct{}) *IPPoolAllocator { crdClient := fakepoolclient.NewIPPoolClient() crdInformerFactory := informers.NewSharedInformerFactory(crdClient, 0) - pools := crdInformerFactory.Crd().V1alpha2().IPPools() + pools := crdInformerFactory.Crd().V1beta1().IPPools() poolInformer := pools.Informer() go crdInformerFactory.Start(stopCh) @@ -70,18 +70,18 @@ func newTestIPPoolAllocator(pool *crdv1a2.IPPool, stopCh <-chan struct{}) *IPPoo return allocator } -func validateAllocationSequence(t *testing.T, allocator *IPPoolAllocator, subnetInfo crdv1a2.SubnetInfo, ipList []string) { +func validateAllocationSequence(t *testing.T, allocator *IPPoolAllocator, subnetInfo *crdv1b1.SubnetInfo, ipList []string) { i := 1 for _, expectedIP := range ipList { klog.Info("Validating allocation for ", expectedIP) - owner := crdv1a2.IPAddressOwner{ - Pod: &crdv1a2.PodOwner{ + owner := crdv1b1.IPAddressOwner{ + Pod: &crdv1b1.PodOwner{ Name: fmt.Sprintf("fakePod%d", i), Namespace: testNamespace, ContainerID: uuid.New().String(), }, } - ip, returnInfo, err := allocator.AllocateNext(crdv1a2.IPAddressPhaseAllocated, owner) + ip, returnInfo, err := allocator.AllocateNext(crdv1b1.IPAddressPhaseAllocated, owner) require.NoError(t, err) assert.Equal(t, net.ParseIP(expectedIP), ip) assert.Equal(t, subnetInfo, *returnInfo) @@ -94,21 +94,19 @@ func TestAllocateIP(t *testing.T) { defer close(stopCh) poolName := uuid.New().String() - ipRange := crdv1a2.IPRange{ + ipRange := crdv1b1.IPRange{ Start: "10.2.2.100", End: "10.2.2.120", } - subnetInfo := crdv1a2.SubnetInfo{ + subnetInfo := &crdv1b1.SubnetInfo{ Gateway: "10.2.2.1", PrefixLength: 24, VLAN: 100, } - subnetRange := crdv1a2.SubnetIPRange{IPRange: ipRange, - SubnetInfo: subnetInfo} - pool := crdv1a2.IPPool{ + pool := crdv1b1.IPPool{ ObjectMeta: metav1.ObjectMeta{Name: poolName}, - Spec: crdv1a2.IPPoolSpec{IPRanges: []crdv1a2.SubnetIPRange{subnetRange}}, + Spec: crdv1b1.IPPoolSpec{IPRanges: []crdv1b1.IPRange{ipRange}, SubnetInfo: subnetInfo}, } allocator := newTestIPPoolAllocator(&pool, stopCh) @@ -116,19 +114,19 @@ func TestAllocateIP(t *testing.T) { assert.Equal(t, 21, allocator.Total()) // Allocate specific IP from the range - returnInfo, err := allocator.AllocateIP(net.ParseIP("10.2.2.101"), crdv1a2.IPAddressPhaseAllocated, fakePodOwner) + returnInfo, err := allocator.AllocateIP(net.ParseIP("10.2.2.101"), crdv1b1.IPAddressPhaseAllocated, fakePodOwner) assert.Equal(t, subnetInfo, *returnInfo) require.NoError(t, err) // Validate IP outside the range is not allocated - _, err = allocator.AllocateIP(net.ParseIP("10.2.2.121"), crdv1a2.IPAddressPhaseAllocated, fakePodOwner) + _, err = allocator.AllocateIP(net.ParseIP("10.2.2.121"), crdv1b1.IPAddressPhaseAllocated, fakePodOwner) require.Error(t, err) // Make sure IP allocated above is not allocated again validateAllocationSequence(t, allocator, subnetInfo, []string{"10.2.2.100", "10.2.2.102"}) // Validate error is returned if IP is already allocated - _, err = allocator.AllocateIP(net.ParseIP("10.2.2.102"), crdv1a2.IPAddressPhaseAllocated, fakePodOwner) + _, err = allocator.AllocateIP(net.ParseIP("10.2.2.102"), crdv1b1.IPAddressPhaseAllocated, fakePodOwner) require.Error(t, err) } @@ -137,20 +135,18 @@ func TestAllocateNext(t *testing.T) { defer close(stopCh) poolName := "fakePool" - ipRange := crdv1a2.IPRange{ + ipRange := crdv1b1.IPRange{ Start: "10.2.2.100", End: "10.2.2.120", } - subnetInfo := crdv1a2.SubnetInfo{ + subnetInfo := &crdv1b1.SubnetInfo{ Gateway: "10.2.2.1", PrefixLength: 24, } - subnetRange := crdv1a2.SubnetIPRange{IPRange: ipRange, - SubnetInfo: subnetInfo} - pool := crdv1a2.IPPool{ + pool := crdv1b1.IPPool{ ObjectMeta: metav1.ObjectMeta{Name: poolName}, - Spec: crdv1a2.IPPoolSpec{IPRanges: []crdv1a2.SubnetIPRange{subnetRange}}, + Spec: crdv1b1.IPPoolSpec{IPRanges: []crdv1b1.IPRange{ipRange}, SubnetInfo: subnetInfo}, } allocator := newTestIPPoolAllocator(&pool, stopCh) @@ -165,24 +161,20 @@ func TestAllocateNextMultiRange(t *testing.T) { defer close(stopCh) poolName := uuid.New().String() - ipRange1 := crdv1a2.IPRange{ + ipRange1 := crdv1b1.IPRange{ Start: "10.2.2.100", End: "10.2.2.101", } - ipRange2 := crdv1a2.IPRange{CIDR: "10.2.2.0/28"} - subnetInfo := crdv1a2.SubnetInfo{ + ipRange2 := crdv1b1.IPRange{CIDR: "10.2.2.0/28"} + subnetInfo := &crdv1b1.SubnetInfo{ Gateway: "10.2.2.1", PrefixLength: 24, } - subnetRange1 := crdv1a2.SubnetIPRange{IPRange: ipRange1, - SubnetInfo: subnetInfo} - subnetRange2 := crdv1a2.SubnetIPRange{IPRange: ipRange2, - SubnetInfo: subnetInfo} - pool := crdv1a2.IPPool{ + pool := crdv1b1.IPPool{ ObjectMeta: metav1.ObjectMeta{Name: poolName}, - Spec: crdv1a2.IPPoolSpec{ - IPRanges: []crdv1a2.SubnetIPRange{subnetRange1, subnetRange2}}, + Spec: crdv1b1.IPPoolSpec{ + IPRanges: []crdv1b1.IPRange{ipRange1, ipRange2}, SubnetInfo: subnetInfo}, } allocator := newTestIPPoolAllocator(&pool, stopCh) @@ -198,27 +190,23 @@ func TestAllocateNextMultiRangeExausted(t *testing.T) { defer close(stopCh) poolName := uuid.New().String() - ipRange1 := crdv1a2.IPRange{ + ipRange1 := crdv1b1.IPRange{ Start: "10.2.2.100", End: "10.2.2.101", } - ipRange2 := crdv1a2.IPRange{ + ipRange2 := crdv1b1.IPRange{ Start: "10.2.2.200", End: "10.2.2.200", } - subnetInfo := crdv1a2.SubnetInfo{ + subnetInfo := &crdv1b1.SubnetInfo{ Gateway: "10.2.2.1", PrefixLength: 24, } - subnetRange1 := crdv1a2.SubnetIPRange{IPRange: ipRange1, - SubnetInfo: subnetInfo} - subnetRange2 := crdv1a2.SubnetIPRange{IPRange: ipRange2, - SubnetInfo: subnetInfo} - - pool := crdv1a2.IPPool{ + pool := crdv1b1.IPPool{ ObjectMeta: metav1.ObjectMeta{Name: poolName}, - Spec: crdv1a2.IPPoolSpec{ - IPRanges: []crdv1a2.SubnetIPRange{subnetRange1, subnetRange2}}, + Spec: crdv1b1.IPPoolSpec{ + IPRanges: []crdv1b1.IPRange{ipRange1, ipRange2}, + SubnetInfo: subnetInfo}, } allocator := newTestIPPoolAllocator(&pool, stopCh) @@ -229,7 +217,7 @@ func TestAllocateNextMultiRangeExausted(t *testing.T) { validateAllocationSequence(t, allocator, subnetInfo, []string{"10.2.2.100", "10.2.2.101", "10.2.2.200"}) // Allocate next IP and get error - _, _, err := allocator.AllocateNext(crdv1a2.IPAddressPhaseAllocated, fakePodOwner) + _, _, err := allocator.AllocateNext(crdv1b1.IPAddressPhaseAllocated, fakePodOwner) require.Error(t, err) } @@ -238,24 +226,21 @@ func TestAllocateReleaseSequence(t *testing.T) { defer close(stopCh) poolName := uuid.New().String() - ipRange1 := crdv1a2.IPRange{ + ipRange1 := crdv1b1.IPRange{ Start: "2001::1000", End: "2001::1000", } - ipRange2 := crdv1a2.IPRange{CIDR: "2001::0/124"} - subnetInfo := crdv1a2.SubnetInfo{ + ipRange2 := crdv1b1.IPRange{CIDR: "2001::0/124"} + subnetInfo := &crdv1b1.SubnetInfo{ Gateway: "2001::1", PrefixLength: 64, } - subnetRange1 := crdv1a2.SubnetIPRange{IPRange: ipRange1, - SubnetInfo: subnetInfo} - subnetRange2 := crdv1a2.SubnetIPRange{IPRange: ipRange2, - SubnetInfo: subnetInfo} - pool := crdv1a2.IPPool{ + pool := crdv1b1.IPPool{ ObjectMeta: metav1.ObjectMeta{Name: poolName}, - Spec: crdv1a2.IPPoolSpec{ - IPRanges: []crdv1a2.SubnetIPRange{subnetRange1, subnetRange2}}, + Spec: crdv1b1.IPPoolSpec{ + IPRanges: []crdv1b1.IPRange{ipRange1, ipRange2}, + SubnetInfo: subnetInfo}, } allocator := newTestIPPoolAllocator(&pool, stopCh) @@ -306,24 +291,21 @@ func TestReleaseResource(t *testing.T) { defer close(stopCh) poolName := uuid.New().String() - ipRange1 := crdv1a2.IPRange{ + ipRange1 := crdv1b1.IPRange{ Start: "2001::1000", End: "2001::1000", } - ipRange2 := crdv1a2.IPRange{CIDR: "2001::0/124"} - subnetInfo := crdv1a2.SubnetInfo{ + ipRange2 := crdv1b1.IPRange{CIDR: "2001::0/124"} + subnetInfo := &crdv1b1.SubnetInfo{ Gateway: "2001::1", PrefixLength: 64, } - subnetRange1 := crdv1a2.SubnetIPRange{IPRange: ipRange1, - SubnetInfo: subnetInfo} - subnetRange2 := crdv1a2.SubnetIPRange{IPRange: ipRange2, - SubnetInfo: subnetInfo} - pool := crdv1a2.IPPool{ + pool := crdv1b1.IPPool{ ObjectMeta: metav1.ObjectMeta{Name: poolName}, - Spec: crdv1a2.IPPoolSpec{ - IPRanges: []crdv1a2.SubnetIPRange{subnetRange1, subnetRange2}}, + Spec: crdv1b1.IPPoolSpec{ + IPRanges: []crdv1b1.IPRange{ipRange1, ipRange2}, + SubnetInfo: subnetInfo}, } allocator := newTestIPPoolAllocator(&pool, stopCh) @@ -346,8 +328,8 @@ func TestHas(t *testing.T) { stopCh := make(chan struct{}) defer close(stopCh) - owner := crdv1a2.IPAddressOwner{ - Pod: &crdv1a2.PodOwner{ + owner := crdv1b1.IPAddressOwner{ + Pod: &crdv1b1.PodOwner{ Name: "fakePod", Namespace: testNamespace, ContainerID: "fakeContainer", @@ -355,27 +337,25 @@ func TestHas(t *testing.T) { }, } poolName := uuid.New().String() - ipRange1 := crdv1a2.IPRange{ + ipRange1 := crdv1b1.IPRange{ Start: "2001::1000", End: "2001::1000", } - subnetInfo := crdv1a2.SubnetInfo{ + subnetInfo := &crdv1b1.SubnetInfo{ Gateway: "2001::1", PrefixLength: 64, } - subnetRange1 := crdv1a2.SubnetIPRange{IPRange: ipRange1, - SubnetInfo: subnetInfo} - - pool := crdv1a2.IPPool{ + pool := crdv1b1.IPPool{ ObjectMeta: metav1.ObjectMeta{Name: poolName}, - Spec: crdv1a2.IPPoolSpec{ - IPRanges: []crdv1a2.SubnetIPRange{subnetRange1}}, + Spec: crdv1b1.IPPoolSpec{ + IPRanges: []crdv1b1.IPRange{ipRange1}, + SubnetInfo: subnetInfo}, } allocator := newTestIPPoolAllocator(&pool, stopCh) require.NotNil(t, allocator) - _, _, err := allocator.AllocateNext(crdv1a2.IPAddressPhaseAllocated, owner) + _, _, err := allocator.AllocateNext(crdv1b1.IPAddressPhaseAllocated, owner) require.NoError(t, err) err = wait.PollImmediate(100*time.Millisecond, 1*time.Second, func() (bool, error) { has, _ := allocator.hasPod(testNamespace, "fakePod") @@ -404,20 +384,18 @@ func TestAllocateReleaseStatefulSet(t *testing.T) { poolName := uuid.New().String() setName := "fakeSet" - ipRange := crdv1a2.IPRange{ + ipRange := crdv1b1.IPRange{ Start: "10.2.2.100", End: "10.2.2.120", } - subnetInfo := crdv1a2.SubnetInfo{ + subnetInfo := &crdv1b1.SubnetInfo{ Gateway: "10.2.2.1", PrefixLength: 24, } - subnetRange := crdv1a2.SubnetIPRange{IPRange: ipRange, - SubnetInfo: subnetInfo} - pool := crdv1a2.IPPool{ + pool := crdv1b1.IPPool{ ObjectMeta: metav1.ObjectMeta{Name: poolName}, - Spec: crdv1a2.IPPoolSpec{IPRanges: []crdv1a2.SubnetIPRange{subnetRange}}, + Spec: crdv1b1.IPPoolSpec{IPRanges: []crdv1b1.IPRange{ipRange}, SubnetInfo: subnetInfo}, } allocator := newTestIPPoolAllocator(&pool, stopCh) diff --git a/pkg/ipam/poolallocator/testing/fake_client.go b/pkg/ipam/poolallocator/testing/fake_client.go index 2333d56a646..ca81cad8667 100644 --- a/pkg/ipam/poolallocator/testing/fake_client.go +++ b/pkg/ipam/poolallocator/testing/fake_client.go @@ -24,7 +24,7 @@ import ( "k8s.io/apimachinery/pkg/watch" k8stesting "k8s.io/client-go/testing" - crdv1a2 "antrea.io/antrea/pkg/apis/crd/v1alpha2" + crdv1b1 "antrea.io/antrea/pkg/apis/crd/v1beta1" fakeversioned "antrea.io/antrea/pkg/client/clientset/versioned/fake" ) @@ -41,7 +41,7 @@ type IPPoolClientset struct { watcher *watch.RaceFreeFakeWatcher } -func (c *IPPoolClientset) InitPool(pool *crdv1a2.IPPool) { +func (c *IPPoolClientset) InitPool(pool *crdv1b1.IPPool) { pool.ResourceVersion = uuid.New().String() c.poolVersion.Store(pool.Name, pool.ResourceVersion) @@ -54,7 +54,7 @@ func NewIPPoolClient() *IPPoolClientset { poolVersion: sync.Map{}} crdClient.AddReactor("update", "ippools", func(action k8stesting.Action) (bool, runtime.Object, error) { - updatedPool := action.(k8stesting.UpdateAction).GetObject().(*crdv1a2.IPPool) + updatedPool := action.(k8stesting.UpdateAction).GetObject().(*crdv1b1.IPPool) obj, exists := crdClient.poolVersion.Load(updatedPool.Name) if !exists { return false, nil, nil