From 082bbef093c6d04dc2c21fdb9ee6578227a0b4ee Mon Sep 17 00:00:00 2001 From: Jianjun Shen Date: Thu, 1 Oct 2020 22:13:38 -0700 Subject: [PATCH] Add egress policy CRD types Add types for egress policy CRDs, including Egress for the egress policy definition, and a common AppliedTo struct for defining the scope to which a policy is applied. --- pkg/apis/crd/v1alpha2/types.go | 51 ++++++ .../crd/v1alpha2/zz_generated.deepcopy.go | 108 ++++++++++++ .../typed/crd/v1alpha2/crd_client.go | 5 + .../versioned/typed/crd/v1alpha2/egress.go | 166 ++++++++++++++++++ .../crd/v1alpha2/fake/fake_crd_client.go | 4 + .../typed/crd/v1alpha2/fake/fake_egress.go | 120 +++++++++++++ .../typed/crd/v1alpha2/generated_expansion.go | 2 + .../externalversions/crd/v1alpha2/egress.go | 87 +++++++++ .../crd/v1alpha2/interface.go | 7 + .../informers/externalversions/generic.go | 2 + pkg/client/listers/crd/v1alpha2/egress.go | 63 +++++++ .../crd/v1alpha2/expansion_generated.go | 4 + 12 files changed, 619 insertions(+) create mode 100644 pkg/client/clientset/versioned/typed/crd/v1alpha2/egress.go create mode 100644 pkg/client/clientset/versioned/typed/crd/v1alpha2/fake/fake_egress.go create mode 100644 pkg/client/informers/externalversions/crd/v1alpha2/egress.go create mode 100644 pkg/client/listers/crd/v1alpha2/egress.go diff --git a/pkg/apis/crd/v1alpha2/types.go b/pkg/apis/crd/v1alpha2/types.go index 2cb5bb8b659..ed146fd0945 100644 --- a/pkg/apis/crd/v1alpha2/types.go +++ b/pkg/apis/crd/v1alpha2/types.go @@ -170,3 +170,54 @@ type ClusterGroupList struct { Items []ClusterGroup `json:"items,omitempty"` } + +// AppliedTo selects the entities to which a policy is applied. +type AppliedTo struct { + // Select Pods matched by this selector. If set with NamespaceSelector, + // Pods are matched from Namespaces matched by the NamespaceSelector; + // otherwise, Pods are matched from all Namespaces. + // +optional + PodSelector *metav1.LabelSelector `json:"podSelector,omitempty"` + // Select all Pods from Namespaces matched by this selector. If set with + // PodSelector, Pods are matched from Namespaces matched by the + // NamespaceSelector. + // +optional + NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"` + // Groups is the set of ClusterGroup names. + // +optional + Groups []string `json:"groups,omitempty"` +} + +// +genclient +// +genclient:nonNamespaced +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Egress defines which egress (SNAT) IP the traffic from the selected Pods to +// the external network should use. +type Egress struct { + metav1.TypeMeta `json:",inline"` + // Standard metadata of the object. + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Specification of the desired behavior of Egress. + Spec EgressSpec `json:"spec"` +} + +// EgressSpec defines the desired state for Egress. +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. + EgressIP string `json:"egressIP"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type EgressList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata,omitempty"` + + Items []Egress `json:"items"` +} diff --git a/pkg/apis/crd/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/crd/v1alpha2/zz_generated.deepcopy.go index 631dc53e83a..0e978d91eda 100644 --- a/pkg/apis/crd/v1alpha2/zz_generated.deepcopy.go +++ b/pkg/apis/crd/v1alpha2/zz_generated.deepcopy.go @@ -24,6 +24,37 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AppliedTo) DeepCopyInto(out *AppliedTo) { + *out = *in + if in.PodSelector != nil { + in, out := &in.PodSelector, &out.PodSelector + *out = new(v1.LabelSelector) + (*in).DeepCopyInto(*out) + } + if in.NamespaceSelector != nil { + in, out := &in.NamespaceSelector, &out.NamespaceSelector + *out = new(v1.LabelSelector) + (*in).DeepCopyInto(*out) + } + if in.Groups != nil { + in, out := &in.Groups, &out.Groups + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AppliedTo. +func (in *AppliedTo) DeepCopy() *AppliedTo { + if in == nil { + return nil + } + out := new(AppliedTo) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterGroup) DeepCopyInto(out *ClusterGroup) { *out = *in @@ -85,6 +116,83 @@ func (in *ClusterGroupList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Egress) DeepCopyInto(out *Egress) { + *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 Egress. +func (in *Egress) DeepCopy() *Egress { + if in == nil { + return nil + } + out := new(Egress) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Egress) 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 *EgressList) DeepCopyInto(out *EgressList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Egress, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EgressList. +func (in *EgressList) DeepCopy() *EgressList { + if in == nil { + return nil + } + out := new(EgressList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *EgressList) 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 *EgressSpec) DeepCopyInto(out *EgressSpec) { + *out = *in + in.AppliedTo.DeepCopyInto(&out.AppliedTo) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EgressSpec. +func (in *EgressSpec) DeepCopy() *EgressSpec { + if in == nil { + return nil + } + out := new(EgressSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Endpoint) DeepCopyInto(out *Endpoint) { *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 6858cc816ec..4e9186851bf 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1alpha2/crd_client.go +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha2/crd_client.go @@ -25,6 +25,7 @@ import ( type CrdV1alpha2Interface interface { RESTClient() rest.Interface ClusterGroupsGetter + EgressesGetter ExternalEntitiesGetter } @@ -37,6 +38,10 @@ func (c *CrdV1alpha2Client) ClusterGroups() ClusterGroupInterface { return newClusterGroups(c) } +func (c *CrdV1alpha2Client) Egresses() EgressInterface { + return newEgresses(c) +} + func (c *CrdV1alpha2Client) ExternalEntities(namespace string) ExternalEntityInterface { return newExternalEntities(c, namespace) } diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha2/egress.go b/pkg/client/clientset/versioned/typed/crd/v1alpha2/egress.go new file mode 100644 index 00000000000..effb298981a --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha2/egress.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 "github.com/vmware-tanzu/antrea/pkg/apis/crd/v1alpha2" + scheme "github.com/vmware-tanzu/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" +) + +// EgressesGetter has a method to return a EgressInterface. +// A group's client should implement this interface. +type EgressesGetter interface { + Egresses() EgressInterface +} + +// EgressInterface has methods to work with Egress resources. +type EgressInterface interface { + Create(ctx context.Context, egress *v1alpha2.Egress, opts v1.CreateOptions) (*v1alpha2.Egress, error) + Update(ctx context.Context, egress *v1alpha2.Egress, opts v1.UpdateOptions) (*v1alpha2.Egress, 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.Egress, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha2.EgressList, 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.Egress, err error) + EgressExpansion +} + +// egresses implements EgressInterface +type egresses struct { + client rest.Interface +} + +// newEgresses returns a Egresses +func newEgresses(c *CrdV1alpha2Client) *egresses { + return &egresses{ + client: c.RESTClient(), + } +} + +// Get takes name of the egress, and returns the corresponding egress object, and an error if there is any. +func (c *egresses) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha2.Egress, err error) { + result = &v1alpha2.Egress{} + err = c.client.Get(). + Resource("egresses"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of Egresses that match those selectors. +func (c *egresses) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha2.EgressList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha2.EgressList{} + err = c.client.Get(). + Resource("egresses"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested egresses. +func (c *egresses) 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("egresses"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a egress and creates it. Returns the server's representation of the egress, and an error, if there is any. +func (c *egresses) Create(ctx context.Context, egress *v1alpha2.Egress, opts v1.CreateOptions) (result *v1alpha2.Egress, err error) { + result = &v1alpha2.Egress{} + err = c.client.Post(). + Resource("egresses"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(egress). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a egress and updates it. Returns the server's representation of the egress, and an error, if there is any. +func (c *egresses) Update(ctx context.Context, egress *v1alpha2.Egress, opts v1.UpdateOptions) (result *v1alpha2.Egress, err error) { + result = &v1alpha2.Egress{} + err = c.client.Put(). + Resource("egresses"). + Name(egress.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(egress). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the egress and deletes it. Returns an error if one occurs. +func (c *egresses) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Resource("egresses"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *egresses) 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("egresses"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched egress. +func (c *egresses) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.Egress, err error) { + result = &v1alpha2.Egress{} + err = c.client.Patch(pt). + Resource("egresses"). + 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 2be5c124820..2d8d68b20f3 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 @@ -30,6 +30,10 @@ func (c *FakeCrdV1alpha2) ClusterGroups() v1alpha2.ClusterGroupInterface { return &FakeClusterGroups{c} } +func (c *FakeCrdV1alpha2) Egresses() v1alpha2.EgressInterface { + return &FakeEgresses{c} +} + func (c *FakeCrdV1alpha2) ExternalEntities(namespace string) v1alpha2.ExternalEntityInterface { return &FakeExternalEntities{c, namespace} } diff --git a/pkg/client/clientset/versioned/typed/crd/v1alpha2/fake/fake_egress.go b/pkg/client/clientset/versioned/typed/crd/v1alpha2/fake/fake_egress.go new file mode 100644 index 00000000000..98afd86b1f6 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha2/fake/fake_egress.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 "github.com/vmware-tanzu/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" +) + +// FakeEgresses implements EgressInterface +type FakeEgresses struct { + Fake *FakeCrdV1alpha2 +} + +var egressesResource = schema.GroupVersionResource{Group: "crd.antrea.io", Version: "v1alpha2", Resource: "egresses"} + +var egressesKind = schema.GroupVersionKind{Group: "crd.antrea.io", Version: "v1alpha2", Kind: "Egress"} + +// Get takes name of the egress, and returns the corresponding egress object, and an error if there is any. +func (c *FakeEgresses) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha2.Egress, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(egressesResource, name), &v1alpha2.Egress{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.Egress), err +} + +// List takes label and field selectors, and returns the list of Egresses that match those selectors. +func (c *FakeEgresses) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha2.EgressList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(egressesResource, egressesKind, opts), &v1alpha2.EgressList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha2.EgressList{ListMeta: obj.(*v1alpha2.EgressList).ListMeta} + for _, item := range obj.(*v1alpha2.EgressList).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 egresses. +func (c *FakeEgresses) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(egressesResource, opts)) +} + +// Create takes the representation of a egress and creates it. Returns the server's representation of the egress, and an error, if there is any. +func (c *FakeEgresses) Create(ctx context.Context, egress *v1alpha2.Egress, opts v1.CreateOptions) (result *v1alpha2.Egress, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(egressesResource, egress), &v1alpha2.Egress{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.Egress), err +} + +// Update takes the representation of a egress and updates it. Returns the server's representation of the egress, and an error, if there is any. +func (c *FakeEgresses) Update(ctx context.Context, egress *v1alpha2.Egress, opts v1.UpdateOptions) (result *v1alpha2.Egress, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(egressesResource, egress), &v1alpha2.Egress{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.Egress), err +} + +// Delete takes name of the egress and deletes it. Returns an error if one occurs. +func (c *FakeEgresses) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteAction(egressesResource, name), &v1alpha2.Egress{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeEgresses) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(egressesResource, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha2.EgressList{}) + return err +} + +// Patch applies the patch and returns the patched egress. +func (c *FakeEgresses) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.Egress, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(egressesResource, name, pt, data, subresources...), &v1alpha2.Egress{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.Egress), 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 94393e2df12..84ce57ad595 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1alpha2/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/crd/v1alpha2/generated_expansion.go @@ -18,4 +18,6 @@ package v1alpha2 type ClusterGroupExpansion interface{} +type EgressExpansion interface{} + type ExternalEntityExpansion interface{} diff --git a/pkg/client/informers/externalversions/crd/v1alpha2/egress.go b/pkg/client/informers/externalversions/crd/v1alpha2/egress.go new file mode 100644 index 00000000000..faeea4d582c --- /dev/null +++ b/pkg/client/informers/externalversions/crd/v1alpha2/egress.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 "github.com/vmware-tanzu/antrea/pkg/apis/crd/v1alpha2" + versioned "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned" + internalinterfaces "github.com/vmware-tanzu/antrea/pkg/client/informers/externalversions/internalinterfaces" + v1alpha2 "github.com/vmware-tanzu/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" +) + +// EgressInformer provides access to a shared informer and lister for +// Egresses. +type EgressInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha2.EgressLister +} + +type egressInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewEgressInformer constructs a new informer for Egress 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 NewEgressInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredEgressInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredEgressInformer constructs a new informer for Egress 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 NewFilteredEgressInformer(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().Egresses().List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CrdV1alpha2().Egresses().Watch(context.TODO(), options) + }, + }, + &crdv1alpha2.Egress{}, + resyncPeriod, + indexers, + ) +} + +func (f *egressInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredEgressInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *egressInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&crdv1alpha2.Egress{}, f.defaultInformer) +} + +func (f *egressInformer) Lister() v1alpha2.EgressLister { + return v1alpha2.NewEgressLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/crd/v1alpha2/interface.go b/pkg/client/informers/externalversions/crd/v1alpha2/interface.go index 0a8d5900de6..f391e5ee899 100644 --- a/pkg/client/informers/externalversions/crd/v1alpha2/interface.go +++ b/pkg/client/informers/externalversions/crd/v1alpha2/interface.go @@ -24,6 +24,8 @@ import ( type Interface interface { // ClusterGroups returns a ClusterGroupInformer. ClusterGroups() ClusterGroupInformer + // Egresses returns a EgressInformer. + Egresses() EgressInformer // ExternalEntities returns a ExternalEntityInformer. ExternalEntities() ExternalEntityInformer } @@ -44,6 +46,11 @@ func (v *version) ClusterGroups() ClusterGroupInformer { return &clusterGroupInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } +// Egresses returns a EgressInformer. +func (v *version) Egresses() EgressInformer { + return &egressInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + // ExternalEntities returns a ExternalEntityInformer. func (v *version) ExternalEntities() ExternalEntityInformer { return &externalEntityInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 4e0b7ef5499..c0620165197 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -65,6 +65,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource // Group=crd.antrea.io, Version=v1alpha2 case v1alpha2.SchemeGroupVersion.WithResource("clustergroups"): return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1alpha2().ClusterGroups().Informer()}, nil + case v1alpha2.SchemeGroupVersion.WithResource("egresses"): + 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 diff --git a/pkg/client/listers/crd/v1alpha2/egress.go b/pkg/client/listers/crd/v1alpha2/egress.go new file mode 100644 index 00000000000..5b4ce42ffc1 --- /dev/null +++ b/pkg/client/listers/crd/v1alpha2/egress.go @@ -0,0 +1,63 @@ +// 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 "github.com/vmware-tanzu/antrea/pkg/apis/crd/v1alpha2" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// EgressLister helps list Egresses. +type EgressLister interface { + // List lists all Egresses in the indexer. + List(selector labels.Selector) (ret []*v1alpha2.Egress, err error) + // Get retrieves the Egress from the index for a given name. + Get(name string) (*v1alpha2.Egress, error) + EgressListerExpansion +} + +// egressLister implements the EgressLister interface. +type egressLister struct { + indexer cache.Indexer +} + +// NewEgressLister returns a new EgressLister. +func NewEgressLister(indexer cache.Indexer) EgressLister { + return &egressLister{indexer: indexer} +} + +// List lists all Egresses in the indexer. +func (s *egressLister) List(selector labels.Selector) (ret []*v1alpha2.Egress, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha2.Egress)) + }) + return ret, err +} + +// Get retrieves the Egress from the index for a given name. +func (s *egressLister) Get(name string) (*v1alpha2.Egress, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha2.Resource("egress"), name) + } + return obj.(*v1alpha2.Egress), nil +} diff --git a/pkg/client/listers/crd/v1alpha2/expansion_generated.go b/pkg/client/listers/crd/v1alpha2/expansion_generated.go index 3b0a15efa32..0ec11ad4cc3 100644 --- a/pkg/client/listers/crd/v1alpha2/expansion_generated.go +++ b/pkg/client/listers/crd/v1alpha2/expansion_generated.go @@ -20,6 +20,10 @@ package v1alpha2 // ClusterGroupLister. type ClusterGroupListerExpansion interface{} +// EgressListerExpansion allows custom methods to be added to +// EgressLister. +type EgressListerExpansion interface{} + // ExternalEntityListerExpansion allows custom methods to be added to // ExternalEntityLister. type ExternalEntityListerExpansion interface{}