From 2cb6c199a4d28afb3aabe3e5f27cad86a19af53f Mon Sep 17 00:00:00 2001 From: Hongliang Liu Date: Tue, 6 Feb 2024 14:33:10 +0800 Subject: [PATCH] Add BGPPolicy API Signed-off-by: Hongliang Liu --- build/charts/antrea/crds/bgppolicy.yaml | 126 +++++++++++ build/yamls/antrea-aks.yml | 129 +++++++++++ build/yamls/antrea-crds.yml | 127 +++++++++++ build/yamls/antrea-eks.yml | 129 +++++++++++ build/yamls/antrea-gke.yml | 129 +++++++++++ build/yamls/antrea-ipsec.yml | 129 +++++++++++ build/yamls/antrea.yml | 129 +++++++++++ pkg/apis/crd/v1alpha1/register.go | 2 + pkg/apis/crd/v1alpha1/types.go | 102 +++++++++ .../crd/v1alpha1/zz_generated.deepcopy.go | 205 ++++++++++++++++++ .../versioned/typed/crd/v1alpha1/bgppolicy.go | 166 ++++++++++++++ .../typed/crd/v1alpha1/crd_client.go | 5 + .../typed/crd/v1alpha1/fake/fake_bgppolicy.go | 119 ++++++++++ .../crd/v1alpha1/fake/fake_crd_client.go | 4 + .../typed/crd/v1alpha1/generated_expansion.go | 2 + .../crd/v1alpha1/bgppolicy.go | 87 ++++++++ .../crd/v1alpha1/interface.go | 7 + .../informers/externalversions/generic.go | 2 + pkg/client/listers/crd/v1alpha1/bgppolicy.go | 66 ++++++ .../crd/v1alpha1/expansion_generated.go | 4 + 20 files changed, 1669 insertions(+) create mode 100644 build/charts/antrea/crds/bgppolicy.yaml create mode 100644 pkg/client/clientset/versioned/typed/crd/v1alpha1/bgppolicy.go create mode 100644 pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_bgppolicy.go create mode 100644 pkg/client/informers/externalversions/crd/v1alpha1/bgppolicy.go create mode 100644 pkg/client/listers/crd/v1alpha1/bgppolicy.go diff --git a/build/charts/antrea/crds/bgppolicy.yaml b/build/charts/antrea/crds/bgppolicy.yaml new file mode 100644 index 00000000000..1dd326f03e4 --- /dev/null +++ b/build/charts/antrea/crds/bgppolicy.yaml @@ -0,0 +1,126 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: bgppolicies.crd.antrea.io +spec: + group: crd.antrea.io + versions: + - name: v1alpha1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - nodeSelector + - localASN + properties: + 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 + localASN: + type: integer + format: int32 + minimum: 64512 + maximum: 65535 + listenPort: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + default: 179 + advertisements: + type: object + properties: + service: + type: object + properties: + ipTypes: + type: array + items: + type: string + enum: + - ClusterIP + - LoadBalancerIP + - ExternalIP + pod: + type: object + properties: {} + egress: + type: object + properties: {} + bgpPeers: + type: array + items: + type: object + required: + - address + - asn + properties: + address: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + port: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + default: 179 + asn: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + multihopTTL: + type: integer + format: int32 + minimum: 1 + maximum: 255 + default: 1 + gracefulRestartTimeSeconds: + type: integer + format: int32 + minimum: 1 + maximum: 3600 + default: 120 + additionalPrinterColumns: + - description: Local BGP AS number + jsonPath: .spec.localASN + name: Local ASN + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + scope: Cluster + names: + plural: bgppolicies + singular: bgppolicy + kind: BGPPolicy diff --git a/build/yamls/antrea-aks.yml b/build/yamls/antrea-aks.yml index 9655b66b5da..25020cd3e40 100644 --- a/build/yamls/antrea-aks.yml +++ b/build/yamls/antrea-aks.yml @@ -300,6 +300,135 @@ spec: shortNames: - aci +--- +# Source: crds/bgppolicy.yaml +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: bgppolicies.crd.antrea.io +spec: + group: crd.antrea.io + versions: + - name: v1alpha1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - nodeSelector + - localASN + properties: + 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 + localASN: + type: integer + format: int32 + minimum: 64512 + maximum: 65535 + listenPort: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + default: 179 + advertisements: + type: object + properties: + service: + type: object + properties: + ipTypes: + type: array + items: + type: string + enum: + - ClusterIP + - LoadBalancerIP + - ExternalIP + pod: + type: object + properties: {} + egress: + type: object + properties: {} + bgpPeers: + type: array + items: + type: object + required: + - address + - asn + properties: + address: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + port: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + default: 179 + asn: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + multihopTTL: + type: integer + format: int32 + minimum: 1 + maximum: 255 + default: 1 + gracefulRestartTimeSeconds: + type: integer + format: int32 + minimum: 1 + maximum: 3600 + default: 120 + additionalPrinterColumns: + - description: Local BGP AS number + jsonPath: .spec.localASN + name: Local ASN + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + scope: Cluster + names: + plural: bgppolicies + singular: bgppolicy + kind: BGPPolicy + --- # Source: crds/clustergroup.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/build/yamls/antrea-crds.yml b/build/yamls/antrea-crds.yml index c449e2ced17..7036bd85bbe 100644 --- a/build/yamls/antrea-crds.yml +++ b/build/yamls/antrea-crds.yml @@ -299,6 +299,133 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + name: bgppolicies.crd.antrea.io +spec: + group: crd.antrea.io + versions: + - name: v1alpha1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - nodeSelector + - localASN + properties: + 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 + localASN: + type: integer + format: int32 + minimum: 64512 + maximum: 65535 + listenPort: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + default: 179 + advertisements: + type: object + properties: + service: + type: object + properties: + ipTypes: + type: array + items: + type: string + enum: + - ClusterIP + - LoadBalancerIP + - ExternalIP + pod: + type: object + properties: {} + egress: + type: object + properties: {} + bgpPeers: + type: array + items: + type: object + required: + - address + - asn + properties: + address: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + port: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + default: 179 + asn: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + multihopTTL: + type: integer + format: int32 + minimum: 1 + maximum: 255 + default: 1 + gracefulRestartTimeSeconds: + type: integer + format: int32 + minimum: 1 + maximum: 3600 + default: 120 + additionalPrinterColumns: + - description: Local BGP AS number + jsonPath: .spec.localASN + name: Local ASN + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + scope: Cluster + names: + plural: bgppolicies + singular: bgppolicy + kind: BGPPolicy +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: name: clustergroups.crd.antrea.io labels: diff --git a/build/yamls/antrea-eks.yml b/build/yamls/antrea-eks.yml index d60cc445413..03ccfb2f46c 100644 --- a/build/yamls/antrea-eks.yml +++ b/build/yamls/antrea-eks.yml @@ -300,6 +300,135 @@ spec: shortNames: - aci +--- +# Source: crds/bgppolicy.yaml +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: bgppolicies.crd.antrea.io +spec: + group: crd.antrea.io + versions: + - name: v1alpha1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - nodeSelector + - localASN + properties: + 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 + localASN: + type: integer + format: int32 + minimum: 64512 + maximum: 65535 + listenPort: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + default: 179 + advertisements: + type: object + properties: + service: + type: object + properties: + ipTypes: + type: array + items: + type: string + enum: + - ClusterIP + - LoadBalancerIP + - ExternalIP + pod: + type: object + properties: {} + egress: + type: object + properties: {} + bgpPeers: + type: array + items: + type: object + required: + - address + - asn + properties: + address: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + port: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + default: 179 + asn: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + multihopTTL: + type: integer + format: int32 + minimum: 1 + maximum: 255 + default: 1 + gracefulRestartTimeSeconds: + type: integer + format: int32 + minimum: 1 + maximum: 3600 + default: 120 + additionalPrinterColumns: + - description: Local BGP AS number + jsonPath: .spec.localASN + name: Local ASN + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + scope: Cluster + names: + plural: bgppolicies + singular: bgppolicy + kind: BGPPolicy + --- # Source: crds/clustergroup.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/build/yamls/antrea-gke.yml b/build/yamls/antrea-gke.yml index 8fb55a482f9..dd628746774 100644 --- a/build/yamls/antrea-gke.yml +++ b/build/yamls/antrea-gke.yml @@ -300,6 +300,135 @@ spec: shortNames: - aci +--- +# Source: crds/bgppolicy.yaml +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: bgppolicies.crd.antrea.io +spec: + group: crd.antrea.io + versions: + - name: v1alpha1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - nodeSelector + - localASN + properties: + 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 + localASN: + type: integer + format: int32 + minimum: 64512 + maximum: 65535 + listenPort: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + default: 179 + advertisements: + type: object + properties: + service: + type: object + properties: + ipTypes: + type: array + items: + type: string + enum: + - ClusterIP + - LoadBalancerIP + - ExternalIP + pod: + type: object + properties: {} + egress: + type: object + properties: {} + bgpPeers: + type: array + items: + type: object + required: + - address + - asn + properties: + address: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + port: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + default: 179 + asn: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + multihopTTL: + type: integer + format: int32 + minimum: 1 + maximum: 255 + default: 1 + gracefulRestartTimeSeconds: + type: integer + format: int32 + minimum: 1 + maximum: 3600 + default: 120 + additionalPrinterColumns: + - description: Local BGP AS number + jsonPath: .spec.localASN + name: Local ASN + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + scope: Cluster + names: + plural: bgppolicies + singular: bgppolicy + kind: BGPPolicy + --- # Source: crds/clustergroup.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/build/yamls/antrea-ipsec.yml b/build/yamls/antrea-ipsec.yml index c843452c63c..6acc2d8ef54 100644 --- a/build/yamls/antrea-ipsec.yml +++ b/build/yamls/antrea-ipsec.yml @@ -300,6 +300,135 @@ spec: shortNames: - aci +--- +# Source: crds/bgppolicy.yaml +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: bgppolicies.crd.antrea.io +spec: + group: crd.antrea.io + versions: + - name: v1alpha1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - nodeSelector + - localASN + properties: + 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 + localASN: + type: integer + format: int32 + minimum: 64512 + maximum: 65535 + listenPort: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + default: 179 + advertisements: + type: object + properties: + service: + type: object + properties: + ipTypes: + type: array + items: + type: string + enum: + - ClusterIP + - LoadBalancerIP + - ExternalIP + pod: + type: object + properties: {} + egress: + type: object + properties: {} + bgpPeers: + type: array + items: + type: object + required: + - address + - asn + properties: + address: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + port: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + default: 179 + asn: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + multihopTTL: + type: integer + format: int32 + minimum: 1 + maximum: 255 + default: 1 + gracefulRestartTimeSeconds: + type: integer + format: int32 + minimum: 1 + maximum: 3600 + default: 120 + additionalPrinterColumns: + - description: Local BGP AS number + jsonPath: .spec.localASN + name: Local ASN + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + scope: Cluster + names: + plural: bgppolicies + singular: bgppolicy + kind: BGPPolicy + --- # Source: crds/clustergroup.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/build/yamls/antrea.yml b/build/yamls/antrea.yml index 60e8df147d4..133f646506b 100644 --- a/build/yamls/antrea.yml +++ b/build/yamls/antrea.yml @@ -300,6 +300,135 @@ spec: shortNames: - aci +--- +# Source: crds/bgppolicy.yaml +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: bgppolicies.crd.antrea.io +spec: + group: crd.antrea.io + versions: + - name: v1alpha1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - nodeSelector + - localASN + properties: + 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 + localASN: + type: integer + format: int32 + minimum: 64512 + maximum: 65535 + listenPort: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + default: 179 + advertisements: + type: object + properties: + service: + type: object + properties: + ipTypes: + type: array + items: + type: string + enum: + - ClusterIP + - LoadBalancerIP + - ExternalIP + pod: + type: object + properties: {} + egress: + type: object + properties: {} + bgpPeers: + type: array + items: + type: object + required: + - address + - asn + properties: + address: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + port: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + default: 179 + asn: + type: integer + format: int32 + minimum: 1 + maximum: 65535 + multihopTTL: + type: integer + format: int32 + minimum: 1 + maximum: 255 + default: 1 + gracefulRestartTimeSeconds: + type: integer + format: int32 + minimum: 1 + maximum: 3600 + default: 120 + additionalPrinterColumns: + - description: Local BGP AS number + jsonPath: .spec.localASN + name: Local ASN + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + scope: Cluster + names: + plural: bgppolicies + singular: bgppolicy + kind: BGPPolicy + --- # Source: crds/clustergroup.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/pkg/apis/crd/v1alpha1/register.go b/pkg/apis/crd/v1alpha1/register.go index 75b6c69cde6..ecefd26a924 100644 --- a/pkg/apis/crd/v1alpha1/register.go +++ b/pkg/apis/crd/v1alpha1/register.go @@ -55,6 +55,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &SupportBundleCollectionList{}, &NodeLatencyMonitor{}, &NodeLatencyMonitorList{}, + &BGPPolicy{}, + &BGPPolicyList{}, ) metav1.AddToGroupVersion( diff --git a/pkg/apis/crd/v1alpha1/types.go b/pkg/apis/crd/v1alpha1/types.go index ac7a7557055..768a9a078fa 100644 --- a/pkg/apis/crd/v1alpha1/types.go +++ b/pkg/apis/crd/v1alpha1/types.go @@ -325,3 +325,105 @@ type NodeLatencyMonitorList struct { Items []NodeLatencyMonitor `json:"items"` } + +// +genclient +// +genclient:nonNamespaced +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// BGPPolicy defines BGP configuration applied to Nodes. +type BGPPolicy struct { + metav1.TypeMeta `json:",inline"` + // Standard metadata of the object. + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec BGPPolicySpec `json:"spec"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type BGPPolicyList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata,omitempty"` + + Items []BGPPolicy `json:"items"` +} + +// BGPPolicySpec defines the specification for a BGPPolicy. +type BGPPolicySpec struct { + // NodeSelector selects Nodes to which the BGPPolicy is applied. If multiple BGPPolicies select a Node, only one + // will be effective and enforced; others serve as alternatives. + NodeSelector metav1.LabelSelector `json:"nodeSelector"` + + // LocalASN is the AS number used by the BGP process. The available private AS number range is 64512-65535. + LocalASN int32 `json:"localASN"` + + // ListenPort is the port on which the BGP process listens, and the default value is 179. + ListenPort *int32 `json:"listenPort,omitempty"` + + // Advertisements configures IPs or CIDRs to be advertised to BGP peers. + Advertisements Advertisements `json:"advertisements,omitempty"` + + // BGPPeers is the list of BGP peers. + BGPPeers []BGPPeer `json:"bgpPeers,omitempty"` +} + +type Advertisements struct { + // Service specifies how to advertise Service IPs. + Service *ServiceAdvertisement `json:"service,omitempty"` + + // Pod specifies how to advertise Pod IPs. Currently, if this is set, NodeIPAM Pod CIDR instead of specific Pods IPs + // will be advertised since pod selector is not added yet. + Pod *PodAdvertisement `json:"pod,omitempty"` + + // Egress specifies how to advertise Egress IPs. Currently, if this is set, all Egress IPs will be advertised since + // Egress selector is not added yet. + Egress *EgressAdvertisement `json:"egress,omitempty"` +} + +type ServiceIPType string + +const ( + ServiceIPTypeClusterIP ServiceIPType = "ClusterIP" + ServiceIPTypeLoadBalancerIP ServiceIPType = "LoadBalancerIP" + ServiceIPTypeExternalIP ServiceIPType = "ExternalIP" +) + +type ServiceAdvertisement struct { + // IPTypes specifies the types of Service IPs from the selected Services to be advertised. Currently, all Services + // will be selected since Service selector is not added yet. + IPTypes []ServiceIPType `json:"ipTypes,omitempty"` + + // Empty now, selectors to be added later, which are used to select specific Services. + // Selectors []Selector `json:"selectors,omitempty"` +} + +type PodAdvertisement struct { + // Empty now, selectors to be added later, which are used to select specific Pods. + // Selectors []Selector `json:"selectors,omitempty"` +} + +type EgressAdvertisement struct { + // Empty now, selectors to be added later, which are used to select specific Egresses. + // Selectors []Selector `json:"selectors,omitempty"` +} + +type BGPPeer struct { + // The IP address on which the BGP peer listens. + Address string `json:"address"` + + // The port number on which the BGP peer listens. The default value is 179, the well-known port of BGP protocol. + Port *int32 `json:"port,omitempty"` + + // The AS number of the BGP peer. + ASN int32 `json:"asn"` + + // The Time To Live (TTL) value used in BGP packets sent to the BGP peer. The range of the value is from 1 to 255, + // and the default value is 1. + MultihopTTL *int32 `json:"multihopTTL,omitempty"` + + // GracefulRestartTimeSeconds specifies how long the BGP peer would wait for the BGP session to re-establish after + // a restart before deleting stale routes. The range of the value is from 1 to 3600, and the default value is 120. + GracefulRestartTimeSeconds *int32 `json:"gracefulRestartTimeSeconds,omitempty"` +} diff --git a/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go index f06755a80a3..a45bdeca9c0 100644 --- a/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go @@ -25,6 +25,158 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Advertisements) DeepCopyInto(out *Advertisements) { + *out = *in + if in.Service != nil { + in, out := &in.Service, &out.Service + *out = new(ServiceAdvertisement) + (*in).DeepCopyInto(*out) + } + if in.Pod != nil { + in, out := &in.Pod, &out.Pod + *out = new(PodAdvertisement) + **out = **in + } + if in.Egress != nil { + in, out := &in.Egress, &out.Egress + *out = new(EgressAdvertisement) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Advertisements. +func (in *Advertisements) DeepCopy() *Advertisements { + if in == nil { + return nil + } + out := new(Advertisements) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BGPPeer) DeepCopyInto(out *BGPPeer) { + *out = *in + if in.Port != nil { + in, out := &in.Port, &out.Port + *out = new(int32) + **out = **in + } + if in.MultihopTTL != nil { + in, out := &in.MultihopTTL, &out.MultihopTTL + *out = new(int32) + **out = **in + } + if in.GracefulRestartTimeSeconds != nil { + in, out := &in.GracefulRestartTimeSeconds, &out.GracefulRestartTimeSeconds + *out = new(int32) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BGPPeer. +func (in *BGPPeer) DeepCopy() *BGPPeer { + if in == nil { + return nil + } + out := new(BGPPeer) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BGPPolicy) DeepCopyInto(out *BGPPolicy) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BGPPolicy. +func (in *BGPPolicy) DeepCopy() *BGPPolicy { + if in == nil { + return nil + } + out := new(BGPPolicy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BGPPolicy) 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 *BGPPolicyList) DeepCopyInto(out *BGPPolicyList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]BGPPolicy, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BGPPolicyList. +func (in *BGPPolicyList) DeepCopy() *BGPPolicyList { + if in == nil { + return nil + } + out := new(BGPPolicyList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BGPPolicyList) 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 *BGPPolicySpec) DeepCopyInto(out *BGPPolicySpec) { + *out = *in + in.NodeSelector.DeepCopyInto(&out.NodeSelector) + if in.ListenPort != nil { + in, out := &in.ListenPort, &out.ListenPort + *out = new(int32) + **out = **in + } + in.Advertisements.DeepCopyInto(&out.Advertisements) + if in.BGPPeers != nil { + in, out := &in.BGPPeers, &out.BGPPeers + *out = make([]BGPPeer, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BGPPolicySpec. +func (in *BGPPolicySpec) DeepCopy() *BGPPolicySpec { + if in == nil { + return nil + } + out := new(BGPPolicySpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BundleExternalNodes) DeepCopyInto(out *BundleExternalNodes) { *out = *in @@ -114,6 +266,22 @@ func (in *BundleServerAuthConfiguration) DeepCopy() *BundleServerAuthConfigurati return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *EgressAdvertisement) DeepCopyInto(out *EgressAdvertisement) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EgressAdvertisement. +func (in *EgressAdvertisement) DeepCopy() *EgressAdvertisement { + if in == nil { + return nil + } + out := new(EgressAdvertisement) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ExternalNode) DeepCopyInto(out *ExternalNode) { *out = *in @@ -368,6 +536,43 @@ func (in *NodeLatencyMonitorSpec) DeepCopy() *NodeLatencyMonitorSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PodAdvertisement) DeepCopyInto(out *PodAdvertisement) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodAdvertisement. +func (in *PodAdvertisement) DeepCopy() *PodAdvertisement { + if in == nil { + return nil + } + out := new(PodAdvertisement) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServiceAdvertisement) DeepCopyInto(out *ServiceAdvertisement) { + *out = *in + if in.IPTypes != nil { + in, out := &in.IPTypes, &out.IPTypes + *out = make([]ServiceIPType, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceAdvertisement. +func (in *ServiceAdvertisement) DeepCopy() *ServiceAdvertisement { + if in == nil { + return nil + } + out := new(ServiceAdvertisement) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SupportBundleCollection) DeepCopyInto(out *SupportBundleCollection) { *out = *in diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha1/bgppolicy.go b/pkg/client/clientset/versioned/typed/crd/v1alpha1/bgppolicy.go new file mode 100644 index 00000000000..911ec0979c5 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha1/bgppolicy.go @@ -0,0 +1,166 @@ +// 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 v1alpha1 + +import ( + "context" + "time" + + v1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + 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" +) + +// BGPPoliciesGetter has a method to return a BGPPolicyInterface. +// A group's client should implement this interface. +type BGPPoliciesGetter interface { + BGPPolicies() BGPPolicyInterface +} + +// BGPPolicyInterface has methods to work with BGPPolicy resources. +type BGPPolicyInterface interface { + Create(ctx context.Context, bGPPolicy *v1alpha1.BGPPolicy, opts v1.CreateOptions) (*v1alpha1.BGPPolicy, error) + Update(ctx context.Context, bGPPolicy *v1alpha1.BGPPolicy, opts v1.UpdateOptions) (*v1alpha1.BGPPolicy, 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) (*v1alpha1.BGPPolicy, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.BGPPolicyList, 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 *v1alpha1.BGPPolicy, err error) + BGPPolicyExpansion +} + +// bGPPolicies implements BGPPolicyInterface +type bGPPolicies struct { + client rest.Interface +} + +// newBGPPolicies returns a BGPPolicies +func newBGPPolicies(c *CrdV1alpha1Client) *bGPPolicies { + return &bGPPolicies{ + client: c.RESTClient(), + } +} + +// Get takes name of the bGPPolicy, and returns the corresponding bGPPolicy object, and an error if there is any. +func (c *bGPPolicies) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.BGPPolicy, err error) { + result = &v1alpha1.BGPPolicy{} + err = c.client.Get(). + Resource("bgppolicies"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of BGPPolicies that match those selectors. +func (c *bGPPolicies) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.BGPPolicyList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.BGPPolicyList{} + err = c.client.Get(). + Resource("bgppolicies"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested bGPPolicies. +func (c *bGPPolicies) 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("bgppolicies"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a bGPPolicy and creates it. Returns the server's representation of the bGPPolicy, and an error, if there is any. +func (c *bGPPolicies) Create(ctx context.Context, bGPPolicy *v1alpha1.BGPPolicy, opts v1.CreateOptions) (result *v1alpha1.BGPPolicy, err error) { + result = &v1alpha1.BGPPolicy{} + err = c.client.Post(). + Resource("bgppolicies"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(bGPPolicy). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a bGPPolicy and updates it. Returns the server's representation of the bGPPolicy, and an error, if there is any. +func (c *bGPPolicies) Update(ctx context.Context, bGPPolicy *v1alpha1.BGPPolicy, opts v1.UpdateOptions) (result *v1alpha1.BGPPolicy, err error) { + result = &v1alpha1.BGPPolicy{} + err = c.client.Put(). + Resource("bgppolicies"). + Name(bGPPolicy.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(bGPPolicy). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the bGPPolicy and deletes it. Returns an error if one occurs. +func (c *bGPPolicies) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Resource("bgppolicies"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *bGPPolicies) 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("bgppolicies"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched bGPPolicy. +func (c *bGPPolicies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.BGPPolicy, err error) { + result = &v1alpha1.BGPPolicy{} + err = c.client.Patch(pt). + Resource("bgppolicies"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha1/crd_client.go b/pkg/client/clientset/versioned/typed/crd/v1alpha1/crd_client.go index 64b9ed11579..bcff19f9bd7 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1alpha1/crd_client.go +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha1/crd_client.go @@ -26,6 +26,7 @@ import ( type CrdV1alpha1Interface interface { RESTClient() rest.Interface + BGPPoliciesGetter ExternalNodesGetter NodeLatencyMonitorsGetter SupportBundleCollectionsGetter @@ -36,6 +37,10 @@ type CrdV1alpha1Client struct { restClient rest.Interface } +func (c *CrdV1alpha1Client) BGPPolicies() BGPPolicyInterface { + return newBGPPolicies(c) +} + func (c *CrdV1alpha1Client) ExternalNodes(namespace string) ExternalNodeInterface { return newExternalNodes(c, namespace) } diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_bgppolicy.go b/pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_bgppolicy.go new file mode 100644 index 00000000000..784b00a6b1e --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_bgppolicy.go @@ -0,0 +1,119 @@ +// 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" + + v1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeBGPPolicies implements BGPPolicyInterface +type FakeBGPPolicies struct { + Fake *FakeCrdV1alpha1 +} + +var bgppoliciesResource = v1alpha1.SchemeGroupVersion.WithResource("bgppolicies") + +var bgppoliciesKind = v1alpha1.SchemeGroupVersion.WithKind("BGPPolicy") + +// Get takes name of the bGPPolicy, and returns the corresponding bGPPolicy object, and an error if there is any. +func (c *FakeBGPPolicies) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.BGPPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(bgppoliciesResource, name), &v1alpha1.BGPPolicy{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.BGPPolicy), err +} + +// List takes label and field selectors, and returns the list of BGPPolicies that match those selectors. +func (c *FakeBGPPolicies) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.BGPPolicyList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(bgppoliciesResource, bgppoliciesKind, opts), &v1alpha1.BGPPolicyList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.BGPPolicyList{ListMeta: obj.(*v1alpha1.BGPPolicyList).ListMeta} + for _, item := range obj.(*v1alpha1.BGPPolicyList).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 bGPPolicies. +func (c *FakeBGPPolicies) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(bgppoliciesResource, opts)) +} + +// Create takes the representation of a bGPPolicy and creates it. Returns the server's representation of the bGPPolicy, and an error, if there is any. +func (c *FakeBGPPolicies) Create(ctx context.Context, bGPPolicy *v1alpha1.BGPPolicy, opts v1.CreateOptions) (result *v1alpha1.BGPPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(bgppoliciesResource, bGPPolicy), &v1alpha1.BGPPolicy{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.BGPPolicy), err +} + +// Update takes the representation of a bGPPolicy and updates it. Returns the server's representation of the bGPPolicy, and an error, if there is any. +func (c *FakeBGPPolicies) Update(ctx context.Context, bGPPolicy *v1alpha1.BGPPolicy, opts v1.UpdateOptions) (result *v1alpha1.BGPPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(bgppoliciesResource, bGPPolicy), &v1alpha1.BGPPolicy{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.BGPPolicy), err +} + +// Delete takes name of the bGPPolicy and deletes it. Returns an error if one occurs. +func (c *FakeBGPPolicies) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteActionWithOptions(bgppoliciesResource, name, opts), &v1alpha1.BGPPolicy{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeBGPPolicies) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(bgppoliciesResource, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.BGPPolicyList{}) + return err +} + +// Patch applies the patch and returns the patched bGPPolicy. +func (c *FakeBGPPolicies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.BGPPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(bgppoliciesResource, name, pt, data, subresources...), &v1alpha1.BGPPolicy{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.BGPPolicy), err +} diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_crd_client.go b/pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_crd_client.go index 036a1f768af..4d6c869b949 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_crd_client.go +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha1/fake/fake_crd_client.go @@ -26,6 +26,10 @@ type FakeCrdV1alpha1 struct { *testing.Fake } +func (c *FakeCrdV1alpha1) BGPPolicies() v1alpha1.BGPPolicyInterface { + return &FakeBGPPolicies{c} +} + func (c *FakeCrdV1alpha1) ExternalNodes(namespace string) v1alpha1.ExternalNodeInterface { return &FakeExternalNodes{c, namespace} } diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/crd/v1alpha1/generated_expansion.go index 34fa36922dd..0631615e701 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1alpha1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha1/generated_expansion.go @@ -16,6 +16,8 @@ package v1alpha1 +type BGPPolicyExpansion interface{} + type ExternalNodeExpansion interface{} type NodeLatencyMonitorExpansion interface{} diff --git a/pkg/client/informers/externalversions/crd/v1alpha1/bgppolicy.go b/pkg/client/informers/externalversions/crd/v1alpha1/bgppolicy.go new file mode 100644 index 00000000000..35c982e0626 --- /dev/null +++ b/pkg/client/informers/externalversions/crd/v1alpha1/bgppolicy.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 v1alpha1 + +import ( + "context" + time "time" + + crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + versioned "antrea.io/antrea/pkg/client/clientset/versioned" + internalinterfaces "antrea.io/antrea/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "antrea.io/antrea/pkg/client/listers/crd/v1alpha1" + 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" +) + +// BGPPolicyInformer provides access to a shared informer and lister for +// BGPPolicies. +type BGPPolicyInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.BGPPolicyLister +} + +type bGPPolicyInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewBGPPolicyInformer constructs a new informer for BGPPolicy 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 NewBGPPolicyInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredBGPPolicyInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredBGPPolicyInformer constructs a new informer for BGPPolicy 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 NewFilteredBGPPolicyInformer(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.CrdV1alpha1().BGPPolicies().List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CrdV1alpha1().BGPPolicies().Watch(context.TODO(), options) + }, + }, + &crdv1alpha1.BGPPolicy{}, + resyncPeriod, + indexers, + ) +} + +func (f *bGPPolicyInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredBGPPolicyInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *bGPPolicyInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&crdv1alpha1.BGPPolicy{}, f.defaultInformer) +} + +func (f *bGPPolicyInformer) Lister() v1alpha1.BGPPolicyLister { + return v1alpha1.NewBGPPolicyLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/crd/v1alpha1/interface.go b/pkg/client/informers/externalversions/crd/v1alpha1/interface.go index c83d379324d..e69100682ba 100644 --- a/pkg/client/informers/externalversions/crd/v1alpha1/interface.go +++ b/pkg/client/informers/externalversions/crd/v1alpha1/interface.go @@ -22,6 +22,8 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { + // BGPPolicies returns a BGPPolicyInformer. + BGPPolicies() BGPPolicyInformer // ExternalNodes returns a ExternalNodeInformer. ExternalNodes() ExternalNodeInformer // NodeLatencyMonitors returns a NodeLatencyMonitorInformer. @@ -41,6 +43,11 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } +// BGPPolicies returns a BGPPolicyInformer. +func (v *version) BGPPolicies() BGPPolicyInformer { + return &bGPPolicyInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + // ExternalNodes returns a ExternalNodeInformer. func (v *version) ExternalNodes() ExternalNodeInformer { return &externalNodeInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index e692c359dd2..07c1d724cbc 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -53,6 +53,8 @@ func (f *genericInformer) Lister() cache.GenericLister { func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { // Group=crd.antrea.io, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("bgppolicies"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1alpha1().BGPPolicies().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("externalnodes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1alpha1().ExternalNodes().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("nodelatencymonitors"): diff --git a/pkg/client/listers/crd/v1alpha1/bgppolicy.go b/pkg/client/listers/crd/v1alpha1/bgppolicy.go new file mode 100644 index 00000000000..8ffe2d1f115 --- /dev/null +++ b/pkg/client/listers/crd/v1alpha1/bgppolicy.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 v1alpha1 + +import ( + v1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// BGPPolicyLister helps list BGPPolicies. +// All objects returned here must be treated as read-only. +type BGPPolicyLister interface { + // List lists all BGPPolicies in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.BGPPolicy, err error) + // Get retrieves the BGPPolicy from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha1.BGPPolicy, error) + BGPPolicyListerExpansion +} + +// bGPPolicyLister implements the BGPPolicyLister interface. +type bGPPolicyLister struct { + indexer cache.Indexer +} + +// NewBGPPolicyLister returns a new BGPPolicyLister. +func NewBGPPolicyLister(indexer cache.Indexer) BGPPolicyLister { + return &bGPPolicyLister{indexer: indexer} +} + +// List lists all BGPPolicies in the indexer. +func (s *bGPPolicyLister) List(selector labels.Selector) (ret []*v1alpha1.BGPPolicy, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.BGPPolicy)) + }) + return ret, err +} + +// Get retrieves the BGPPolicy from the index for a given name. +func (s *bGPPolicyLister) Get(name string) (*v1alpha1.BGPPolicy, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("bgppolicy"), name) + } + return obj.(*v1alpha1.BGPPolicy), nil +} diff --git a/pkg/client/listers/crd/v1alpha1/expansion_generated.go b/pkg/client/listers/crd/v1alpha1/expansion_generated.go index e3a50a984f1..6d1c92155c1 100644 --- a/pkg/client/listers/crd/v1alpha1/expansion_generated.go +++ b/pkg/client/listers/crd/v1alpha1/expansion_generated.go @@ -16,6 +16,10 @@ package v1alpha1 +// BGPPolicyListerExpansion allows custom methods to be added to +// BGPPolicyLister. +type BGPPolicyListerExpansion interface{} + // ExternalNodeListerExpansion allows custom methods to be added to // ExternalNodeLister. type ExternalNodeListerExpansion interface{}