diff --git a/build/yamls/antrea-aks.yml b/build/yamls/antrea-aks.yml index 3981c98fbb6..b48eff4f796 100644 --- a/build/yamls/antrea-aks.yml +++ b/build/yamls/antrea-aks.yml @@ -1350,6 +1350,11 @@ spec: openAPIV3Schema: properties: spec: + anyOf: + - required: + - egressIP + - required: + - externalIPPool properties: appliedTo: properties: @@ -1405,9 +1410,10 @@ spec: - format: ipv4 - format: ipv6 type: string + externalIPPool: + type: string required: - appliedTo - - egressIP type: object required: - spec @@ -1533,6 +1539,85 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + labels: + app: antrea + name: externalippools.crd.antrea.io +spec: + group: crd.antrea.io + names: + kind: ExternalIPPool + plural: externalippools + shortNames: + - eip + singular: externalippool + scope: Cluster + versions: + - name: v1alpha2 + schema: + openAPIV3Schema: + properties: + spec: + properties: + ipRanges: + items: + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + format: cidr + type: string + end: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + start: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + type: object + type: array + nodeSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + enum: + - In + - NotIn + - Exists + - DoesNotExist + type: string + values: + items: + type: string + type: array + type: object + type: array + matchLabels: + x-kubernetes-preserve-unknown-fields: true + type: object + required: + - ipRanges + - nodeSelector + type: object + required: + - spec + type: object + served: true + storage: true +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: labels: app: antrea @@ -3404,6 +3489,15 @@ rules: - get - watch - list + - update +- apiGroups: + - crd.antrea.io + resources: + - externalippools + verbs: + - get + - watch + - list - apiGroups: - clusterinformation.antrea.tanzu.vmware.com resources: diff --git a/build/yamls/antrea-eks.yml b/build/yamls/antrea-eks.yml index a26884c800e..8164ce1dba7 100644 --- a/build/yamls/antrea-eks.yml +++ b/build/yamls/antrea-eks.yml @@ -1350,6 +1350,11 @@ spec: openAPIV3Schema: properties: spec: + anyOf: + - required: + - egressIP + - required: + - externalIPPool properties: appliedTo: properties: @@ -1405,9 +1410,10 @@ spec: - format: ipv4 - format: ipv6 type: string + externalIPPool: + type: string required: - appliedTo - - egressIP type: object required: - spec @@ -1533,6 +1539,85 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + labels: + app: antrea + name: externalippools.crd.antrea.io +spec: + group: crd.antrea.io + names: + kind: ExternalIPPool + plural: externalippools + shortNames: + - eip + singular: externalippool + scope: Cluster + versions: + - name: v1alpha2 + schema: + openAPIV3Schema: + properties: + spec: + properties: + ipRanges: + items: + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + format: cidr + type: string + end: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + start: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + type: object + type: array + nodeSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + enum: + - In + - NotIn + - Exists + - DoesNotExist + type: string + values: + items: + type: string + type: array + type: object + type: array + matchLabels: + x-kubernetes-preserve-unknown-fields: true + type: object + required: + - ipRanges + - nodeSelector + type: object + required: + - spec + type: object + served: true + storage: true +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: labels: app: antrea @@ -3404,6 +3489,15 @@ rules: - get - watch - list + - update +- apiGroups: + - crd.antrea.io + resources: + - externalippools + verbs: + - get + - watch + - list - apiGroups: - clusterinformation.antrea.tanzu.vmware.com resources: diff --git a/build/yamls/antrea-gke.yml b/build/yamls/antrea-gke.yml index 0f813ff93a0..a9b9199a5e7 100644 --- a/build/yamls/antrea-gke.yml +++ b/build/yamls/antrea-gke.yml @@ -1350,6 +1350,11 @@ spec: openAPIV3Schema: properties: spec: + anyOf: + - required: + - egressIP + - required: + - externalIPPool properties: appliedTo: properties: @@ -1405,9 +1410,10 @@ spec: - format: ipv4 - format: ipv6 type: string + externalIPPool: + type: string required: - appliedTo - - egressIP type: object required: - spec @@ -1533,6 +1539,85 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + labels: + app: antrea + name: externalippools.crd.antrea.io +spec: + group: crd.antrea.io + names: + kind: ExternalIPPool + plural: externalippools + shortNames: + - eip + singular: externalippool + scope: Cluster + versions: + - name: v1alpha2 + schema: + openAPIV3Schema: + properties: + spec: + properties: + ipRanges: + items: + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + format: cidr + type: string + end: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + start: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + type: object + type: array + nodeSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + enum: + - In + - NotIn + - Exists + - DoesNotExist + type: string + values: + items: + type: string + type: array + type: object + type: array + matchLabels: + x-kubernetes-preserve-unknown-fields: true + type: object + required: + - ipRanges + - nodeSelector + type: object + required: + - spec + type: object + served: true + storage: true +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: labels: app: antrea @@ -3404,6 +3489,15 @@ rules: - get - watch - list + - update +- apiGroups: + - crd.antrea.io + resources: + - externalippools + verbs: + - get + - watch + - list - apiGroups: - clusterinformation.antrea.tanzu.vmware.com resources: diff --git a/build/yamls/antrea-ipsec.yml b/build/yamls/antrea-ipsec.yml index 2b2a92f77ab..bcdc93cc523 100644 --- a/build/yamls/antrea-ipsec.yml +++ b/build/yamls/antrea-ipsec.yml @@ -1350,6 +1350,11 @@ spec: openAPIV3Schema: properties: spec: + anyOf: + - required: + - egressIP + - required: + - externalIPPool properties: appliedTo: properties: @@ -1405,9 +1410,10 @@ spec: - format: ipv4 - format: ipv6 type: string + externalIPPool: + type: string required: - appliedTo - - egressIP type: object required: - spec @@ -1533,6 +1539,85 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + labels: + app: antrea + name: externalippools.crd.antrea.io +spec: + group: crd.antrea.io + names: + kind: ExternalIPPool + plural: externalippools + shortNames: + - eip + singular: externalippool + scope: Cluster + versions: + - name: v1alpha2 + schema: + openAPIV3Schema: + properties: + spec: + properties: + ipRanges: + items: + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + format: cidr + type: string + end: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + start: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + type: object + type: array + nodeSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + enum: + - In + - NotIn + - Exists + - DoesNotExist + type: string + values: + items: + type: string + type: array + type: object + type: array + matchLabels: + x-kubernetes-preserve-unknown-fields: true + type: object + required: + - ipRanges + - nodeSelector + type: object + required: + - spec + type: object + served: true + storage: true +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: labels: app: antrea @@ -3404,6 +3489,15 @@ rules: - get - watch - list + - update +- apiGroups: + - crd.antrea.io + resources: + - externalippools + verbs: + - get + - watch + - list - apiGroups: - clusterinformation.antrea.tanzu.vmware.com resources: diff --git a/build/yamls/antrea.yml b/build/yamls/antrea.yml index 8a9dac6a0ee..a68a5afa2a4 100644 --- a/build/yamls/antrea.yml +++ b/build/yamls/antrea.yml @@ -1350,6 +1350,11 @@ spec: openAPIV3Schema: properties: spec: + anyOf: + - required: + - egressIP + - required: + - externalIPPool properties: appliedTo: properties: @@ -1405,9 +1410,10 @@ spec: - format: ipv4 - format: ipv6 type: string + externalIPPool: + type: string required: - appliedTo - - egressIP type: object required: - spec @@ -1533,6 +1539,85 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + labels: + app: antrea + name: externalippools.crd.antrea.io +spec: + group: crd.antrea.io + names: + kind: ExternalIPPool + plural: externalippools + shortNames: + - eip + singular: externalippool + scope: Cluster + versions: + - name: v1alpha2 + schema: + openAPIV3Schema: + properties: + spec: + properties: + ipRanges: + items: + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + format: cidr + type: string + end: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + start: + oneOf: + - format: ipv4 + - format: ipv6 + type: string + type: object + type: array + nodeSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + enum: + - In + - NotIn + - Exists + - DoesNotExist + type: string + values: + items: + type: string + type: array + type: object + type: array + matchLabels: + x-kubernetes-preserve-unknown-fields: true + type: object + required: + - ipRanges + - nodeSelector + type: object + required: + - spec + type: object + served: true + storage: true +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: labels: app: antrea @@ -3404,6 +3489,15 @@ rules: - get - watch - list + - update +- apiGroups: + - crd.antrea.io + resources: + - externalippools + verbs: + - get + - watch + - list - apiGroups: - clusterinformation.antrea.tanzu.vmware.com resources: diff --git a/build/yamls/base/controller-rbac.yml b/build/yamls/base/controller-rbac.yml index efdd54f8e04..7dffa9a60fd 100644 --- a/build/yamls/base/controller-rbac.yml +++ b/build/yamls/base/controller-rbac.yml @@ -198,6 +198,15 @@ rules: - get - watch - list + - update + - apiGroups: + - crd.antrea.io + resources: + - externalippools + verbs: + - get + - watch + - list # Deprecated in v1.0.0. - apiGroups: - clusterinformation.antrea.tanzu.vmware.com diff --git a/build/yamls/base/crds.yml b/build/yamls/base/crds.yml index fa9eca30fb3..38a1867b21c 100644 --- a/build/yamls/base/crds.yml +++ b/build/yamls/base/crds.yml @@ -19,7 +19,11 @@ spec: type: object required: - appliedTo - - egressIP + anyOf: + - required: + - egressIP + - required: + - externalIPPool properties: appliedTo: type: object @@ -75,6 +79,8 @@ spec: oneOf: - format: ipv4 - format: ipv6 + externalIPPool: + type: string additionalPrinterColumns: - description: Specifies the SNAT IP address for the selected workloads. jsonPath: .spec.egressIP @@ -93,6 +99,83 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + name: externalippools.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: + - ipRanges + - nodeSelector + properties: + ipRanges: + type: array + items: + type: object + oneOf: + - required: + - cidr + - required: + - start + - end + properties: + cidr: + type: string + format: cidr + start: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + end: + type: string + oneOf: + - format: ipv4 + - format: ipv6 + nodeSelector: + type: object + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + enum: + - In + - NotIn + - Exists + - DoesNotExist + type: string + values: + items: + type: string + type: array + type: object + type: array + matchLabels: + x-kubernetes-preserve-unknown-fields: true + scope: Cluster + names: + plural: externalippools + singular: externalippool + kind: ExternalIPPool + shortNames: + - eip +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: name: antreacontrollerinfos.crd.antrea.io spec: diff --git a/pkg/apis/crd/v1alpha2/register.go b/pkg/apis/crd/v1alpha2/register.go index 5535b6785dc..98d5d2bc48c 100644 --- a/pkg/apis/crd/v1alpha2/register.go +++ b/pkg/apis/crd/v1alpha2/register.go @@ -50,6 +50,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &ClusterGroupList{}, &Egress{}, &EgressList{}, + &ExternalIPPool{}, + &ExternalIPPoolList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) diff --git a/pkg/apis/crd/v1alpha2/types.go b/pkg/apis/crd/v1alpha2/types.go index 19c8afaef7f..6393886a43b 100644 --- a/pkg/apis/crd/v1alpha2/types.go +++ b/pkg/apis/crd/v1alpha2/types.go @@ -209,7 +209,15 @@ type EgressSpec struct { // AppliedTo selects Pods to which the Egress will be applied. AppliedTo AppliedTo `json:"appliedTo"` // EgressIP specifies the SNAT IP address for the selected workloads. + // If ExternalIPPool is empty, it must be specified manually. + // If ExternalIPPool is non-empty, it can be empty and will be assigned by Antrea automatically. + // If both ExternalIPPool and EgressIP are non-empty, the IP must be in the pool. EgressIP string `json:"egressIP"` + // ExternalIPPool specifies the IP Pool that the EgressIP should be allocated from. + // If it is empty, the specified EgressIP must be assigned to a Node manually. + // If it is non-empty, the EgressIP will be assigned to a Node specified by the pool automatically and will failover + // to a different Node when the Node becomes unreachable. + ExternalIPPool string `json:"externalIPPool"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -221,3 +229,46 @@ type EgressList struct { Items []Egress `json:"items"` } + +// +genclient +// +genclient:nonNamespaced +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// ExternalIPPool defines one or multiple IP sets that can be used in the external network. For instance, the IPs can be +// allocated to the Egress resources as the Egress IPs. +type ExternalIPPool struct { + metav1.TypeMeta `json:",inline"` + // Standard metadata of the object. + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Specification of the ExternalIPPool. + Spec ExternalIPPoolSpec `json:"spec"` +} + +type ExternalIPPoolSpec struct { + // The IP ranges of this IP pool, e.g. 10.10.0.0/24, 10.10.10.2-10.10.10.20, 10.10.10.30-10.10.10.30. + IPRanges []IPRange `json:"ipRanges"` + // The Nodes that the external IPs can be assigned to. If empty, it means all Nodes. + NodeSelector metav1.LabelSelector `json:"nodeSelector"` +} + +// IPRange is a set of contiguous IP addresses, represented by a CIDR or a pair of start and end IPs. +type IPRange struct { + // The CIDR of this range, e.g. 10.10.10.0/24. + CIDR string `json:"cidr"` + // The start IP of the range, e.g. 10.10.20.5, inclusive. + Start string `json:"start"` + // The end IP of the range, e.g. 10.10.20.20, inclusive. + End string `json:"end"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type ExternalIPPoolList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata,omitempty"` + + Items []ExternalIPPool `json:"items"` +} diff --git a/pkg/apis/crd/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/crd/v1alpha2/zz_generated.deepcopy.go index 1349bf9a243..cdf7e23580f 100644 --- a/pkg/apis/crd/v1alpha2/zz_generated.deepcopy.go +++ b/pkg/apis/crd/v1alpha2/zz_generated.deepcopy.go @@ -295,6 +295,88 @@ func (in *ExternalEntitySpec) DeepCopy() *ExternalEntitySpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExternalIPPool) DeepCopyInto(out *ExternalIPPool) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalIPPool. +func (in *ExternalIPPool) DeepCopy() *ExternalIPPool { + if in == nil { + return nil + } + out := new(ExternalIPPool) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ExternalIPPool) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExternalIPPoolList) DeepCopyInto(out *ExternalIPPoolList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ExternalIPPool, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalIPPoolList. +func (in *ExternalIPPoolList) DeepCopy() *ExternalIPPoolList { + if in == nil { + return nil + } + out := new(ExternalIPPoolList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ExternalIPPoolList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExternalIPPoolSpec) DeepCopyInto(out *ExternalIPPoolSpec) { + *out = *in + if in.IPRanges != nil { + in, out := &in.IPRanges, &out.IPRanges + *out = make([]IPRange, len(*in)) + copy(*out, *in) + } + in.NodeSelector.DeepCopyInto(&out.NodeSelector) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalIPPoolSpec. +func (in *ExternalIPPoolSpec) DeepCopy() *ExternalIPPoolSpec { + if in == nil { + return nil + } + out := new(ExternalIPPoolSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GroupCondition) DeepCopyInto(out *GroupCondition) { *out = *in @@ -386,6 +468,22 @@ func (in *GroupStatus) DeepCopy() *GroupStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPRange) DeepCopyInto(out *IPRange) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPRange. +func (in *IPRange) DeepCopy() *IPRange { + if in == nil { + return nil + } + out := new(IPRange) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NamedPort) DeepCopyInto(out *NamedPort) { *out = *in diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha2/crd_client.go b/pkg/client/clientset/versioned/typed/crd/v1alpha2/crd_client.go index 7644a87a64f..1ce952857ba 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1alpha2/crd_client.go +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha2/crd_client.go @@ -27,6 +27,7 @@ type CrdV1alpha2Interface interface { ClusterGroupsGetter EgressesGetter ExternalEntitiesGetter + ExternalIPPoolsGetter } // CrdV1alpha2Client is used to interact with features provided by the crd.antrea.io group. @@ -46,6 +47,10 @@ func (c *CrdV1alpha2Client) ExternalEntities(namespace string) ExternalEntityInt return newExternalEntities(c, namespace) } +func (c *CrdV1alpha2Client) ExternalIPPools() ExternalIPPoolInterface { + return newExternalIPPools(c) +} + // NewForConfig creates a new CrdV1alpha2Client for the given config. func NewForConfig(c *rest.Config) (*CrdV1alpha2Client, error) { config := *c diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha2/externalippool.go b/pkg/client/clientset/versioned/typed/crd/v1alpha2/externalippool.go new file mode 100644 index 00000000000..22bda211898 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha2/externalippool.go @@ -0,0 +1,166 @@ +// Copyright 2021 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 v1alpha2 + +import ( + "context" + "time" + + v1alpha2 "antrea.io/antrea/pkg/apis/crd/v1alpha2" + scheme "antrea.io/antrea/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// ExternalIPPoolsGetter has a method to return a ExternalIPPoolInterface. +// A group's client should implement this interface. +type ExternalIPPoolsGetter interface { + ExternalIPPools() ExternalIPPoolInterface +} + +// ExternalIPPoolInterface has methods to work with ExternalIPPool resources. +type ExternalIPPoolInterface interface { + Create(ctx context.Context, externalIPPool *v1alpha2.ExternalIPPool, opts v1.CreateOptions) (*v1alpha2.ExternalIPPool, error) + Update(ctx context.Context, externalIPPool *v1alpha2.ExternalIPPool, opts v1.UpdateOptions) (*v1alpha2.ExternalIPPool, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha2.ExternalIPPool, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha2.ExternalIPPoolList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.ExternalIPPool, err error) + ExternalIPPoolExpansion +} + +// externalIPPools implements ExternalIPPoolInterface +type externalIPPools struct { + client rest.Interface +} + +// newExternalIPPools returns a ExternalIPPools +func newExternalIPPools(c *CrdV1alpha2Client) *externalIPPools { + return &externalIPPools{ + client: c.RESTClient(), + } +} + +// Get takes name of the externalIPPool, and returns the corresponding externalIPPool object, and an error if there is any. +func (c *externalIPPools) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha2.ExternalIPPool, err error) { + result = &v1alpha2.ExternalIPPool{} + err = c.client.Get(). + Resource("externalippools"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of ExternalIPPools that match those selectors. +func (c *externalIPPools) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha2.ExternalIPPoolList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha2.ExternalIPPoolList{} + err = c.client.Get(). + Resource("externalippools"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested externalIPPools. +func (c *externalIPPools) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Resource("externalippools"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a externalIPPool and creates it. Returns the server's representation of the externalIPPool, and an error, if there is any. +func (c *externalIPPools) Create(ctx context.Context, externalIPPool *v1alpha2.ExternalIPPool, opts v1.CreateOptions) (result *v1alpha2.ExternalIPPool, err error) { + result = &v1alpha2.ExternalIPPool{} + err = c.client.Post(). + Resource("externalippools"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(externalIPPool). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a externalIPPool and updates it. Returns the server's representation of the externalIPPool, and an error, if there is any. +func (c *externalIPPools) Update(ctx context.Context, externalIPPool *v1alpha2.ExternalIPPool, opts v1.UpdateOptions) (result *v1alpha2.ExternalIPPool, err error) { + result = &v1alpha2.ExternalIPPool{} + err = c.client.Put(). + Resource("externalippools"). + Name(externalIPPool.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(externalIPPool). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the externalIPPool and deletes it. Returns an error if one occurs. +func (c *externalIPPools) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Resource("externalippools"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *externalIPPools) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Resource("externalippools"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched externalIPPool. +func (c *externalIPPools) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.ExternalIPPool, err error) { + result = &v1alpha2.ExternalIPPool{} + err = c.client.Patch(pt). + Resource("externalippools"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha2/fake/fake_crd_client.go b/pkg/client/clientset/versioned/typed/crd/v1alpha2/fake/fake_crd_client.go index b0313f4392f..391235b1022 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1alpha2/fake/fake_crd_client.go +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha2/fake/fake_crd_client.go @@ -38,6 +38,10 @@ func (c *FakeCrdV1alpha2) ExternalEntities(namespace string) v1alpha2.ExternalEn return &FakeExternalEntities{c, namespace} } +func (c *FakeCrdV1alpha2) ExternalIPPools() v1alpha2.ExternalIPPoolInterface { + return &FakeExternalIPPools{c} +} + // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. func (c *FakeCrdV1alpha2) RESTClient() rest.Interface { diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha2/fake/fake_externalippool.go b/pkg/client/clientset/versioned/typed/crd/v1alpha2/fake/fake_externalippool.go new file mode 100644 index 00000000000..ec9728439df --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha2/fake/fake_externalippool.go @@ -0,0 +1,120 @@ +// Copyright 2021 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" + + v1alpha2 "antrea.io/antrea/pkg/apis/crd/v1alpha2" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeExternalIPPools implements ExternalIPPoolInterface +type FakeExternalIPPools struct { + Fake *FakeCrdV1alpha2 +} + +var externalippoolsResource = schema.GroupVersionResource{Group: "crd.antrea.io", Version: "v1alpha2", Resource: "externalippools"} + +var externalippoolsKind = schema.GroupVersionKind{Group: "crd.antrea.io", Version: "v1alpha2", Kind: "ExternalIPPool"} + +// Get takes name of the externalIPPool, and returns the corresponding externalIPPool object, and an error if there is any. +func (c *FakeExternalIPPools) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha2.ExternalIPPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(externalippoolsResource, name), &v1alpha2.ExternalIPPool{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.ExternalIPPool), err +} + +// List takes label and field selectors, and returns the list of ExternalIPPools that match those selectors. +func (c *FakeExternalIPPools) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha2.ExternalIPPoolList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(externalippoolsResource, externalippoolsKind, opts), &v1alpha2.ExternalIPPoolList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha2.ExternalIPPoolList{ListMeta: obj.(*v1alpha2.ExternalIPPoolList).ListMeta} + for _, item := range obj.(*v1alpha2.ExternalIPPoolList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested externalIPPools. +func (c *FakeExternalIPPools) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(externalippoolsResource, opts)) +} + +// Create takes the representation of a externalIPPool and creates it. Returns the server's representation of the externalIPPool, and an error, if there is any. +func (c *FakeExternalIPPools) Create(ctx context.Context, externalIPPool *v1alpha2.ExternalIPPool, opts v1.CreateOptions) (result *v1alpha2.ExternalIPPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(externalippoolsResource, externalIPPool), &v1alpha2.ExternalIPPool{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.ExternalIPPool), err +} + +// Update takes the representation of a externalIPPool and updates it. Returns the server's representation of the externalIPPool, and an error, if there is any. +func (c *FakeExternalIPPools) Update(ctx context.Context, externalIPPool *v1alpha2.ExternalIPPool, opts v1.UpdateOptions) (result *v1alpha2.ExternalIPPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(externalippoolsResource, externalIPPool), &v1alpha2.ExternalIPPool{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.ExternalIPPool), err +} + +// Delete takes name of the externalIPPool and deletes it. Returns an error if one occurs. +func (c *FakeExternalIPPools) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteAction(externalippoolsResource, name), &v1alpha2.ExternalIPPool{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeExternalIPPools) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(externalippoolsResource, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha2.ExternalIPPoolList{}) + return err +} + +// Patch applies the patch and returns the patched externalIPPool. +func (c *FakeExternalIPPools) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.ExternalIPPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(externalippoolsResource, name, pt, data, subresources...), &v1alpha2.ExternalIPPool{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.ExternalIPPool), err +} diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha2/generated_expansion.go b/pkg/client/clientset/versioned/typed/crd/v1alpha2/generated_expansion.go index 84ce57ad595..08dcf57456d 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1alpha2/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha2/generated_expansion.go @@ -21,3 +21,5 @@ type ClusterGroupExpansion interface{} type EgressExpansion interface{} type ExternalEntityExpansion interface{} + +type ExternalIPPoolExpansion interface{} diff --git a/pkg/client/informers/externalversions/crd/v1alpha2/externalippool.go b/pkg/client/informers/externalversions/crd/v1alpha2/externalippool.go new file mode 100644 index 00000000000..faa0fd0a7be --- /dev/null +++ b/pkg/client/informers/externalversions/crd/v1alpha2/externalippool.go @@ -0,0 +1,87 @@ +// Copyright 2021 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 v1alpha2 + +import ( + "context" + time "time" + + crdv1alpha2 "antrea.io/antrea/pkg/apis/crd/v1alpha2" + versioned "antrea.io/antrea/pkg/client/clientset/versioned" + internalinterfaces "antrea.io/antrea/pkg/client/informers/externalversions/internalinterfaces" + v1alpha2 "antrea.io/antrea/pkg/client/listers/crd/v1alpha2" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// ExternalIPPoolInformer provides access to a shared informer and lister for +// ExternalIPPools. +type ExternalIPPoolInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha2.ExternalIPPoolLister +} + +type externalIPPoolInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewExternalIPPoolInformer constructs a new informer for ExternalIPPool type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewExternalIPPoolInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredExternalIPPoolInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredExternalIPPoolInformer constructs a new informer for ExternalIPPool type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredExternalIPPoolInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CrdV1alpha2().ExternalIPPools().List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CrdV1alpha2().ExternalIPPools().Watch(context.TODO(), options) + }, + }, + &crdv1alpha2.ExternalIPPool{}, + resyncPeriod, + indexers, + ) +} + +func (f *externalIPPoolInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredExternalIPPoolInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *externalIPPoolInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&crdv1alpha2.ExternalIPPool{}, f.defaultInformer) +} + +func (f *externalIPPoolInformer) Lister() v1alpha2.ExternalIPPoolLister { + return v1alpha2.NewExternalIPPoolLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/crd/v1alpha2/interface.go b/pkg/client/informers/externalversions/crd/v1alpha2/interface.go index 34429581736..43a1a6ab589 100644 --- a/pkg/client/informers/externalversions/crd/v1alpha2/interface.go +++ b/pkg/client/informers/externalversions/crd/v1alpha2/interface.go @@ -28,6 +28,8 @@ type Interface interface { Egresses() EgressInformer // ExternalEntities returns a ExternalEntityInformer. ExternalEntities() ExternalEntityInformer + // ExternalIPPools returns a ExternalIPPoolInformer. + ExternalIPPools() ExternalIPPoolInformer } type version struct { @@ -55,3 +57,8 @@ func (v *version) Egresses() EgressInformer { func (v *version) ExternalEntities() ExternalEntityInformer { return &externalEntityInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } + +// ExternalIPPools returns a ExternalIPPoolInformer. +func (v *version) ExternalIPPools() ExternalIPPoolInformer { + return &externalIPPoolInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 3c2e8def088..a8036b1278f 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -70,6 +70,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1alpha2().Egresses().Informer()}, nil case v1alpha2.SchemeGroupVersion.WithResource("externalentities"): return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1alpha2().ExternalEntities().Informer()}, nil + case v1alpha2.SchemeGroupVersion.WithResource("externalippools"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1alpha2().ExternalIPPools().Informer()}, nil // Group=crd.antrea.io, Version=v1alpha3 case v1alpha3.SchemeGroupVersion.WithResource("clustergroups"): diff --git a/pkg/client/listers/crd/v1alpha2/expansion_generated.go b/pkg/client/listers/crd/v1alpha2/expansion_generated.go index 0ec11ad4cc3..3fb6441e337 100644 --- a/pkg/client/listers/crd/v1alpha2/expansion_generated.go +++ b/pkg/client/listers/crd/v1alpha2/expansion_generated.go @@ -31,3 +31,7 @@ type ExternalEntityListerExpansion interface{} // ExternalEntityNamespaceListerExpansion allows custom methods to be added to // ExternalEntityNamespaceLister. type ExternalEntityNamespaceListerExpansion interface{} + +// ExternalIPPoolListerExpansion allows custom methods to be added to +// ExternalIPPoolLister. +type ExternalIPPoolListerExpansion interface{} diff --git a/pkg/client/listers/crd/v1alpha2/externalippool.go b/pkg/client/listers/crd/v1alpha2/externalippool.go new file mode 100644 index 00000000000..c3d8ef31b7c --- /dev/null +++ b/pkg/client/listers/crd/v1alpha2/externalippool.go @@ -0,0 +1,66 @@ +// Copyright 2021 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 v1alpha2 + +import ( + v1alpha2 "antrea.io/antrea/pkg/apis/crd/v1alpha2" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// ExternalIPPoolLister helps list ExternalIPPools. +// All objects returned here must be treated as read-only. +type ExternalIPPoolLister interface { + // List lists all ExternalIPPools in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha2.ExternalIPPool, err error) + // Get retrieves the ExternalIPPool from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha2.ExternalIPPool, error) + ExternalIPPoolListerExpansion +} + +// externalIPPoolLister implements the ExternalIPPoolLister interface. +type externalIPPoolLister struct { + indexer cache.Indexer +} + +// NewExternalIPPoolLister returns a new ExternalIPPoolLister. +func NewExternalIPPoolLister(indexer cache.Indexer) ExternalIPPoolLister { + return &externalIPPoolLister{indexer: indexer} +} + +// List lists all ExternalIPPools in the indexer. +func (s *externalIPPoolLister) List(selector labels.Selector) (ret []*v1alpha2.ExternalIPPool, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha2.ExternalIPPool)) + }) + return ret, err +} + +// Get retrieves the ExternalIPPool from the index for a given name. +func (s *externalIPPoolLister) Get(name string) (*v1alpha2.ExternalIPPool, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha2.Resource("externalippool"), name) + } + return obj.(*v1alpha2.ExternalIPPool), nil +}