diff --git a/build/charts/antrea/crds/externalippool.yaml b/build/charts/antrea/crds/externalippool.yaml index 080c0c620c0..e6d375661b9 100644 --- a/build/charts/antrea/crds/externalippool.yaml +++ b/build/charts/antrea/crds/externalippool.yaml @@ -9,7 +9,7 @@ spec: versions: - name: v1alpha2 served: true - storage: true + storage: false schema: openAPIV3Schema: type: object @@ -94,6 +94,93 @@ spec: type: date subresources: status: {} + - name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - ipRanges + - nodeSelector + properties: + ipRanges: + type: array + items: + type: object + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + type: string + format: cidr + start: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + end: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + nodeSelector: + type: object + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + enum: + - In + - NotIn + - Exists + - DoesNotExist + type: string + values: + items: + type: string + pattern: "^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$" + type: array + type: object + type: array + matchLabels: + x-kubernetes-preserve-unknown-fields: true + status: + type: object + properties: + usage: + type: object + properties: + total: + type: integer + used: + type: integer + 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: externalippools diff --git a/build/yamls/antrea-aks.yml b/build/yamls/antrea-aks.yml index ec792ec21e6..0462a9390a1 100644 --- a/build/yamls/antrea-aks.yml +++ b/build/yamls/antrea-aks.yml @@ -1283,7 +1283,7 @@ spec: versions: - name: v1alpha2 served: true - storage: true + storage: false schema: openAPIV3Schema: type: object @@ -1368,6 +1368,93 @@ spec: type: date subresources: status: {} + - name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - ipRanges + - nodeSelector + properties: + ipRanges: + type: array + items: + type: object + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + type: string + format: cidr + start: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + end: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + nodeSelector: + type: object + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + enum: + - In + - NotIn + - Exists + - DoesNotExist + type: string + values: + items: + type: string + pattern: "^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$" + type: array + type: object + type: array + matchLabels: + x-kubernetes-preserve-unknown-fields: true + status: + type: object + properties: + usage: + type: object + properties: + total: + type: integer + used: + type: integer + 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: externalippools diff --git a/build/yamls/antrea-crds.yml b/build/yamls/antrea-crds.yml index f1ac54f55ea..41ed209d7a2 100644 --- a/build/yamls/antrea-crds.yml +++ b/build/yamls/antrea-crds.yml @@ -1270,7 +1270,7 @@ spec: versions: - name: v1alpha2 served: true - storage: true + storage: false schema: openAPIV3Schema: type: object @@ -1355,6 +1355,93 @@ spec: type: date subresources: status: {} + - name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - ipRanges + - nodeSelector + properties: + ipRanges: + type: array + items: + type: object + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + type: string + format: cidr + start: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + end: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + nodeSelector: + type: object + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + enum: + - In + - NotIn + - Exists + - DoesNotExist + type: string + values: + items: + type: string + pattern: "^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$" + type: array + type: object + type: array + matchLabels: + x-kubernetes-preserve-unknown-fields: true + status: + type: object + properties: + usage: + type: object + properties: + total: + type: integer + used: + type: integer + 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: externalippools diff --git a/build/yamls/antrea-eks.yml b/build/yamls/antrea-eks.yml index c8175867cfd..b8e28dd382a 100644 --- a/build/yamls/antrea-eks.yml +++ b/build/yamls/antrea-eks.yml @@ -1283,7 +1283,7 @@ spec: versions: - name: v1alpha2 served: true - storage: true + storage: false schema: openAPIV3Schema: type: object @@ -1368,6 +1368,93 @@ spec: type: date subresources: status: {} + - name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - ipRanges + - nodeSelector + properties: + ipRanges: + type: array + items: + type: object + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + type: string + format: cidr + start: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + end: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + nodeSelector: + type: object + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + enum: + - In + - NotIn + - Exists + - DoesNotExist + type: string + values: + items: + type: string + pattern: "^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$" + type: array + type: object + type: array + matchLabels: + x-kubernetes-preserve-unknown-fields: true + status: + type: object + properties: + usage: + type: object + properties: + total: + type: integer + used: + type: integer + 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: externalippools diff --git a/build/yamls/antrea-gke.yml b/build/yamls/antrea-gke.yml index 7812ff71dc6..4aadf8a612e 100644 --- a/build/yamls/antrea-gke.yml +++ b/build/yamls/antrea-gke.yml @@ -1283,7 +1283,7 @@ spec: versions: - name: v1alpha2 served: true - storage: true + storage: false schema: openAPIV3Schema: type: object @@ -1368,6 +1368,93 @@ spec: type: date subresources: status: {} + - name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - ipRanges + - nodeSelector + properties: + ipRanges: + type: array + items: + type: object + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + type: string + format: cidr + start: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + end: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + nodeSelector: + type: object + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + enum: + - In + - NotIn + - Exists + - DoesNotExist + type: string + values: + items: + type: string + pattern: "^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$" + type: array + type: object + type: array + matchLabels: + x-kubernetes-preserve-unknown-fields: true + status: + type: object + properties: + usage: + type: object + properties: + total: + type: integer + used: + type: integer + 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: externalippools diff --git a/build/yamls/antrea-ipsec.yml b/build/yamls/antrea-ipsec.yml index f8f6d4f8538..17283af7226 100644 --- a/build/yamls/antrea-ipsec.yml +++ b/build/yamls/antrea-ipsec.yml @@ -1283,7 +1283,7 @@ spec: versions: - name: v1alpha2 served: true - storage: true + storage: false schema: openAPIV3Schema: type: object @@ -1368,6 +1368,93 @@ spec: type: date subresources: status: {} + - name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - ipRanges + - nodeSelector + properties: + ipRanges: + type: array + items: + type: object + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + type: string + format: cidr + start: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + end: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + nodeSelector: + type: object + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + enum: + - In + - NotIn + - Exists + - DoesNotExist + type: string + values: + items: + type: string + pattern: "^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$" + type: array + type: object + type: array + matchLabels: + x-kubernetes-preserve-unknown-fields: true + status: + type: object + properties: + usage: + type: object + properties: + total: + type: integer + used: + type: integer + 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: externalippools diff --git a/build/yamls/antrea.yml b/build/yamls/antrea.yml index 8f9e23e8511..7acf7c75ac8 100644 --- a/build/yamls/antrea.yml +++ b/build/yamls/antrea.yml @@ -1283,7 +1283,7 @@ spec: versions: - name: v1alpha2 served: true - storage: true + storage: false schema: openAPIV3Schema: type: object @@ -1368,6 +1368,93 @@ spec: type: date subresources: status: {} + - name: v1beta1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - ipRanges + - nodeSelector + properties: + ipRanges: + type: array + items: + type: object + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + type: string + format: cidr + start: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + end: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + nodeSelector: + type: object + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + enum: + - In + - NotIn + - Exists + - DoesNotExist + type: string + values: + items: + type: string + pattern: "^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$" + type: array + type: object + type: array + matchLabels: + x-kubernetes-preserve-unknown-fields: true + status: + type: object + properties: + usage: + type: object + properties: + total: + type: integer + used: + type: integer + 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: externalippools diff --git a/cmd/antrea-agent/agent.go b/cmd/antrea-agent/agent.go index 94deecedadf..9d8a1d04431 100644 --- a/cmd/antrea-agent/agent.go +++ b/cmd/antrea-agent/agent.go @@ -108,7 +108,7 @@ func run(o *Options) error { crdInformerFactory := crdinformers.NewSharedInformerFactory(crdClient, informerDefaultResync) traceflowInformer := crdInformerFactory.Crd().V1alpha1().Traceflows() egressInformer := crdInformerFactory.Crd().V1alpha2().Egresses() - externalIPPoolInformer := crdInformerFactory.Crd().V1alpha2().ExternalIPPools() + externalIPPoolInformer := crdInformerFactory.Crd().V1beta1().ExternalIPPools() trafficControlInformer := crdInformerFactory.Crd().V1alpha2().TrafficControls() nodeInformer := informerFactory.Core().V1().Nodes() serviceInformer := informerFactory.Core().V1().Services() diff --git a/cmd/antrea-controller/controller.go b/cmd/antrea-controller/controller.go index f2655b15289..5dbc5e1ae73 100644 --- a/cmd/antrea-controller/controller.go +++ b/cmd/antrea-controller/controller.go @@ -142,7 +142,7 @@ func run(o *Options) error { cgInformer := crdInformerFactory.Crd().V1alpha3().ClusterGroups() grpInformer := crdInformerFactory.Crd().V1alpha3().Groups() egressInformer := crdInformerFactory.Crd().V1alpha2().Egresses() - externalIPPoolInformer := crdInformerFactory.Crd().V1alpha2().ExternalIPPools() + externalIPPoolInformer := crdInformerFactory.Crd().V1beta1().ExternalIPPools() externalNodeInformer := crdInformerFactory.Crd().V1alpha1().ExternalNodes() // Add IP-Pod index. Each Pod has no more than 2 IPs, the extra overhead is constant and acceptable. diff --git a/docs/api.md b/docs/api.md index 926930618d8..4d7df9d6bef 100644 --- a/docs/api.md +++ b/docs/api.md @@ -32,7 +32,7 @@ These are the CRDs currently available in `crd.antrea.io`. | `ClusterNetworkPolicy` | v1alpha1 | v1.0.0 | N/A | N/A | | `Egress` | v1alpha2 | v1.0.0 | N/A | N/A | | `ExternalEntity` | v1alpha2 | v1.0.0 | N/A | N/A | -| `ExternalIPPool` | v1alpha2 | v1.2.0 | N/A | N/A | +| `ExternalIPPool` | v1beta1 | v1.13.0 | N/A | N/A | | `Group` | v1alpha3 | v1.8.0 | N/A | N/A | | `NetworkPolicy` | v1alpha1 | v1.0.0 | N/A | N/A | | `Tier` | v1alpha1 | v1.0.0 | N/A | N/A | @@ -70,6 +70,7 @@ These are the API group versions which are curently available when using Antrea. | CRD | CRD version | Introduced in | Deprecated in | Removed in | |---|---|---|---|---| | `ClusterGroup` | v1alpha2 | v1.0.0 | v1.1.0 | v1.12.0 [^1] | +| `ExternalIPPool` | v1alpha2 | v1.2.0 | v1.13.0 | N/A | [^1]: The v1alpha2 version of the `ClusterGroup` CRD is no longer served by the apiserver in v1.12 and is completely removed in v1.13. diff --git a/docs/egress.md b/docs/egress.md index dd44af45f4b..2829ee92c1d 100644 --- a/docs/egress.md +++ b/docs/egress.md @@ -134,7 +134,7 @@ external network. The IPs in the pool can be allocated to the Egress resources as the Egress IPs. A typical ExternalIPPool resource example: ```yaml -apiVersion: crd.antrea.io/v1alpha2 +apiVersion: crd.antrea.io/v1beta1 kind: ExternalIPPool metadata: name: prod-external-ip-pool @@ -173,7 +173,7 @@ First, create an `ExternalIPPool` with a list of external routable IPs on the network. ```yaml -apiVersion: crd.antrea.io/v1alpha2 +apiVersion: crd.antrea.io/v1beta1 kind: ExternalIPPool metadata: name: external-ip-pool diff --git a/pkg/agent/memberlist/cluster.go b/pkg/agent/memberlist/cluster.go index c8338775ec9..f52cf68629a 100644 --- a/pkg/agent/memberlist/cluster.go +++ b/pkg/agent/memberlist/cluster.go @@ -37,9 +37,9 @@ import ( "k8s.io/klog/v2" "antrea.io/antrea/pkg/agent/consistenthash" - "antrea.io/antrea/pkg/apis/crd/v1alpha2" - crdinformers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1alpha2" - crdlister "antrea.io/antrea/pkg/client/listers/crd/v1alpha2" + "antrea.io/antrea/pkg/apis/crd/v1beta1" + crdinformers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1beta1" + crdlister "antrea.io/antrea/pkg/client/listers/crd/v1beta1" "antrea.io/antrea/pkg/util/k8s" ) @@ -187,8 +187,8 @@ func NewCluster( cache.ResourceEventHandlerFuncs{ AddFunc: c.enqueueExternalIPPool, UpdateFunc: func(oldObj, newObj interface{}) { - oldExternalIPPool := oldObj.(*v1alpha2.ExternalIPPool) - curExternalIPPool := newObj.(*v1alpha2.ExternalIPPool) + oldExternalIPPool := oldObj.(*v1beta1.ExternalIPPool) + curExternalIPPool := newObj.(*v1beta1.ExternalIPPool) if !reflect.DeepEqual(oldExternalIPPool.Spec.NodeSelector, curExternalIPPool.Spec.NodeSelector) { c.enqueueExternalIPPool(newObj) } @@ -262,14 +262,14 @@ func (c *Cluster) enqueueExternalIPPools(eips sets.Set[string]) { } func (c *Cluster) enqueueExternalIPPool(obj interface{}) { - eip, ok := obj.(*v1alpha2.ExternalIPPool) + eip, ok := obj.(*v1beta1.ExternalIPPool) if !ok { deletedState, ok := obj.(cache.DeletedFinalStateUnknown) if !ok { klog.ErrorS(errDecodingObject, "Processing ExternalIPPool DELETE event error", "obj", obj) return } - eip, ok = deletedState.Obj.(*v1alpha2.ExternalIPPool) + eip, ok = deletedState.Obj.(*v1beta1.ExternalIPPool) if !ok { klog.ErrorS(errDecodingObjectTombstone, "Processing ExternalIPPool DELETE event error", "obj", deletedState.Obj) return @@ -434,7 +434,7 @@ func (c *Cluster) syncConsistentHash(eipName string) error { } // updateConsistentHash refreshes the consistentHashMap. - updateConsistentHash := func(eip *v1alpha2.ExternalIPPool) error { + updateConsistentHash := func(eip *v1beta1.ExternalIPPool) error { nodeSel, err := metav1.LabelSelectorAsSelector(&eip.Spec.NodeSelector) if err != nil { return fmt.Errorf("labelSelectorAsSelector error: %v", err) diff --git a/pkg/agent/memberlist/cluster_test.go b/pkg/agent/memberlist/cluster_test.go index ca472407a65..73513dce17b 100644 --- a/pkg/agent/memberlist/cluster_test.go +++ b/pkg/agent/memberlist/cluster_test.go @@ -36,6 +36,7 @@ import ( "antrea.io/antrea/pkg/agent/consistenthash" "antrea.io/antrea/pkg/apis" 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" crdinformers "antrea.io/antrea/pkg/client/informers/externalversions" "antrea.io/antrea/pkg/util/ip" @@ -54,7 +55,7 @@ func newFakeCluster(nodeConfig *config.NodeConfig, stopCh <-chan struct{}, membe nodeInformer := informerFactory.Core().V1().Nodes() crdClient := fakeversioned.NewSimpleClientset() crdInformerFactory := crdinformers.NewSharedInformerFactory(crdClient, 0) - ipPoolInformer := crdInformerFactory.Crd().V1alpha2().ExternalIPPools() + ipPoolInformer := crdInformerFactory.Crd().V1beta1().ExternalIPPools() cluster, err := NewCluster(nodeConfig.NodeIPv4Addr.IP, apis.AntreaAgentClusterMembershipPort, nodeConfig.Name, nodeInformer, ipPoolInformer, memberlist) if err != nil { return nil, err @@ -81,8 +82,8 @@ func createNode(cs *fake.Clientset, node *v1.Node) error { return nil } -func createExternalIPPool(crdClient *fakeversioned.Clientset, eip *crdv1a2.ExternalIPPool) error { - _, err := crdClient.CrdV1alpha2().ExternalIPPools().Create(context.TODO(), eip, metav1.CreateOptions{}) +func createExternalIPPool(crdClient *fakeversioned.Clientset, eip *crdv1b1.ExternalIPPool) error { + _, err := crdClient.CrdV1beta1().ExternalIPPools().Create(context.TODO(), eip, metav1.CreateOptions{}) if err != nil { return err } @@ -94,7 +95,7 @@ func TestCluster_Run(t *testing.T) { testCases := []struct { name string egress *crdv1a2.Egress - externalIPPool *crdv1a2.ExternalIPPool + externalIPPool *crdv1b1.ExternalIPPool localNode *v1.Node expectEgressSelectResult bool }{ @@ -103,10 +104,10 @@ func TestCluster_Run(t *testing.T) { egress: &crdv1a2.Egress{ Spec: crdv1a2.EgressSpec{ExternalIPPool: "", EgressIP: "1.1.1.1"}, }, - externalIPPool: &crdv1a2.ExternalIPPool{ + externalIPPool: &crdv1b1.ExternalIPPool{ TypeMeta: metav1.TypeMeta{Kind: "CustomResourceDefinition"}, ObjectMeta: metav1.ObjectMeta{Name: "fakeExternalIPPool"}, - Spec: crdv1a2.ExternalIPPoolSpec{NodeSelector: metav1.LabelSelector{MatchLabels: map[string]string{"env": "pro"}}}, + Spec: crdv1b1.ExternalIPPoolSpec{NodeSelector: metav1.LabelSelector{MatchLabels: map[string]string{"env": "pro"}}}, }, localNode: &v1.Node{ ObjectMeta: metav1.ObjectMeta{Name: localNodeName, Labels: map[string]string{"env": "pro"}}, @@ -119,10 +120,10 @@ func TestCluster_Run(t *testing.T) { egress: &crdv1a2.Egress{ Spec: crdv1a2.EgressSpec{ExternalIPPool: "", EgressIP: "1.1.1.1"}, }, - externalIPPool: &crdv1a2.ExternalIPPool{ + externalIPPool: &crdv1b1.ExternalIPPool{ TypeMeta: metav1.TypeMeta{Kind: "CustomResourceDefinition"}, ObjectMeta: metav1.ObjectMeta{Name: "fakeExternalIPPool1"}, - Spec: crdv1a2.ExternalIPPoolSpec{NodeSelector: metav1.LabelSelector{MatchLabels: map[string]string{"env": "pro"}}}, + Spec: crdv1b1.ExternalIPPoolSpec{NodeSelector: metav1.LabelSelector{MatchLabels: map[string]string{"env": "pro"}}}, }, localNode: &v1.Node{ ObjectMeta: metav1.ObjectMeta{Name: localNodeName}, @@ -192,10 +193,10 @@ func TestCluster_RunClusterEvents(t *testing.T) { localNode := &v1.Node{ ObjectMeta: metav1.ObjectMeta{Name: nodeName}, Status: v1.NodeStatus{Addresses: []v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "127.0.0.1"}}}} - fakeEIP1 := &crdv1a2.ExternalIPPool{ + fakeEIP1 := &crdv1b1.ExternalIPPool{ TypeMeta: metav1.TypeMeta{Kind: "CustomResourceDefinition"}, ObjectMeta: metav1.ObjectMeta{Name: "fakeExternalIPPool1"}, - Spec: crdv1a2.ExternalIPPoolSpec{NodeSelector: metav1.LabelSelector{MatchLabels: map[string]string{"env": "pro"}}}, + Spec: crdv1b1.ExternalIPPoolSpec{NodeSelector: metav1.LabelSelector{MatchLabels: map[string]string{"env": "pro"}}}, } fakeEgress1 := &crdv1a2.Egress{ ObjectMeta: metav1.ObjectMeta{Name: "fakeEgress1", UID: "fakeUID1"}, @@ -301,7 +302,7 @@ func TestCluster_RunClusterEvents(t *testing.T) { for _, tCase := range testCasesUpdateEIP { t.Run(tCase.name, func(t *testing.T) { fakeEIP1.Spec.NodeSelector = tCase.newEIPnodeSelectors - _, err := fakeCluster.crdClient.CrdV1alpha2().ExternalIPPools().Update(context.TODO(), fakeEIP1, metav1.UpdateOptions{}) + _, err := fakeCluster.crdClient.CrdV1beta1().ExternalIPPools().Update(context.TODO(), fakeEIP1, metav1.UpdateOptions{}) if err != nil { t.Fatalf("Update ExternalIPPool error: %v", err) } @@ -313,14 +314,14 @@ func TestCluster_RunClusterEvents(t *testing.T) { } // Test creating new ExternalIPPool. - fakeEIP2 := &crdv1a2.ExternalIPPool{ + fakeEIP2 := &crdv1b1.ExternalIPPool{ TypeMeta: metav1.TypeMeta{ Kind: "CustomResourceDefinition", }, ObjectMeta: metav1.ObjectMeta{ Name: "fakeExternalIPPool2", }, - Spec: crdv1a2.ExternalIPPoolSpec{NodeSelector: metav1.LabelSelector{MatchLabels: map[string]string{"env": "test"}}}, + Spec: crdv1b1.ExternalIPPoolSpec{NodeSelector: metav1.LabelSelector{MatchLabels: map[string]string{"env": "test"}}}, } fakeEgressIP2 := "1.1.1.2" fakeEgress2 := &crdv1a2.Egress{ @@ -343,7 +344,7 @@ func TestCluster_RunClusterEvents(t *testing.T) { // Test deleting ExternalIPPool. deleteExternalIPPool := func(eipName string) { - err := fakeCluster.crdClient.CrdV1alpha2().ExternalIPPools().Delete(context.TODO(), eipName, metav1.DeleteOptions{}) + err := fakeCluster.crdClient.CrdV1beta1().ExternalIPPools().Delete(context.TODO(), eipName, metav1.DeleteOptions{}) if err != nil { t.Fatalf("Delete ExternalIPPool error: %v", err) } diff --git a/pkg/apis/crd/v1beta1/register.go b/pkg/apis/crd/v1beta1/register.go index 7ff2c5e2d64..3d08c419512 100644 --- a/pkg/apis/crd/v1beta1/register.go +++ b/pkg/apis/crd/v1beta1/register.go @@ -46,6 +46,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &AntreaControllerInfoList{}, &AntreaAgentInfo{}, &AntreaAgentInfoList{}, + &ExternalIPPool{}, + &ExternalIPPoolList{}, ) metav1.AddToGroupVersion( diff --git a/pkg/apis/crd/v1beta1/types.go b/pkg/apis/crd/v1beta1/types.go index 80962b6c4bf..52a44118f51 100644 --- a/pkg/apis/crd/v1beta1/types.go +++ b/pkg/apis/crd/v1beta1/types.go @@ -154,3 +154,59 @@ type ControllerCondition struct { // Human readable message indicating details Message string `json:"message,omitempty"` } + +// +genclient +// +genclient:nonNamespaced +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// ExternalIPPool defines one or multiple IP sets that can be used in the external network. For instance, the IPs can be +// allocated to the Egress resources as the Egress IPs. +type ExternalIPPool struct { + metav1.TypeMeta `json:",inline"` + // Standard metadata of the object. + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Specification of the ExternalIPPool. + Spec ExternalIPPoolSpec `json:"spec"` + + // The current status of the ExternalIPPool. + Status ExternalIPPoolStatus `json:"status"` +} + +type ExternalIPPoolSpec struct { + // 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 Nodes that the external IPs can be assigned to. If empty, it means all Nodes. + NodeSelector metav1.LabelSelector `json:"nodeSelector"` +} + +// IPRange is a set of contiguous IP addresses, represented by a CIDR or a pair of start and end IPs. +type IPRange struct { + // The CIDR of this range, e.g. 10.10.10.0/24. + CIDR string `json:"cidr,omitempty"` + // The start IP of the range, e.g. 10.10.20.5, inclusive. + Start string `json:"start,omitempty"` + // The end IP of the range, e.g. 10.10.20.20, inclusive. + End string `json:"end,omitempty"` +} + +type ExternalIPPoolStatus struct { + Usage IPPoolUsage `json:"usage,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type ExternalIPPoolList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata,omitempty"` + + Items []ExternalIPPool `json:"items"` +} + +type IPPoolUsage struct { + // Total number of IPs. + Total int `json:"total"` + // Number of allocated IPs. + Used int `json:"used"` +} diff --git a/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go b/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go index ab06a42283f..3c4032d6be0 100644 --- a/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go @@ -207,6 +207,138 @@ func (in *ControllerCondition) DeepCopy() *ControllerCondition { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExternalIPPool) DeepCopyInto(out *ExternalIPPool) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalIPPool. +func (in *ExternalIPPool) DeepCopy() *ExternalIPPool { + if in == nil { + return nil + } + out := new(ExternalIPPool) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ExternalIPPool) 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 *ExternalIPPoolList) DeepCopyInto(out *ExternalIPPoolList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ExternalIPPool, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalIPPoolList. +func (in *ExternalIPPoolList) DeepCopy() *ExternalIPPoolList { + if in == nil { + return nil + } + out := new(ExternalIPPoolList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ExternalIPPoolList) 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 *ExternalIPPoolSpec) DeepCopyInto(out *ExternalIPPoolSpec) { + *out = *in + if in.IPRanges != nil { + in, out := &in.IPRanges, &out.IPRanges + *out = make([]IPRange, len(*in)) + copy(*out, *in) + } + in.NodeSelector.DeepCopyInto(&out.NodeSelector) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalIPPoolSpec. +func (in *ExternalIPPoolSpec) DeepCopy() *ExternalIPPoolSpec { + if in == nil { + return nil + } + out := new(ExternalIPPoolSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExternalIPPoolStatus) DeepCopyInto(out *ExternalIPPoolStatus) { + *out = *in + out.Usage = in.Usage + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalIPPoolStatus. +func (in *ExternalIPPoolStatus) DeepCopy() *ExternalIPPoolStatus { + if in == nil { + return nil + } + out := new(ExternalIPPoolStatus) + 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 + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPPoolUsage. +func (in *IPPoolUsage) DeepCopy() *IPPoolUsage { + if in == nil { + return nil + } + out := new(IPPoolUsage) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPRange) DeepCopyInto(out *IPRange) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPRange. +func (in *IPRange) DeepCopy() *IPRange { + if in == nil { + return nil + } + out := new(IPRange) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NetworkPolicyControllerInfo) DeepCopyInto(out *NetworkPolicyControllerInfo) { *out = *in diff --git a/pkg/apiserver/openapi/zz_generated.openapi.go b/pkg/apiserver/openapi/zz_generated.openapi.go index fe220e3d179..320c726ec8d 100644 --- a/pkg/apiserver/openapi/zz_generated.openapi.go +++ b/pkg/apiserver/openapi/zz_generated.openapi.go @@ -78,6 +78,12 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "antrea.io/antrea/pkg/apis/crd/v1beta1.AntreaControllerInfo": schema_pkg_apis_crd_v1beta1_AntreaControllerInfo(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.AntreaControllerInfoList": schema_pkg_apis_crd_v1beta1_AntreaControllerInfoList(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.ControllerCondition": schema_pkg_apis_crd_v1beta1_ControllerCondition(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.ExternalIPPool": schema_pkg_apis_crd_v1beta1_ExternalIPPool(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.ExternalIPPoolList": schema_pkg_apis_crd_v1beta1_ExternalIPPoolList(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.ExternalIPPoolSpec": schema_pkg_apis_crd_v1beta1_ExternalIPPoolSpec(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.ExternalIPPoolStatus": schema_pkg_apis_crd_v1beta1_ExternalIPPoolStatus(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.NetworkPolicyControllerInfo": schema_pkg_apis_crd_v1beta1_NetworkPolicyControllerInfo(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.OVSInfo": schema_pkg_apis_crd_v1beta1_OVSInfo(ref), "antrea.io/antrea/pkg/apis/stats/v1alpha1.AntreaClusterNetworkPolicyStats": schema_pkg_apis_stats_v1alpha1_AntreaClusterNetworkPolicyStats(ref), @@ -2821,6 +2827,224 @@ func schema_pkg_apis_crd_v1beta1_ControllerCondition(ref common.ReferenceCallbac } } +func schema_pkg_apis_crd_v1beta1_ExternalIPPool(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "ExternalIPPool defines one or multiple IP sets that can be used in the external network. For instance, the IPs can be allocated to the Egress resources as the Egress IPs.", + 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 ExternalIPPool.", + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.ExternalIPPoolSpec"), + }, + }, + "status": { + SchemaProps: spec.SchemaProps{ + Description: "The current status of the ExternalIPPool.", + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.ExternalIPPoolStatus"), + }, + }, + }, + Required: []string{"spec", "status"}, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.ExternalIPPoolSpec", "antrea.io/antrea/pkg/apis/crd/v1beta1.ExternalIPPoolStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, + } +} + +func schema_pkg_apis_crd_v1beta1_ExternalIPPoolList(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.ExternalIPPool"), + }, + }, + }, + }, + }, + }, + Required: []string{"items"}, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.ExternalIPPool", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, + } +} + +func schema_pkg_apis_crd_v1beta1_ExternalIPPoolSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "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"), + }, + }, + }, + }, + }, + "nodeSelector": { + SchemaProps: spec.SchemaProps{ + Description: "The Nodes that the external IPs can be assigned to. If empty, it means all Nodes.", + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.LabelSelector"), + }, + }, + }, + Required: []string{"ipRanges", "nodeSelector"}, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.IPRange", "k8s.io/apimachinery/pkg/apis/meta/v1.LabelSelector"}, + } +} + +func schema_pkg_apis_crd_v1beta1_ExternalIPPoolStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "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.IPPoolUsage"}, + } +} + +func schema_pkg_apis_crd_v1beta1_IPPoolUsage(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "total": { + SchemaProps: spec.SchemaProps{ + Description: "Total number of IPs.", + Default: 0, + Type: []string{"integer"}, + Format: "int32", + }, + }, + "used": { + SchemaProps: spec.SchemaProps{ + Description: "Number of allocated IPs.", + Default: 0, + Type: []string{"integer"}, + Format: "int32", + }, + }, + }, + Required: []string{"total", "used"}, + }, + }, + } +} + +func schema_pkg_apis_crd_v1beta1_IPRange(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "IPRange is a set of contiguous IP addresses, represented by a CIDR or a pair of start and end IPs.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "cidr": { + SchemaProps: spec.SchemaProps{ + Description: "The CIDR of this range, e.g. 10.10.10.0/24.", + Type: []string{"string"}, + Format: "", + }, + }, + "start": { + SchemaProps: spec.SchemaProps{ + Description: "The start IP of the range, e.g. 10.10.20.5, inclusive.", + Type: []string{"string"}, + Format: "", + }, + }, + "end": { + SchemaProps: spec.SchemaProps{ + Description: "The end IP of the range, e.g. 10.10.20.20, inclusive.", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + } +} + func schema_pkg_apis_crd_v1beta1_NetworkPolicyControllerInfo(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 672e970dcba..a272e9a0314 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 2022 Antrea Authors +// Copyright 2023 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,6 +28,7 @@ type CrdV1beta1Interface interface { RESTClient() rest.Interface AntreaAgentInfosGetter AntreaControllerInfosGetter + ExternalIPPoolsGetter } // CrdV1beta1Client is used to interact with features provided by the crd.antrea.io group. @@ -43,6 +44,10 @@ func (c *CrdV1beta1Client) AntreaControllerInfos() AntreaControllerInfoInterface return newAntreaControllerInfos(c) } +func (c *CrdV1beta1Client) ExternalIPPools() ExternalIPPoolInterface { + return newExternalIPPools(c) +} + // NewForConfig creates a new CrdV1beta1Client for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/externalippool.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/externalippool.go new file mode 100644 index 00000000000..95f8950f772 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/externalippool.go @@ -0,0 +1,182 @@ +// Copyright 2023 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" +) + +// ExternalIPPoolsGetter has a method to return a ExternalIPPoolInterface. +// A group's client should implement this interface. +type ExternalIPPoolsGetter interface { + ExternalIPPools() ExternalIPPoolInterface +} + +// ExternalIPPoolInterface has methods to work with ExternalIPPool resources. +type ExternalIPPoolInterface interface { + Create(ctx context.Context, externalIPPool *v1beta1.ExternalIPPool, opts v1.CreateOptions) (*v1beta1.ExternalIPPool, error) + Update(ctx context.Context, externalIPPool *v1beta1.ExternalIPPool, opts v1.UpdateOptions) (*v1beta1.ExternalIPPool, error) + UpdateStatus(ctx context.Context, externalIPPool *v1beta1.ExternalIPPool, opts v1.UpdateOptions) (*v1beta1.ExternalIPPool, 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.ExternalIPPool, error) + List(ctx context.Context, opts v1.ListOptions) (*v1beta1.ExternalIPPoolList, 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.ExternalIPPool, err error) + ExternalIPPoolExpansion +} + +// externalIPPools implements ExternalIPPoolInterface +type externalIPPools struct { + client rest.Interface +} + +// newExternalIPPools returns a ExternalIPPools +func newExternalIPPools(c *CrdV1beta1Client) *externalIPPools { + return &externalIPPools{ + client: c.RESTClient(), + } +} + +// Get takes name of the externalIPPool, and returns the corresponding externalIPPool object, and an error if there is any. +func (c *externalIPPools) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.ExternalIPPool, err error) { + result = &v1beta1.ExternalIPPool{} + err = c.client.Get(). + Resource("externalippools"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of ExternalIPPools that match those selectors. +func (c *externalIPPools) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.ExternalIPPoolList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1beta1.ExternalIPPoolList{} + err = c.client.Get(). + Resource("externalippools"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested externalIPPools. +func (c *externalIPPools) 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("externalippools"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a externalIPPool and creates it. Returns the server's representation of the externalIPPool, and an error, if there is any. +func (c *externalIPPools) Create(ctx context.Context, externalIPPool *v1beta1.ExternalIPPool, opts v1.CreateOptions) (result *v1beta1.ExternalIPPool, err error) { + result = &v1beta1.ExternalIPPool{} + err = c.client.Post(). + Resource("externalippools"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(externalIPPool). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a externalIPPool and updates it. Returns the server's representation of the externalIPPool, and an error, if there is any. +func (c *externalIPPools) Update(ctx context.Context, externalIPPool *v1beta1.ExternalIPPool, opts v1.UpdateOptions) (result *v1beta1.ExternalIPPool, err error) { + result = &v1beta1.ExternalIPPool{} + err = c.client.Put(). + Resource("externalippools"). + Name(externalIPPool.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(externalIPPool). + 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 *externalIPPools) UpdateStatus(ctx context.Context, externalIPPool *v1beta1.ExternalIPPool, opts v1.UpdateOptions) (result *v1beta1.ExternalIPPool, err error) { + result = &v1beta1.ExternalIPPool{} + err = c.client.Put(). + Resource("externalippools"). + Name(externalIPPool.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(externalIPPool). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the externalIPPool and deletes it. Returns an error if one occurs. +func (c *externalIPPools) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Resource("externalippools"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *externalIPPools) 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("externalippools"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched externalIPPool. +func (c *externalIPPools) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.ExternalIPPool, err error) { + result = &v1beta1.ExternalIPPool{} + err = c.client.Patch(pt). + Resource("externalippools"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} 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 cc16e366e0b..54636034fab 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 2021 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -34,6 +34,10 @@ func (c *FakeCrdV1beta1) AntreaControllerInfos() v1beta1.AntreaControllerInfoInt return &FakeAntreaControllerInfos{c} } +func (c *FakeCrdV1beta1) ExternalIPPools() v1beta1.ExternalIPPoolInterface { + return &FakeExternalIPPools{c} +} + // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. func (c *FakeCrdV1beta1) RESTClient() rest.Interface { diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_externalippool.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_externalippool.go new file mode 100644 index 00000000000..8688bcd963d --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_externalippool.go @@ -0,0 +1,131 @@ +// Copyright 2023 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" +) + +// FakeExternalIPPools implements ExternalIPPoolInterface +type FakeExternalIPPools struct { + Fake *FakeCrdV1beta1 +} + +var externalippoolsResource = schema.GroupVersionResource{Group: "crd.antrea.io", Version: "v1beta1", Resource: "externalippools"} + +var externalippoolsKind = schema.GroupVersionKind{Group: "crd.antrea.io", Version: "v1beta1", Kind: "ExternalIPPool"} + +// Get takes name of the externalIPPool, and returns the corresponding externalIPPool object, and an error if there is any. +func (c *FakeExternalIPPools) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.ExternalIPPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(externalippoolsResource, name), &v1beta1.ExternalIPPool{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.ExternalIPPool), err +} + +// List takes label and field selectors, and returns the list of ExternalIPPools that match those selectors. +func (c *FakeExternalIPPools) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.ExternalIPPoolList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(externalippoolsResource, externalippoolsKind, opts), &v1beta1.ExternalIPPoolList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1beta1.ExternalIPPoolList{ListMeta: obj.(*v1beta1.ExternalIPPoolList).ListMeta} + for _, item := range obj.(*v1beta1.ExternalIPPoolList).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 externalIPPools. +func (c *FakeExternalIPPools) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(externalippoolsResource, opts)) +} + +// Create takes the representation of a externalIPPool and creates it. Returns the server's representation of the externalIPPool, and an error, if there is any. +func (c *FakeExternalIPPools) Create(ctx context.Context, externalIPPool *v1beta1.ExternalIPPool, opts v1.CreateOptions) (result *v1beta1.ExternalIPPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(externalippoolsResource, externalIPPool), &v1beta1.ExternalIPPool{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.ExternalIPPool), err +} + +// Update takes the representation of a externalIPPool and updates it. Returns the server's representation of the externalIPPool, and an error, if there is any. +func (c *FakeExternalIPPools) Update(ctx context.Context, externalIPPool *v1beta1.ExternalIPPool, opts v1.UpdateOptions) (result *v1beta1.ExternalIPPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(externalippoolsResource, externalIPPool), &v1beta1.ExternalIPPool{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.ExternalIPPool), 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 *FakeExternalIPPools) UpdateStatus(ctx context.Context, externalIPPool *v1beta1.ExternalIPPool, opts v1.UpdateOptions) (*v1beta1.ExternalIPPool, error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceAction(externalippoolsResource, "status", externalIPPool), &v1beta1.ExternalIPPool{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.ExternalIPPool), err +} + +// Delete takes name of the externalIPPool and deletes it. Returns an error if one occurs. +func (c *FakeExternalIPPools) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteActionWithOptions(externalippoolsResource, name, opts), &v1beta1.ExternalIPPool{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeExternalIPPools) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(externalippoolsResource, listOpts) + + _, err := c.Fake.Invokes(action, &v1beta1.ExternalIPPoolList{}) + return err +} + +// Patch applies the patch and returns the patched externalIPPool. +func (c *FakeExternalIPPools) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.ExternalIPPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(externalippoolsResource, name, pt, data, subresources...), &v1beta1.ExternalIPPool{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.ExternalIPPool), 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 9e4c79f4934..fc423008303 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 2021 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,3 +19,5 @@ package v1beta1 type AntreaAgentInfoExpansion interface{} type AntreaControllerInfoExpansion interface{} + +type ExternalIPPoolExpansion interface{} diff --git a/pkg/client/informers/externalversions/crd/v1beta1/externalippool.go b/pkg/client/informers/externalversions/crd/v1beta1/externalippool.go new file mode 100644 index 00000000000..f17e9ddb3df --- /dev/null +++ b/pkg/client/informers/externalversions/crd/v1beta1/externalippool.go @@ -0,0 +1,87 @@ +// Copyright 2023 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" +) + +// ExternalIPPoolInformer provides access to a shared informer and lister for +// ExternalIPPools. +type ExternalIPPoolInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1beta1.ExternalIPPoolLister +} + +type externalIPPoolInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewExternalIPPoolInformer constructs a new informer for ExternalIPPool 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 NewExternalIPPoolInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredExternalIPPoolInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredExternalIPPoolInformer constructs a new informer for ExternalIPPool 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 NewFilteredExternalIPPoolInformer(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().ExternalIPPools().List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CrdV1beta1().ExternalIPPools().Watch(context.TODO(), options) + }, + }, + &crdv1beta1.ExternalIPPool{}, + resyncPeriod, + indexers, + ) +} + +func (f *externalIPPoolInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredExternalIPPoolInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *externalIPPoolInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&crdv1beta1.ExternalIPPool{}, f.defaultInformer) +} + +func (f *externalIPPoolInformer) Lister() v1beta1.ExternalIPPoolLister { + return v1beta1.NewExternalIPPoolLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/crd/v1beta1/interface.go b/pkg/client/informers/externalversions/crd/v1beta1/interface.go index 79585d9e5c5..115265dc220 100644 --- a/pkg/client/informers/externalversions/crd/v1beta1/interface.go +++ b/pkg/client/informers/externalversions/crd/v1beta1/interface.go @@ -1,4 +1,4 @@ -// Copyright 2021 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -26,6 +26,8 @@ type Interface interface { AntreaAgentInfos() AntreaAgentInfoInformer // AntreaControllerInfos returns a AntreaControllerInfoInformer. AntreaControllerInfos() AntreaControllerInfoInformer + // ExternalIPPools returns a ExternalIPPoolInformer. + ExternalIPPools() ExternalIPPoolInformer } type version struct { @@ -48,3 +50,8 @@ func (v *version) AntreaAgentInfos() AntreaAgentInfoInformer { func (v *version) AntreaControllerInfos() AntreaControllerInfoInformer { return &antreaControllerInfoInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// ExternalIPPools returns a ExternalIPPoolInformer. +func (v *version) ExternalIPPools() ExternalIPPoolInformer { + return &externalIPPoolInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index c706d13834c..7bde3fd8f30 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -1,4 +1,4 @@ -// Copyright 2022 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -92,6 +92,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1beta1().AntreaAgentInfos().Informer()}, nil case v1beta1.SchemeGroupVersion.WithResource("antreacontrollerinfos"): return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1beta1().AntreaControllerInfos().Informer()}, nil + case v1beta1.SchemeGroupVersion.WithResource("externalippools"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1beta1().ExternalIPPools().Informer()}, nil } diff --git a/pkg/client/listers/crd/v1beta1/expansion_generated.go b/pkg/client/listers/crd/v1beta1/expansion_generated.go index 2181551a0c7..649b6eb33b2 100644 --- a/pkg/client/listers/crd/v1beta1/expansion_generated.go +++ b/pkg/client/listers/crd/v1beta1/expansion_generated.go @@ -1,4 +1,4 @@ -// Copyright 2021 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,3 +23,7 @@ type AntreaAgentInfoListerExpansion interface{} // AntreaControllerInfoListerExpansion allows custom methods to be added to // AntreaControllerInfoLister. type AntreaControllerInfoListerExpansion interface{} + +// ExternalIPPoolListerExpansion allows custom methods to be added to +// ExternalIPPoolLister. +type ExternalIPPoolListerExpansion interface{} diff --git a/pkg/client/listers/crd/v1beta1/externalippool.go b/pkg/client/listers/crd/v1beta1/externalippool.go new file mode 100644 index 00000000000..ae43d75391d --- /dev/null +++ b/pkg/client/listers/crd/v1beta1/externalippool.go @@ -0,0 +1,66 @@ +// Copyright 2023 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" +) + +// ExternalIPPoolLister helps list ExternalIPPools. +// All objects returned here must be treated as read-only. +type ExternalIPPoolLister interface { + // List lists all ExternalIPPools in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1beta1.ExternalIPPool, err error) + // Get retrieves the ExternalIPPool from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1beta1.ExternalIPPool, error) + ExternalIPPoolListerExpansion +} + +// externalIPPoolLister implements the ExternalIPPoolLister interface. +type externalIPPoolLister struct { + indexer cache.Indexer +} + +// NewExternalIPPoolLister returns a new ExternalIPPoolLister. +func NewExternalIPPoolLister(indexer cache.Indexer) ExternalIPPoolLister { + return &externalIPPoolLister{indexer: indexer} +} + +// List lists all ExternalIPPools in the indexer. +func (s *externalIPPoolLister) List(selector labels.Selector) (ret []*v1beta1.ExternalIPPool, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1beta1.ExternalIPPool)) + }) + return ret, err +} + +// Get retrieves the ExternalIPPool from the index for a given name. +func (s *externalIPPoolLister) Get(name string) (*v1beta1.ExternalIPPool, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1beta1.Resource("externalippool"), name) + } + return obj.(*v1beta1.ExternalIPPool), nil +} diff --git a/pkg/controller/egress/controller_test.go b/pkg/controller/egress/controller_test.go index a2e4d59fbe2..cf847c76a8d 100644 --- a/pkg/controller/egress/controller_test.go +++ b/pkg/controller/egress/controller_test.go @@ -39,6 +39,7 @@ import ( "antrea.io/antrea/pkg/apis/controlplane" "antrea.io/antrea/pkg/apis/crd/v1alpha2" + "antrea.io/antrea/pkg/apis/crd/v1beta1" "antrea.io/antrea/pkg/client/clientset/versioned" fakeversioned "antrea.io/antrea/pkg/client/clientset/versioned/fake" crdinformers "antrea.io/antrea/pkg/client/informers/externalversions" @@ -82,17 +83,17 @@ func newEgress(name, egressIP, externalIPPool string, podSelector, namespaceSele return egress } -func newExternalIPPool(name, cidr, start, end string) *v1alpha2.ExternalIPPool { - pool := &v1alpha2.ExternalIPPool{ +func newExternalIPPool(name, cidr, start, end string) *v1beta1.ExternalIPPool { + pool := &v1beta1.ExternalIPPool{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, } if len(cidr) > 0 { - pool.Spec.IPRanges = append(pool.Spec.IPRanges, v1alpha2.IPRange{CIDR: cidr}) + pool.Spec.IPRanges = append(pool.Spec.IPRanges, v1beta1.IPRange{CIDR: cidr}) } if len(start) > 0 && len(end) > 0 { - pool.Spec.IPRanges = append(pool.Spec.IPRanges, v1alpha2.IPRange{Start: start, End: end}) + pool.Spec.IPRanges = append(pool.Spec.IPRanges, v1beta1.IPRange{Start: start, End: end}) } return pool } @@ -180,7 +181,7 @@ func newController(objects, crdObjects []runtime.Object) *egressController { crdClient.PrependReactor("patch", "egresses", egressPatchReactor) informerFactory := informers.NewSharedInformerFactory(client, resyncPeriod) crdInformerFactory := crdinformers.NewSharedInformerFactory(crdClient, resyncPeriod) - externalIPAllocator := externalippool.NewExternalIPPoolController(crdClient, crdInformerFactory.Crd().V1alpha2().ExternalIPPools()) + externalIPAllocator := externalippool.NewExternalIPPoolController(crdClient, crdInformerFactory.Crd().V1beta1().ExternalIPPools()) egressGroupStore := store.NewEgressGroupStore() egressInformer := crdInformerFactory.Crd().V1alpha2().Egresses() groupEntityIndex := grouping.NewGroupEntityIndex() @@ -509,7 +510,7 @@ func TestUpdateEgress(t *testing.T) { checkExternalIPPoolUsed(t, controller, eipFoo2.Name, 1) // Delete the IPPool in use. The EgressIP should be released. - controller.crdClient.CrdV1alpha2().ExternalIPPools().Delete(context.TODO(), eipFoo2.Name, metav1.DeleteOptions{}) + controller.crdClient.CrdV1beta1().ExternalIPPools().Delete(context.TODO(), eipFoo2.Name, metav1.DeleteOptions{}) assert.Eventually(t, func() bool { _, _, exists := controller.getIPAllocation(egress.Name) if exists { @@ -523,7 +524,7 @@ func TestUpdateEgress(t *testing.T) { }, time.Second, 50*time.Millisecond, "EgressIP was not deleted after the ExternalIPPool was deleted") // Recreate the ExternalIPPool. An EgressIP should be allocated. - controller.crdClient.CrdV1alpha2().ExternalIPPools().Create(context.TODO(), eipFoo2, metav1.CreateOptions{}) + controller.crdClient.CrdV1beta1().ExternalIPPools().Create(context.TODO(), eipFoo2, metav1.CreateOptions{}) assert.Eventually(t, func() bool { _, _, exists := controller.getIPAllocation(egress.Name) return exists @@ -543,7 +544,7 @@ func TestSyncEgressIP(t *testing.T) { tests := []struct { name string existingEgresses []*v1alpha2.Egress - existingExternalIPPool *v1alpha2.ExternalIPPool + existingExternalIPPool *v1beta1.ExternalIPPool inputEgress *v1alpha2.Egress expectedEgressIP string expectedExternalIPPoolUsed int @@ -758,7 +759,7 @@ func checkExternalIPPoolUsed(t *testing.T, controller *egressController, poolNam exists := controller.externalIPAllocator.IPPoolExists(poolName) require.True(t, exists) err := wait.PollImmediate(50*time.Millisecond, 2*time.Second, func() (found bool, err error) { - eip, err := controller.crdClient.CrdV1alpha2().ExternalIPPools().Get(context.TODO(), poolName, metav1.GetOptions{}) + eip, err := controller.crdClient.CrdV1beta1().ExternalIPPools().Get(context.TODO(), poolName, metav1.GetOptions{}) if err != nil { return false, err } diff --git a/pkg/controller/egress/validate_test.go b/pkg/controller/egress/validate_test.go index e5496d679f5..29105707337 100644 --- a/pkg/controller/egress/validate_test.go +++ b/pkg/controller/egress/validate_test.go @@ -25,7 +25,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/tools/cache" - crdv1alpha2 "antrea.io/antrea/pkg/apis/crd/v1alpha2" + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" ) func marshal(object runtime.Object) []byte { @@ -36,7 +36,7 @@ func marshal(object runtime.Object) []byte { func TestEgressControllerValidateEgress(t *testing.T) { tests := []struct { name string - existingExternalIPPool *crdv1alpha2.ExternalIPPool + existingExternalIPPool *crdv1beta1.ExternalIPPool request *admv1.AdmissionRequest expectedResponse *admv1.AdmissionResponse }{ diff --git a/pkg/controller/externalippool/controller.go b/pkg/controller/externalippool/controller.go index 3cca6c83d1f..b51f09cb84e 100644 --- a/pkg/controller/externalippool/controller.go +++ b/pkg/controller/externalippool/controller.go @@ -35,10 +35,10 @@ import ( "k8s.io/klog/v2" utilnet "k8s.io/utils/net" - antreacrds "antrea.io/antrea/pkg/apis/crd/v1alpha2" + antreacrds "antrea.io/antrea/pkg/apis/crd/v1beta1" clientset "antrea.io/antrea/pkg/client/clientset/versioned" - antreainformers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1alpha2" - antrealisters "antrea.io/antrea/pkg/client/listers/crd/v1alpha2" + antreainformers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1beta1" + antrealisters "antrea.io/antrea/pkg/client/listers/crd/v1beta1" "antrea.io/antrea/pkg/controller/metrics" "antrea.io/antrea/pkg/ipam/ipallocator" iputil "antrea.io/antrea/pkg/util/ip" @@ -314,8 +314,8 @@ func (c *ExternalIPPoolController) updateExternalIPPoolStatus(poolName string) e } klog.V(2).InfoS("Updating ExternalIPPool status", "ExternalIPPool", poolName, "usage", usage) toUpdate.Status.Usage = usage - if _, updateErr := c.crdClient.CrdV1alpha2().ExternalIPPools().UpdateStatus(context.TODO(), toUpdate, metav1.UpdateOptions{}); updateErr != nil && apierrors.IsConflict(updateErr) { - toUpdate, getErr = c.crdClient.CrdV1alpha2().ExternalIPPools().Get(context.TODO(), poolName, metav1.GetOptions{}) + if _, updateErr := c.crdClient.CrdV1beta1().ExternalIPPools().UpdateStatus(context.TODO(), toUpdate, metav1.UpdateOptions{}); updateErr != nil && apierrors.IsConflict(updateErr) { + toUpdate, getErr = c.crdClient.CrdV1beta1().ExternalIPPools().Get(context.TODO(), poolName, metav1.GetOptions{}) if getErr != nil { return getErr } diff --git a/pkg/controller/externalippool/controller_test.go b/pkg/controller/externalippool/controller_test.go index 9e4e40e3c0f..3e8a3c594fc 100644 --- a/pkg/controller/externalippool/controller_test.go +++ b/pkg/controller/externalippool/controller_test.go @@ -29,7 +29,7 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/tools/cache" - antreacrds "antrea.io/antrea/pkg/apis/crd/v1alpha2" + antreacrds "antrea.io/antrea/pkg/apis/crd/v1beta1" "antrea.io/antrea/pkg/client/clientset/versioned" fakeversioned "antrea.io/antrea/pkg/client/clientset/versioned/fake" crdinformers "antrea.io/antrea/pkg/client/informers/externalversions" @@ -60,7 +60,7 @@ type controller struct { func newController(crdObjects []runtime.Object) *controller { crdClient := fakeversioned.NewSimpleClientset(crdObjects...) crdInformerFactory := crdinformers.NewSharedInformerFactory(crdClient, resyncPeriod) - externalIPPoolController := NewExternalIPPoolController(crdClient, crdInformerFactory.Crd().V1alpha2().ExternalIPPools()) + externalIPPoolController := NewExternalIPPoolController(crdClient, crdInformerFactory.Crd().V1beta1().ExternalIPPools()) return &controller{ externalIPPoolController, crdClient, @@ -296,7 +296,7 @@ func TestIPPoolEvents(t *testing.T) { go controller.Run(stopCh) require.True(t, cache.WaitForCacheSync(stopCh, controller.HasSynced)) // ADD event - eip, err := controller.crdClient.CrdV1alpha2().ExternalIPPools().Create(context, + eip, err := controller.crdClient.CrdV1beta1().ExternalIPPools().Create(context, newExternalIPPool("eip1", "", "10.10.10.2", "10.10.10.3"), metav1.CreateOptions{}, ) @@ -304,14 +304,14 @@ func TestIPPoolEvents(t *testing.T) { assert.Equal(t, "eip1", <-consumerCh) // UPDATE event eip.Spec.IPRanges[0].End = "10.10.10.4" - eip, err = controller.crdClient.CrdV1alpha2().ExternalIPPools().Update(context, + eip, err = controller.crdClient.CrdV1beta1().ExternalIPPools().Update(context, eip, metav1.UpdateOptions{}, ) require.NoError(t, err) assert.Equal(t, "eip1", <-consumerCh) // DELETE event - err = controller.crdClient.CrdV1alpha2().ExternalIPPools().Delete(context, + err = controller.crdClient.CrdV1beta1().ExternalIPPools().Delete(context, eip.Name, metav1.DeleteOptions{}, ) @@ -459,7 +459,7 @@ func checkExternalIPPoolStatus(t *testing.T, controller *controller, poolName st exists := controller.IPPoolExists(poolName) require.True(t, exists) err := wait.PollImmediate(50*time.Millisecond, 2*time.Second, func() (found bool, err error) { - eip, err := controller.crdClient.CrdV1alpha2().ExternalIPPools().Get(context.TODO(), poolName, metav1.GetOptions{}) + eip, err := controller.crdClient.CrdV1beta1().ExternalIPPools().Get(context.TODO(), poolName, metav1.GetOptions{}) if err != nil { return false, err } diff --git a/pkg/controller/externalippool/validate.go b/pkg/controller/externalippool/validate.go index e9d8b80e93a..f95ecaf6e6a 100644 --- a/pkg/controller/externalippool/validate.go +++ b/pkg/controller/externalippool/validate.go @@ -23,7 +23,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" - crdv1alpha2 "antrea.io/antrea/pkg/apis/crd/v1alpha2" + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" ) func (c *ExternalIPPoolController) ValidateExternalIPPool(review *admv1.AdmissionReview) *admv1.AdmissionResponse { @@ -32,7 +32,7 @@ func (c *ExternalIPPoolController) ValidateExternalIPPool(review *admv1.Admissio allowed := true klog.V(2).Info("Validating ExternalIPPool", "request", review.Request) - var newObj, oldObj crdv1alpha2.ExternalIPPool + var newObj, oldObj crdv1beta1.ExternalIPPool if review.Request.Object.Raw != nil { if err := json.Unmarshal(review.Request.Object.Raw, &newObj); err != nil { klog.ErrorS(err, "Error de-serializing current ExternalIPPool") @@ -77,7 +77,7 @@ func (c *ExternalIPPoolController) ValidateExternalIPPool(review *admv1.Admissio Result: result, } } -func getIPRangeSet(ipRanges []crdv1alpha2.IPRange) sets.Set[string] { +func getIPRangeSet(ipRanges []crdv1beta1.IPRange) sets.Set[string] { set := sets.New[string]() for _, ipRange := range ipRanges { ipRangeStr := ipRange.CIDR diff --git a/pkg/controller/serviceexternalip/controller_test.go b/pkg/controller/serviceexternalip/controller_test.go index 67ae8308398..a30716e970b 100644 --- a/pkg/controller/serviceexternalip/controller_test.go +++ b/pkg/controller/serviceexternalip/controller_test.go @@ -31,7 +31,7 @@ import ( "k8s.io/client-go/tools/cache" antreaagenttypes "antrea.io/antrea/pkg/agent/types" - antreacrds "antrea.io/antrea/pkg/apis/crd/v1alpha2" + antreacrds "antrea.io/antrea/pkg/apis/crd/v1beta1" "antrea.io/antrea/pkg/client/clientset/versioned" fakeversioned "antrea.io/antrea/pkg/client/clientset/versioned/fake" crdinformers "antrea.io/antrea/pkg/client/informers/externalversions" @@ -86,7 +86,7 @@ func newController(objects, crdObjects []runtime.Object) *loadBalancerController crdClient := fakeversioned.NewSimpleClientset(crdObjects...) informerFactory := informers.NewSharedInformerFactory(client, resyncPeriod) crdInformerFactory := crdinformers.NewSharedInformerFactory(crdClient, resyncPeriod) - externalIPPoolController := externalippool.NewExternalIPPoolController(crdClient, crdInformerFactory.Crd().V1alpha2().ExternalIPPools()) + externalIPPoolController := externalippool.NewExternalIPPoolController(crdClient, crdInformerFactory.Crd().V1beta1().ExternalIPPools()) controller := NewServiceExternalIPController(client, informerFactory.Core().V1().Services(), externalIPPoolController) return &loadBalancerController{ ServiceExternalIPController: controller, @@ -193,21 +193,21 @@ func TestSyncService(t *testing.T) { eip1 := newExternalIPPool("eip1", "", "1.2.3.4", "1.2.3.5") t.Run("IP pool eip1 created", func(t *testing.T) { - _, err = controller.crdClient.CrdV1alpha2().ExternalIPPools().Create(context.TODO(), eip1, metav1.CreateOptions{}) + _, err = controller.crdClient.CrdV1beta1().ExternalIPPools().Create(context.TODO(), eip1, metav1.CreateOptions{}) require.NoError(t, err) checkForServiceExternalIP(t, controller, service.Name, service.Namespace, "1.2.3.4") checkExternalIPPoolUsed(t, controller, "eip1", 1) }) t.Run("IP pool eip1 deleted", func(t *testing.T) { - err = controller.crdClient.CrdV1alpha2().ExternalIPPools().Delete(context.TODO(), eip1.Name, metav1.DeleteOptions{}) + err = controller.crdClient.CrdV1beta1().ExternalIPPools().Delete(context.TODO(), eip1.Name, metav1.DeleteOptions{}) assert.NoError(t, err) checkForServiceExternalIP(t, controller, service.Name, service.Namespace, "") }) t.Run("IP pool eip1 re-created", func(t *testing.T) { // Re-create ExternalIPPool. - _, err = controller.crdClient.CrdV1alpha2().ExternalIPPools().Create(context.TODO(), eip1, metav1.CreateOptions{}) + _, err = controller.crdClient.CrdV1beta1().ExternalIPPools().Create(context.TODO(), eip1, metav1.CreateOptions{}) require.NoError(t, err) checkForServiceExternalIP(t, controller, service.Name, service.Namespace, "1.2.3.4") checkExternalIPPoolUsed(t, controller, "eip1", 1) @@ -226,7 +226,7 @@ func TestSyncService(t *testing.T) { t.Run("IP pool eip2 created", func(t *testing.T) { // Create second ExternalIPPool. - _, err = controller.crdClient.CrdV1alpha2().ExternalIPPools().Create(context.TODO(), eip2, metav1.CreateOptions{}) + _, err = controller.crdClient.CrdV1beta1().ExternalIPPools().Create(context.TODO(), eip2, metav1.CreateOptions{}) require.NoError(t, err) checkForServiceExternalIP(t, controller, service.Name, service.Namespace, "1.2.4.4") checkExternalIPPoolUsed(t, controller, "eip1", 0) @@ -315,7 +315,7 @@ func checkExternalIPPoolUsed(t *testing.T, controller *loadBalancerController, p exists := controller.externalIPAllocator.IPPoolExists(poolName) require.True(t, exists) assert.Eventually(t, func() bool { - eip, err := controller.crdClient.CrdV1alpha2().ExternalIPPools().Get(context.TODO(), poolName, metav1.GetOptions{}) + eip, err := controller.crdClient.CrdV1beta1().ExternalIPPools().Get(context.TODO(), poolName, metav1.GetOptions{}) require.NoError(t, err) t.Logf("current status %#v", eip.Status) return eip.Status.Usage.Used == used