From 30290bcdf6ad1a37f90687124179cd603a88c6bf 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 | 133 ++++++++++++ build/yamls/antrea-aks.yml | 136 ++++++++++++ build/yamls/antrea-crds.yml | 134 ++++++++++++ build/yamls/antrea-eks.yml | 136 ++++++++++++ build/yamls/antrea-gke.yml | 136 ++++++++++++ build/yamls/antrea-ipsec.yml | 136 ++++++++++++ build/yamls/antrea.yml | 136 ++++++++++++ pkg/apis/crd/v1alpha1/register.go | 2 + pkg/apis/crd/v1alpha1/types.go | 92 ++++++++ .../crd/v1alpha1/zz_generated.deepcopy.go | 201 +++++++++++++++++- .../versioned/typed/crd/v1alpha1/bgppolicy.go | 166 +++++++++++++++ .../typed/crd/v1alpha1/crd_client.go | 7 +- .../typed/crd/v1alpha1/fake/fake_bgppolicy.go | 119 +++++++++++ .../crd/v1alpha1/fake/fake_crd_client.go | 6 +- .../typed/crd/v1alpha1/generated_expansion.go | 4 +- .../crd/v1alpha1/bgppolicy.go | 87 ++++++++ .../crd/v1alpha1/interface.go | 9 +- .../informers/externalversions/generic.go | 2 + pkg/client/listers/crd/v1alpha1/bgppolicy.go | 66 ++++++ .../crd/v1alpha1/expansion_generated.go | 6 +- 20 files changed, 1708 insertions(+), 6 deletions(-) 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..14d7e3ac21f --- /dev/null +++ b/build/charts/antrea/crds/bgppolicy.yaml @@ -0,0 +1,133 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: bgppolicies.crd.antrea.io +spec: + group: crd.antrea.io + versions: + - name: v1alpha2 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - nodeSelector + - localASN + - advertisements + - bgpPeers + 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 + minimum: 64512 + maximum: 65535 + format: int32 + listenPort: + type: integer + minimum: 1 + maximum: 65535 + format: int32 + default: 179 + advertisements: + type: object + anyOf: + - required: [service] + - required: [pod] + - required: [egress] + properties: + service: + type: object + anyOf: + - required: [ clusterIPs ] + - required: [ externalIPs ] + - required: [ loadBalancerIPs ] + properties: + clusterIPs: + type: boolean + default: false + externalIPs: + type: boolean + default: false + loadBalancerIPs: + type: boolean + default: false + pod: + type: object + properties: {} + egress: + type: object + properties: {} + bgpPeers: + type: array + items: + type: object + required: + - address + - asn + properties: + address: + type: string + format: cidr + port: + type: integer + default: 179 + format: int32 + minimum: 1 + maximum: 65535 + asn: + type: integer + minimum: 1 + maximum: 65535 + format: int32 + gracefulRestartTime: + type: integer + default: 120 + format: int32 + minimum: 1 + maximum: 3600 + additionalPrinterColumns: + - description: Local BGP ASN. + jsonPath: .spec.localASN + name: Local ASN + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + subresources: + status: {} + scope: Cluster + names: + plural: bgppolicies + singular: bgppolicy + kind: BGPPolicy + shortNames: + - bp diff --git a/build/yamls/antrea-aks.yml b/build/yamls/antrea-aks.yml index f4bc9bb2162..4428cbb3485 100644 --- a/build/yamls/antrea-aks.yml +++ b/build/yamls/antrea-aks.yml @@ -300,6 +300,142 @@ 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: v1alpha2 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - nodeSelector + - localASN + - advertisements + - bgpPeers + 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 + minimum: 64512 + maximum: 65535 + format: int32 + listenPort: + type: integer + minimum: 1 + maximum: 65535 + format: int32 + default: 179 + advertisements: + type: object + anyOf: + - required: [service] + - required: [pod] + - required: [egress] + properties: + service: + type: object + anyOf: + - required: [ clusterIPs ] + - required: [ externalIPs ] + - required: [ loadBalancerIPs ] + properties: + clusterIPs: + type: boolean + default: false + externalIPs: + type: boolean + default: false + loadBalancerIPs: + type: boolean + default: false + pod: + type: object + properties: {} + egress: + type: object + properties: {} + bgpPeers: + type: array + items: + type: object + required: + - address + - asn + properties: + address: + type: string + format: cidr + port: + type: integer + default: 179 + format: int32 + minimum: 1 + maximum: 65535 + asn: + type: integer + minimum: 1 + maximum: 65535 + format: int32 + gracefulRestartTime: + type: integer + default: 120 + format: int32 + minimum: 1 + maximum: 3600 + additionalPrinterColumns: + - description: Local BGP ASN. + jsonPath: .spec.localASN + name: Local ASN + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + subresources: + status: {} + scope: Cluster + names: + plural: bgppolicies + singular: bgppolicy + kind: BGPPolicy + shortNames: + - bp + --- # Source: crds/clustergroup.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/build/yamls/antrea-crds.yml b/build/yamls/antrea-crds.yml index e0497dcf8b2..a11ab119924 100644 --- a/build/yamls/antrea-crds.yml +++ b/build/yamls/antrea-crds.yml @@ -299,6 +299,140 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + name: bgppolicies.crd.antrea.io +spec: + group: crd.antrea.io + versions: + - name: v1alpha2 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - nodeSelector + - localASN + - advertisements + - bgpPeers + 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 + minimum: 64512 + maximum: 65535 + format: int32 + listenPort: + type: integer + minimum: 1 + maximum: 65535 + format: int32 + default: 179 + advertisements: + type: object + anyOf: + - required: [service] + - required: [pod] + - required: [egress] + properties: + service: + type: object + anyOf: + - required: [ clusterIPs ] + - required: [ externalIPs ] + - required: [ loadBalancerIPs ] + properties: + clusterIPs: + type: boolean + default: false + externalIPs: + type: boolean + default: false + loadBalancerIPs: + type: boolean + default: false + pod: + type: object + properties: {} + egress: + type: object + properties: {} + bgpPeers: + type: array + items: + type: object + required: + - address + - asn + properties: + address: + type: string + format: cidr + port: + type: integer + default: 179 + format: int32 + minimum: 1 + maximum: 65535 + asn: + type: integer + minimum: 1 + maximum: 65535 + format: int32 + gracefulRestartTime: + type: integer + default: 120 + format: int32 + minimum: 1 + maximum: 3600 + additionalPrinterColumns: + - description: Local BGP ASN. + jsonPath: .spec.localASN + name: Local ASN + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + subresources: + status: {} + scope: Cluster + names: + plural: bgppolicies + singular: bgppolicy + kind: BGPPolicy + shortNames: + - bp +--- +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 bec701d3056..81ed928894d 100644 --- a/build/yamls/antrea-eks.yml +++ b/build/yamls/antrea-eks.yml @@ -300,6 +300,142 @@ 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: v1alpha2 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - nodeSelector + - localASN + - advertisements + - bgpPeers + 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 + minimum: 64512 + maximum: 65535 + format: int32 + listenPort: + type: integer + minimum: 1 + maximum: 65535 + format: int32 + default: 179 + advertisements: + type: object + anyOf: + - required: [service] + - required: [pod] + - required: [egress] + properties: + service: + type: object + anyOf: + - required: [ clusterIPs ] + - required: [ externalIPs ] + - required: [ loadBalancerIPs ] + properties: + clusterIPs: + type: boolean + default: false + externalIPs: + type: boolean + default: false + loadBalancerIPs: + type: boolean + default: false + pod: + type: object + properties: {} + egress: + type: object + properties: {} + bgpPeers: + type: array + items: + type: object + required: + - address + - asn + properties: + address: + type: string + format: cidr + port: + type: integer + default: 179 + format: int32 + minimum: 1 + maximum: 65535 + asn: + type: integer + minimum: 1 + maximum: 65535 + format: int32 + gracefulRestartTime: + type: integer + default: 120 + format: int32 + minimum: 1 + maximum: 3600 + additionalPrinterColumns: + - description: Local BGP ASN. + jsonPath: .spec.localASN + name: Local ASN + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + subresources: + status: {} + scope: Cluster + names: + plural: bgppolicies + singular: bgppolicy + kind: BGPPolicy + shortNames: + - bp + --- # Source: crds/clustergroup.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/build/yamls/antrea-gke.yml b/build/yamls/antrea-gke.yml index a4ae810f7b0..f23f0b14685 100644 --- a/build/yamls/antrea-gke.yml +++ b/build/yamls/antrea-gke.yml @@ -300,6 +300,142 @@ 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: v1alpha2 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - nodeSelector + - localASN + - advertisements + - bgpPeers + 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 + minimum: 64512 + maximum: 65535 + format: int32 + listenPort: + type: integer + minimum: 1 + maximum: 65535 + format: int32 + default: 179 + advertisements: + type: object + anyOf: + - required: [service] + - required: [pod] + - required: [egress] + properties: + service: + type: object + anyOf: + - required: [ clusterIPs ] + - required: [ externalIPs ] + - required: [ loadBalancerIPs ] + properties: + clusterIPs: + type: boolean + default: false + externalIPs: + type: boolean + default: false + loadBalancerIPs: + type: boolean + default: false + pod: + type: object + properties: {} + egress: + type: object + properties: {} + bgpPeers: + type: array + items: + type: object + required: + - address + - asn + properties: + address: + type: string + format: cidr + port: + type: integer + default: 179 + format: int32 + minimum: 1 + maximum: 65535 + asn: + type: integer + minimum: 1 + maximum: 65535 + format: int32 + gracefulRestartTime: + type: integer + default: 120 + format: int32 + minimum: 1 + maximum: 3600 + additionalPrinterColumns: + - description: Local BGP ASN. + jsonPath: .spec.localASN + name: Local ASN + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + subresources: + status: {} + scope: Cluster + names: + plural: bgppolicies + singular: bgppolicy + kind: BGPPolicy + shortNames: + - bp + --- # Source: crds/clustergroup.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/build/yamls/antrea-ipsec.yml b/build/yamls/antrea-ipsec.yml index 393cb59da0a..ffcf39f5861 100644 --- a/build/yamls/antrea-ipsec.yml +++ b/build/yamls/antrea-ipsec.yml @@ -300,6 +300,142 @@ 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: v1alpha2 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - nodeSelector + - localASN + - advertisements + - bgpPeers + 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 + minimum: 64512 + maximum: 65535 + format: int32 + listenPort: + type: integer + minimum: 1 + maximum: 65535 + format: int32 + default: 179 + advertisements: + type: object + anyOf: + - required: [service] + - required: [pod] + - required: [egress] + properties: + service: + type: object + anyOf: + - required: [ clusterIPs ] + - required: [ externalIPs ] + - required: [ loadBalancerIPs ] + properties: + clusterIPs: + type: boolean + default: false + externalIPs: + type: boolean + default: false + loadBalancerIPs: + type: boolean + default: false + pod: + type: object + properties: {} + egress: + type: object + properties: {} + bgpPeers: + type: array + items: + type: object + required: + - address + - asn + properties: + address: + type: string + format: cidr + port: + type: integer + default: 179 + format: int32 + minimum: 1 + maximum: 65535 + asn: + type: integer + minimum: 1 + maximum: 65535 + format: int32 + gracefulRestartTime: + type: integer + default: 120 + format: int32 + minimum: 1 + maximum: 3600 + additionalPrinterColumns: + - description: Local BGP ASN. + jsonPath: .spec.localASN + name: Local ASN + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + subresources: + status: {} + scope: Cluster + names: + plural: bgppolicies + singular: bgppolicy + kind: BGPPolicy + shortNames: + - bp + --- # Source: crds/clustergroup.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/build/yamls/antrea.yml b/build/yamls/antrea.yml index 2451670ca39..55a4d726fc9 100644 --- a/build/yamls/antrea.yml +++ b/build/yamls/antrea.yml @@ -300,6 +300,142 @@ 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: v1alpha2 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + required: + - spec + properties: + spec: + type: object + required: + - nodeSelector + - localASN + - advertisements + - bgpPeers + 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 + minimum: 64512 + maximum: 65535 + format: int32 + listenPort: + type: integer + minimum: 1 + maximum: 65535 + format: int32 + default: 179 + advertisements: + type: object + anyOf: + - required: [service] + - required: [pod] + - required: [egress] + properties: + service: + type: object + anyOf: + - required: [ clusterIPs ] + - required: [ externalIPs ] + - required: [ loadBalancerIPs ] + properties: + clusterIPs: + type: boolean + default: false + externalIPs: + type: boolean + default: false + loadBalancerIPs: + type: boolean + default: false + pod: + type: object + properties: {} + egress: + type: object + properties: {} + bgpPeers: + type: array + items: + type: object + required: + - address + - asn + properties: + address: + type: string + format: cidr + port: + type: integer + default: 179 + format: int32 + minimum: 1 + maximum: 65535 + asn: + type: integer + minimum: 1 + maximum: 65535 + format: int32 + gracefulRestartTime: + type: integer + default: 120 + format: int32 + minimum: 1 + maximum: 3600 + additionalPrinterColumns: + - description: Local BGP ASN. + jsonPath: .spec.localASN + name: Local ASN + type: integer + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + subresources: + status: {} + scope: Cluster + names: + plural: bgppolicies + singular: bgppolicy + kind: BGPPolicy + shortNames: + - bp + --- # 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 a9492ab5ac0..2e59b487c8c 100644 --- a/pkg/apis/crd/v1alpha1/register.go +++ b/pkg/apis/crd/v1alpha1/register.go @@ -61,6 +61,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &ExternalNodeList{}, &SupportBundleCollection{}, &SupportBundleCollectionList{}, + &BGPPolicy{}, + &BGPPolicyList{}, ) metav1.AddToGroupVersion( diff --git a/pkg/apis/crd/v1alpha1/types.go b/pkg/apis/crd/v1alpha1/types.go index 8682ddeb09b..25255398966 100644 --- a/pkg/apis/crd/v1alpha1/types.go +++ b/pkg/apis/crd/v1alpha1/types.go @@ -935,3 +935,95 @@ type TLSProtocol struct { // SNI (Server Name Indication) indicates the server domain name in the TLS/SSL hello message. SNI string `json:"sni,omitempty"` } + +// +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 BGP policy. +type BGPPolicySpec struct { + // NodeSelector is utilized to select Nodes to which the policy is applied. It's important to note that only one + // BGPPolicy will be effective and enforced per Node, and others serve as alternatives. + NodeSelector *metav1.LabelSelector `json:"nodeSelector"` + + // LocalASN is the AS number used by the BGP protocol. + LocalASN int32 `json:"localASN"` + + // ListenPort is the port on which the BGP protocol listens. + ListenPort *int32 `json:"listenPort,omitempty"` + + // Advertisements selects IPs or CIDRs to be advertised to external BGP peers. + Advertisements Advertisements `json:"advertisements"` + + // BGPPeers are the list of external BGP peers. + BGPPeers []BGPPeer `json:"bgpPeers"` +} + +type Advertisements struct { + Service *ServiceAdvertisement `json:"service,omitempty"` + + Pod *PodAdvertisement `json:"pod,omitempty"` + + Egress *EgressAdvertisement `json:"egress,omitempty"` +} + +type ServiceAdvertisement struct { + // Determine whether to advertise ClusterIPs. + ClusterIPs bool `json:"clusterIPs,omitempty"` + + // Determine whether to advertise ExternalIPs. + ExternalIPs bool `json:"externalIPs,omitempty"` + + // Determine whether to advertise LoadBalancerIPs. + LoadBalancerIPs bool `json:"loadBalancerIPs,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 external BGP peer listens. + Address string `json:"address"` + + // The port number on which the external 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 external BGP peer. + ASN int32 `json:"asn"` + + // GracefulRestartTime specifies how long the external 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 seconds, and the default value + // is 120 seconds. + GracefulRestartTime *int32 `json:"gracefulRestartTime,omitempty"` +} diff --git a/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go index f80a99a2c64..f170ec137ce 100644 --- a/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Copyright 2023 Antrea Authors +// Copyright 2024 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -26,6 +26,37 @@ import ( intstr "k8s.io/apimachinery/pkg/util/intstr" ) +// 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) + **out = **in + } + 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 *AppliedTo) DeepCopyInto(out *AppliedTo) { *out = *in @@ -67,6 +98,126 @@ func (in *AppliedTo) DeepCopy() *AppliedTo { 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.GracefulRestartTime != nil { + in, out := &in.GracefulRestartTime, &out.GracefulRestartTime + *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 + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = new(v1.LabelSelector) + (*in).DeepCopyInto(*out) + } + 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 @@ -270,6 +421,22 @@ func (in *Destination) DeepCopy() *Destination { 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 @@ -896,6 +1063,22 @@ func (in *PeerService) DeepCopy() *PeerService { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *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 *Rule) DeepCopyInto(out *Rule) { *out = *in @@ -964,6 +1147,22 @@ func (in *Rule) DeepCopy() *Rule { 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 + 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 *Source) DeepCopyInto(out *Source) { *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 140c2de5f47..45a8da96ae6 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1alpha1/crd_client.go +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha1/crd_client.go @@ -1,4 +1,4 @@ -// Copyright 2022 Antrea Authors +// Copyright 2024 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import ( type CrdV1alpha1Interface interface { RESTClient() rest.Interface + BGPPoliciesGetter ClusterNetworkPoliciesGetter ExternalNodesGetter NetworkPoliciesGetter @@ -39,6 +40,10 @@ type CrdV1alpha1Client struct { restClient rest.Interface } +func (c *CrdV1alpha1Client) BGPPolicies() BGPPolicyInterface { + return newBGPPolicies(c) +} + func (c *CrdV1alpha1Client) ClusterNetworkPolicies() ClusterNetworkPolicyInterface { return newClusterNetworkPolicies(c) } 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 a90f91178bc..6e5e78134f5 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 @@ -1,4 +1,4 @@ -// Copyright 2022 Antrea Authors +// Copyright 2024 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -26,6 +26,10 @@ type FakeCrdV1alpha1 struct { *testing.Fake } +func (c *FakeCrdV1alpha1) BGPPolicies() v1alpha1.BGPPolicyInterface { + return &FakeBGPPolicies{c} +} + func (c *FakeCrdV1alpha1) ClusterNetworkPolicies() v1alpha1.ClusterNetworkPolicyInterface { return &FakeClusterNetworkPolicies{c} } 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 d4d390824f7..9b0c2b72fdd 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1alpha1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha1/generated_expansion.go @@ -1,4 +1,4 @@ -// Copyright 2022 Antrea Authors +// Copyright 2024 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ package v1alpha1 +type BGPPolicyExpansion interface{} + type ClusterNetworkPolicyExpansion interface{} type ExternalNodeExpansion 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 5f34c67e3e2..aca4149e658 100644 --- a/pkg/client/informers/externalversions/crd/v1alpha1/interface.go +++ b/pkg/client/informers/externalversions/crd/v1alpha1/interface.go @@ -1,4 +1,4 @@ -// Copyright 2022 Antrea Authors +// Copyright 2024 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -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 // ClusterNetworkPolicies returns a ClusterNetworkPolicyInformer. ClusterNetworkPolicies() ClusterNetworkPolicyInformer // ExternalNodes returns a ExternalNodeInformer. @@ -47,6 +49,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} +} + // ClusterNetworkPolicies returns a ClusterNetworkPolicyInformer. func (v *version) ClusterNetworkPolicies() ClusterNetworkPolicyInformer { return &clusterNetworkPolicyInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index e3f7e903ce7..c86867849f3 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -54,6 +54,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("clusternetworkpolicies"): return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1alpha1().ClusterNetworkPolicies().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("externalnodes"): 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 99f199fd8a1..5e455530e50 100644 --- a/pkg/client/listers/crd/v1alpha1/expansion_generated.go +++ b/pkg/client/listers/crd/v1alpha1/expansion_generated.go @@ -1,4 +1,4 @@ -// Copyright 2022 Antrea Authors +// Copyright 2024 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,6 +16,10 @@ package v1alpha1 +// BGPPolicyListerExpansion allows custom methods to be added to +// BGPPolicyLister. +type BGPPolicyListerExpansion interface{} + // ClusterNetworkPolicyListerExpansion allows custom methods to be added to // ClusterNetworkPolicyLister. type ClusterNetworkPolicyListerExpansion interface{}