From 489c8968f49ad8c96beda9c43049fbb71e71c54b Mon Sep 17 00:00:00 2001 From: Michi Mutsuzaki Date: Fri, 15 Sep 2023 21:40:46 +0000 Subject: [PATCH] k8s: Generate PodInfo client I forgot to add "// +genclient" for PodInfo. Signed-off-by: Michi Mutsuzaki --- pkg/k8s/apis/cilium.io/v1alpha1/types.go | 1 + .../cilium.io/v1alpha1/cilium.io_client.go | 5 + .../v1alpha1/fake/fake_cilium.io_client.go | 4 + .../cilium.io/v1alpha1/fake/fake_podinfo.go | 128 ++++++++++++ .../cilium.io/v1alpha1/generated_expansion.go | 2 + .../typed/cilium.io/v1alpha1/podinfo.go | 182 ++++++++++++++++++ .../cilium.io/v1alpha1/interface.go | 7 + .../cilium.io/v1alpha1/podinfo.go | 77 ++++++++ .../informers/externalversions/generic.go | 2 + .../cilium.io/v1alpha1/expansion_generated.go | 8 + .../listers/cilium.io/v1alpha1/podinfo.go | 86 +++++++++ .../pkg/k8s/apis/cilium.io/v1alpha1/types.go | 1 + .../cilium.io/v1alpha1/cilium.io_client.go | 5 + .../cilium.io/v1alpha1/generated_expansion.go | 2 + .../typed/cilium.io/v1alpha1/podinfo.go | 182 ++++++++++++++++++ .../cilium.io/v1alpha1/interface.go | 7 + .../cilium.io/v1alpha1/podinfo.go | 77 ++++++++ .../informers/externalversions/generic.go | 2 + .../cilium.io/v1alpha1/expansion_generated.go | 8 + .../listers/cilium.io/v1alpha1/podinfo.go | 86 +++++++++ 20 files changed, 872 insertions(+) create mode 100644 pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/fake/fake_podinfo.go create mode 100644 pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/podinfo.go create mode 100644 pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/podinfo.go create mode 100644 pkg/k8s/client/listers/cilium.io/v1alpha1/podinfo.go create mode 100644 vendor/github.com/cilium/tetragon/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/podinfo.go create mode 100644 vendor/github.com/cilium/tetragon/pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/podinfo.go create mode 100644 vendor/github.com/cilium/tetragon/pkg/k8s/client/listers/cilium.io/v1alpha1/podinfo.go diff --git a/pkg/k8s/apis/cilium.io/v1alpha1/types.go b/pkg/k8s/apis/cilium.io/v1alpha1/types.go index e3fe6271424..560f5a5f9d5 100644 --- a/pkg/k8s/apis/cilium.io/v1alpha1/types.go +++ b/pkg/k8s/apis/cilium.io/v1alpha1/types.go @@ -271,6 +271,7 @@ type PodIP struct { IP string `json:"IP,omitempty"` } +// +genclient // +kubebuilder:object:root=true // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +kubebuilder:resource:singular="podinfo",path="podinfo",scope="Namespaced",shortName={} diff --git a/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/cilium.io_client.go b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/cilium.io_client.go index 92f41bf30b1..8392d8b2b17 100644 --- a/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/cilium.io_client.go +++ b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/cilium.io_client.go @@ -15,6 +15,7 @@ import ( type CiliumV1alpha1Interface interface { RESTClient() rest.Interface + PodInfoGetter TracingPoliciesGetter TracingPoliciesNamespacedGetter } @@ -24,6 +25,10 @@ type CiliumV1alpha1Client struct { restClient rest.Interface } +func (c *CiliumV1alpha1Client) PodInfo(namespace string) PodInfoInterface { + return newPodInfo(c, namespace) +} + func (c *CiliumV1alpha1Client) TracingPolicies() TracingPolicyInterface { return newTracingPolicies(c) } diff --git a/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/fake/fake_cilium.io_client.go b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/fake/fake_cilium.io_client.go index f6f74531a5d..d91edfe95e4 100644 --- a/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/fake/fake_cilium.io_client.go +++ b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/fake/fake_cilium.io_client.go @@ -15,6 +15,10 @@ type FakeCiliumV1alpha1 struct { *testing.Fake } +func (c *FakeCiliumV1alpha1) PodInfo(namespace string) v1alpha1.PodInfoInterface { + return &FakePodInfo{c, namespace} +} + func (c *FakeCiliumV1alpha1) TracingPolicies() v1alpha1.TracingPolicyInterface { return &FakeTracingPolicies{c} } diff --git a/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/fake/fake_podinfo.go b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/fake/fake_podinfo.go new file mode 100644 index 00000000000..b33229b2114 --- /dev/null +++ b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/fake/fake_podinfo.go @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Authors of Tetragon + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1alpha1 "github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/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" +) + +// FakePodInfo implements PodInfoInterface +type FakePodInfo struct { + Fake *FakeCiliumV1alpha1 + ns string +} + +var podinfoResource = v1alpha1.SchemeGroupVersion.WithResource("podinfo") + +var podinfoKind = v1alpha1.SchemeGroupVersion.WithKind("PodInfo") + +// Get takes name of the podInfo, and returns the corresponding podInfo object, and an error if there is any. +func (c *FakePodInfo) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.PodInfo, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(podinfoResource, c.ns, name), &v1alpha1.PodInfo{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.PodInfo), err +} + +// List takes label and field selectors, and returns the list of PodInfo that match those selectors. +func (c *FakePodInfo) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.PodInfoList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(podinfoResource, podinfoKind, c.ns, opts), &v1alpha1.PodInfoList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.PodInfoList{ListMeta: obj.(*v1alpha1.PodInfoList).ListMeta} + for _, item := range obj.(*v1alpha1.PodInfoList).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 podInfo. +func (c *FakePodInfo) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(podinfoResource, c.ns, opts)) + +} + +// Create takes the representation of a podInfo and creates it. Returns the server's representation of the podInfo, and an error, if there is any. +func (c *FakePodInfo) Create(ctx context.Context, podInfo *v1alpha1.PodInfo, opts v1.CreateOptions) (result *v1alpha1.PodInfo, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(podinfoResource, c.ns, podInfo), &v1alpha1.PodInfo{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.PodInfo), err +} + +// Update takes the representation of a podInfo and updates it. Returns the server's representation of the podInfo, and an error, if there is any. +func (c *FakePodInfo) Update(ctx context.Context, podInfo *v1alpha1.PodInfo, opts v1.UpdateOptions) (result *v1alpha1.PodInfo, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(podinfoResource, c.ns, podInfo), &v1alpha1.PodInfo{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.PodInfo), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakePodInfo) UpdateStatus(ctx context.Context, podInfo *v1alpha1.PodInfo, opts v1.UpdateOptions) (*v1alpha1.PodInfo, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(podinfoResource, "status", c.ns, podInfo), &v1alpha1.PodInfo{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.PodInfo), err +} + +// Delete takes name of the podInfo and deletes it. Returns an error if one occurs. +func (c *FakePodInfo) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(podinfoResource, c.ns, name, opts), &v1alpha1.PodInfo{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakePodInfo) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(podinfoResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.PodInfoList{}) + return err +} + +// Patch applies the patch and returns the patched podInfo. +func (c *FakePodInfo) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PodInfo, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(podinfoResource, c.ns, name, pt, data, subresources...), &v1alpha1.PodInfo{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.PodInfo), err +} diff --git a/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/generated_expansion.go b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/generated_expansion.go index 64d58993240..320ab473249 100644 --- a/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/generated_expansion.go +++ b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/generated_expansion.go @@ -5,6 +5,8 @@ package v1alpha1 +type PodInfoExpansion interface{} + type TracingPolicyExpansion interface{} type TracingPolicyNamespacedExpansion interface{} diff --git a/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/podinfo.go b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/podinfo.go new file mode 100644 index 00000000000..3701342df53 --- /dev/null +++ b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/podinfo.go @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Authors of Tetragon + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + "time" + + v1alpha1 "github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/v1alpha1" + scheme "github.com/cilium/tetragon/pkg/k8s/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" +) + +// PodInfoGetter has a method to return a PodInfoInterface. +// A group's client should implement this interface. +type PodInfoGetter interface { + PodInfo(namespace string) PodInfoInterface +} + +// PodInfoInterface has methods to work with PodInfo resources. +type PodInfoInterface interface { + Create(ctx context.Context, podInfo *v1alpha1.PodInfo, opts v1.CreateOptions) (*v1alpha1.PodInfo, error) + Update(ctx context.Context, podInfo *v1alpha1.PodInfo, opts v1.UpdateOptions) (*v1alpha1.PodInfo, error) + UpdateStatus(ctx context.Context, podInfo *v1alpha1.PodInfo, opts v1.UpdateOptions) (*v1alpha1.PodInfo, 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.PodInfo, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.PodInfoList, 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.PodInfo, err error) + PodInfoExpansion +} + +// podInfo implements PodInfoInterface +type podInfo struct { + client rest.Interface + ns string +} + +// newPodInfo returns a PodInfo +func newPodInfo(c *CiliumV1alpha1Client, namespace string) *podInfo { + return &podInfo{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the podInfo, and returns the corresponding podInfo object, and an error if there is any. +func (c *podInfo) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.PodInfo, err error) { + result = &v1alpha1.PodInfo{} + err = c.client.Get(). + Namespace(c.ns). + Resource("podinfo"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of PodInfo that match those selectors. +func (c *podInfo) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.PodInfoList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.PodInfoList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("podinfo"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested podInfo. +func (c *podInfo) 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(). + Namespace(c.ns). + Resource("podinfo"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a podInfo and creates it. Returns the server's representation of the podInfo, and an error, if there is any. +func (c *podInfo) Create(ctx context.Context, podInfo *v1alpha1.PodInfo, opts v1.CreateOptions) (result *v1alpha1.PodInfo, err error) { + result = &v1alpha1.PodInfo{} + err = c.client.Post(). + Namespace(c.ns). + Resource("podinfo"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(podInfo). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a podInfo and updates it. Returns the server's representation of the podInfo, and an error, if there is any. +func (c *podInfo) Update(ctx context.Context, podInfo *v1alpha1.PodInfo, opts v1.UpdateOptions) (result *v1alpha1.PodInfo, err error) { + result = &v1alpha1.PodInfo{} + err = c.client.Put(). + Namespace(c.ns). + Resource("podinfo"). + Name(podInfo.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(podInfo). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *podInfo) UpdateStatus(ctx context.Context, podInfo *v1alpha1.PodInfo, opts v1.UpdateOptions) (result *v1alpha1.PodInfo, err error) { + result = &v1alpha1.PodInfo{} + err = c.client.Put(). + Namespace(c.ns). + Resource("podinfo"). + Name(podInfo.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(podInfo). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the podInfo and deletes it. Returns an error if one occurs. +func (c *podInfo) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("podinfo"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *podInfo) 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(). + Namespace(c.ns). + Resource("podinfo"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched podInfo. +func (c *podInfo) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PodInfo, err error) { + result = &v1alpha1.PodInfo{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("podinfo"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/interface.go b/pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/interface.go index f111696ff19..7629d430363 100644 --- a/pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/interface.go +++ b/pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/interface.go @@ -11,6 +11,8 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { + // PodInfo returns a PodInfoInformer. + PodInfo() PodInfoInformer // TracingPolicies returns a TracingPolicyInformer. TracingPolicies() TracingPolicyInformer // TracingPoliciesNamespaced returns a TracingPolicyNamespacedInformer. @@ -28,6 +30,11 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } +// PodInfo returns a PodInfoInformer. +func (v *version) PodInfo() PodInfoInformer { + return &podInfoInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + // TracingPolicies returns a TracingPolicyInformer. func (v *version) TracingPolicies() TracingPolicyInformer { return &tracingPolicyInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} diff --git a/pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/podinfo.go b/pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/podinfo.go new file mode 100644 index 00000000000..ba92eeb19b7 --- /dev/null +++ b/pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/podinfo.go @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Authors of Tetragon + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + time "time" + + ciliumiov1alpha1 "github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/v1alpha1" + versioned "github.com/cilium/tetragon/pkg/k8s/client/clientset/versioned" + internalinterfaces "github.com/cilium/tetragon/pkg/k8s/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/cilium/tetragon/pkg/k8s/client/listers/cilium.io/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" +) + +// PodInfoInformer provides access to a shared informer and lister for +// PodInfo. +type PodInfoInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.PodInfoLister +} + +type podInfoInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewPodInfoInformer constructs a new informer for PodInfo 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 NewPodInfoInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredPodInfoInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredPodInfoInformer constructs a new informer for PodInfo 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 NewFilteredPodInfoInformer(client versioned.Interface, namespace string, 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.CiliumV1alpha1().PodInfo(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CiliumV1alpha1().PodInfo(namespace).Watch(context.TODO(), options) + }, + }, + &ciliumiov1alpha1.PodInfo{}, + resyncPeriod, + indexers, + ) +} + +func (f *podInfoInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredPodInfoInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *podInfoInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&ciliumiov1alpha1.PodInfo{}, f.defaultInformer) +} + +func (f *podInfoInformer) Lister() v1alpha1.PodInfoLister { + return v1alpha1.NewPodInfoLister(f.Informer().GetIndexer()) +} diff --git a/pkg/k8s/client/informers/externalversions/generic.go b/pkg/k8s/client/informers/externalversions/generic.go index 14b37fe38ff..510dfec2e71 100644 --- a/pkg/k8s/client/informers/externalversions/generic.go +++ b/pkg/k8s/client/informers/externalversions/generic.go @@ -40,6 +40,8 @@ func (f *genericInformer) Lister() cache.GenericLister { func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { // Group=cilium.io, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("podinfo"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Cilium().V1alpha1().PodInfo().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("tracingpolicies"): return &genericInformer{resource: resource.GroupResource(), informer: f.Cilium().V1alpha1().TracingPolicies().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("tracingpoliciesnamespaced"): diff --git a/pkg/k8s/client/listers/cilium.io/v1alpha1/expansion_generated.go b/pkg/k8s/client/listers/cilium.io/v1alpha1/expansion_generated.go index 4c9d71592e2..dc536f08a09 100644 --- a/pkg/k8s/client/listers/cilium.io/v1alpha1/expansion_generated.go +++ b/pkg/k8s/client/listers/cilium.io/v1alpha1/expansion_generated.go @@ -5,6 +5,14 @@ package v1alpha1 +// PodInfoListerExpansion allows custom methods to be added to +// PodInfoLister. +type PodInfoListerExpansion interface{} + +// PodInfoNamespaceListerExpansion allows custom methods to be added to +// PodInfoNamespaceLister. +type PodInfoNamespaceListerExpansion interface{} + // TracingPolicyListerExpansion allows custom methods to be added to // TracingPolicyLister. type TracingPolicyListerExpansion interface{} diff --git a/pkg/k8s/client/listers/cilium.io/v1alpha1/podinfo.go b/pkg/k8s/client/listers/cilium.io/v1alpha1/podinfo.go new file mode 100644 index 00000000000..c04d518f27a --- /dev/null +++ b/pkg/k8s/client/listers/cilium.io/v1alpha1/podinfo.go @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Authors of Tetragon + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// PodInfoLister helps list PodInfo. +// All objects returned here must be treated as read-only. +type PodInfoLister interface { + // List lists all PodInfo in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.PodInfo, err error) + // PodInfo returns an object that can list and get PodInfo. + PodInfo(namespace string) PodInfoNamespaceLister + PodInfoListerExpansion +} + +// podInfoLister implements the PodInfoLister interface. +type podInfoLister struct { + indexer cache.Indexer +} + +// NewPodInfoLister returns a new PodInfoLister. +func NewPodInfoLister(indexer cache.Indexer) PodInfoLister { + return &podInfoLister{indexer: indexer} +} + +// List lists all PodInfo in the indexer. +func (s *podInfoLister) List(selector labels.Selector) (ret []*v1alpha1.PodInfo, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.PodInfo)) + }) + return ret, err +} + +// PodInfo returns an object that can list and get PodInfo. +func (s *podInfoLister) PodInfo(namespace string) PodInfoNamespaceLister { + return podInfoNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// PodInfoNamespaceLister helps list and get PodInfo. +// All objects returned here must be treated as read-only. +type PodInfoNamespaceLister interface { + // List lists all PodInfo in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.PodInfo, err error) + // Get retrieves the PodInfo from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha1.PodInfo, error) + PodInfoNamespaceListerExpansion +} + +// podInfoNamespaceLister implements the PodInfoNamespaceLister +// interface. +type podInfoNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all PodInfo in the indexer for a given namespace. +func (s podInfoNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.PodInfo, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.PodInfo)) + }) + return ret, err +} + +// Get retrieves the PodInfo from the indexer for a given namespace and name. +func (s podInfoNamespaceLister) Get(name string) (*v1alpha1.PodInfo, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("podinfo"), name) + } + return obj.(*v1alpha1.PodInfo), nil +} diff --git a/vendor/github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/v1alpha1/types.go b/vendor/github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/v1alpha1/types.go index e3fe6271424..560f5a5f9d5 100644 --- a/vendor/github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/v1alpha1/types.go +++ b/vendor/github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/v1alpha1/types.go @@ -271,6 +271,7 @@ type PodIP struct { IP string `json:"IP,omitempty"` } +// +genclient // +kubebuilder:object:root=true // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +kubebuilder:resource:singular="podinfo",path="podinfo",scope="Namespaced",shortName={} diff --git a/vendor/github.com/cilium/tetragon/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/cilium.io_client.go b/vendor/github.com/cilium/tetragon/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/cilium.io_client.go index 92f41bf30b1..8392d8b2b17 100644 --- a/vendor/github.com/cilium/tetragon/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/cilium.io_client.go +++ b/vendor/github.com/cilium/tetragon/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/cilium.io_client.go @@ -15,6 +15,7 @@ import ( type CiliumV1alpha1Interface interface { RESTClient() rest.Interface + PodInfoGetter TracingPoliciesGetter TracingPoliciesNamespacedGetter } @@ -24,6 +25,10 @@ type CiliumV1alpha1Client struct { restClient rest.Interface } +func (c *CiliumV1alpha1Client) PodInfo(namespace string) PodInfoInterface { + return newPodInfo(c, namespace) +} + func (c *CiliumV1alpha1Client) TracingPolicies() TracingPolicyInterface { return newTracingPolicies(c) } diff --git a/vendor/github.com/cilium/tetragon/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/generated_expansion.go b/vendor/github.com/cilium/tetragon/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/generated_expansion.go index 64d58993240..320ab473249 100644 --- a/vendor/github.com/cilium/tetragon/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/generated_expansion.go +++ b/vendor/github.com/cilium/tetragon/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/generated_expansion.go @@ -5,6 +5,8 @@ package v1alpha1 +type PodInfoExpansion interface{} + type TracingPolicyExpansion interface{} type TracingPolicyNamespacedExpansion interface{} diff --git a/vendor/github.com/cilium/tetragon/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/podinfo.go b/vendor/github.com/cilium/tetragon/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/podinfo.go new file mode 100644 index 00000000000..3701342df53 --- /dev/null +++ b/vendor/github.com/cilium/tetragon/pkg/k8s/client/clientset/versioned/typed/cilium.io/v1alpha1/podinfo.go @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Authors of Tetragon + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + "time" + + v1alpha1 "github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/v1alpha1" + scheme "github.com/cilium/tetragon/pkg/k8s/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" +) + +// PodInfoGetter has a method to return a PodInfoInterface. +// A group's client should implement this interface. +type PodInfoGetter interface { + PodInfo(namespace string) PodInfoInterface +} + +// PodInfoInterface has methods to work with PodInfo resources. +type PodInfoInterface interface { + Create(ctx context.Context, podInfo *v1alpha1.PodInfo, opts v1.CreateOptions) (*v1alpha1.PodInfo, error) + Update(ctx context.Context, podInfo *v1alpha1.PodInfo, opts v1.UpdateOptions) (*v1alpha1.PodInfo, error) + UpdateStatus(ctx context.Context, podInfo *v1alpha1.PodInfo, opts v1.UpdateOptions) (*v1alpha1.PodInfo, 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.PodInfo, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.PodInfoList, 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.PodInfo, err error) + PodInfoExpansion +} + +// podInfo implements PodInfoInterface +type podInfo struct { + client rest.Interface + ns string +} + +// newPodInfo returns a PodInfo +func newPodInfo(c *CiliumV1alpha1Client, namespace string) *podInfo { + return &podInfo{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the podInfo, and returns the corresponding podInfo object, and an error if there is any. +func (c *podInfo) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.PodInfo, err error) { + result = &v1alpha1.PodInfo{} + err = c.client.Get(). + Namespace(c.ns). + Resource("podinfo"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of PodInfo that match those selectors. +func (c *podInfo) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.PodInfoList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.PodInfoList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("podinfo"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested podInfo. +func (c *podInfo) 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(). + Namespace(c.ns). + Resource("podinfo"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a podInfo and creates it. Returns the server's representation of the podInfo, and an error, if there is any. +func (c *podInfo) Create(ctx context.Context, podInfo *v1alpha1.PodInfo, opts v1.CreateOptions) (result *v1alpha1.PodInfo, err error) { + result = &v1alpha1.PodInfo{} + err = c.client.Post(). + Namespace(c.ns). + Resource("podinfo"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(podInfo). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a podInfo and updates it. Returns the server's representation of the podInfo, and an error, if there is any. +func (c *podInfo) Update(ctx context.Context, podInfo *v1alpha1.PodInfo, opts v1.UpdateOptions) (result *v1alpha1.PodInfo, err error) { + result = &v1alpha1.PodInfo{} + err = c.client.Put(). + Namespace(c.ns). + Resource("podinfo"). + Name(podInfo.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(podInfo). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *podInfo) UpdateStatus(ctx context.Context, podInfo *v1alpha1.PodInfo, opts v1.UpdateOptions) (result *v1alpha1.PodInfo, err error) { + result = &v1alpha1.PodInfo{} + err = c.client.Put(). + Namespace(c.ns). + Resource("podinfo"). + Name(podInfo.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(podInfo). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the podInfo and deletes it. Returns an error if one occurs. +func (c *podInfo) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("podinfo"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *podInfo) 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(). + Namespace(c.ns). + Resource("podinfo"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched podInfo. +func (c *podInfo) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PodInfo, err error) { + result = &v1alpha1.PodInfo{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("podinfo"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/vendor/github.com/cilium/tetragon/pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/interface.go b/vendor/github.com/cilium/tetragon/pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/interface.go index f111696ff19..7629d430363 100644 --- a/vendor/github.com/cilium/tetragon/pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/interface.go +++ b/vendor/github.com/cilium/tetragon/pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/interface.go @@ -11,6 +11,8 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { + // PodInfo returns a PodInfoInformer. + PodInfo() PodInfoInformer // TracingPolicies returns a TracingPolicyInformer. TracingPolicies() TracingPolicyInformer // TracingPoliciesNamespaced returns a TracingPolicyNamespacedInformer. @@ -28,6 +30,11 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } +// PodInfo returns a PodInfoInformer. +func (v *version) PodInfo() PodInfoInformer { + return &podInfoInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + // TracingPolicies returns a TracingPolicyInformer. func (v *version) TracingPolicies() TracingPolicyInformer { return &tracingPolicyInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} diff --git a/vendor/github.com/cilium/tetragon/pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/podinfo.go b/vendor/github.com/cilium/tetragon/pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/podinfo.go new file mode 100644 index 00000000000..ba92eeb19b7 --- /dev/null +++ b/vendor/github.com/cilium/tetragon/pkg/k8s/client/informers/externalversions/cilium.io/v1alpha1/podinfo.go @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Authors of Tetragon + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + time "time" + + ciliumiov1alpha1 "github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/v1alpha1" + versioned "github.com/cilium/tetragon/pkg/k8s/client/clientset/versioned" + internalinterfaces "github.com/cilium/tetragon/pkg/k8s/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/cilium/tetragon/pkg/k8s/client/listers/cilium.io/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" +) + +// PodInfoInformer provides access to a shared informer and lister for +// PodInfo. +type PodInfoInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.PodInfoLister +} + +type podInfoInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewPodInfoInformer constructs a new informer for PodInfo 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 NewPodInfoInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredPodInfoInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredPodInfoInformer constructs a new informer for PodInfo 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 NewFilteredPodInfoInformer(client versioned.Interface, namespace string, 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.CiliumV1alpha1().PodInfo(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CiliumV1alpha1().PodInfo(namespace).Watch(context.TODO(), options) + }, + }, + &ciliumiov1alpha1.PodInfo{}, + resyncPeriod, + indexers, + ) +} + +func (f *podInfoInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredPodInfoInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *podInfoInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&ciliumiov1alpha1.PodInfo{}, f.defaultInformer) +} + +func (f *podInfoInformer) Lister() v1alpha1.PodInfoLister { + return v1alpha1.NewPodInfoLister(f.Informer().GetIndexer()) +} diff --git a/vendor/github.com/cilium/tetragon/pkg/k8s/client/informers/externalversions/generic.go b/vendor/github.com/cilium/tetragon/pkg/k8s/client/informers/externalversions/generic.go index 14b37fe38ff..510dfec2e71 100644 --- a/vendor/github.com/cilium/tetragon/pkg/k8s/client/informers/externalversions/generic.go +++ b/vendor/github.com/cilium/tetragon/pkg/k8s/client/informers/externalversions/generic.go @@ -40,6 +40,8 @@ func (f *genericInformer) Lister() cache.GenericLister { func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { // Group=cilium.io, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("podinfo"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Cilium().V1alpha1().PodInfo().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("tracingpolicies"): return &genericInformer{resource: resource.GroupResource(), informer: f.Cilium().V1alpha1().TracingPolicies().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("tracingpoliciesnamespaced"): diff --git a/vendor/github.com/cilium/tetragon/pkg/k8s/client/listers/cilium.io/v1alpha1/expansion_generated.go b/vendor/github.com/cilium/tetragon/pkg/k8s/client/listers/cilium.io/v1alpha1/expansion_generated.go index 4c9d71592e2..dc536f08a09 100644 --- a/vendor/github.com/cilium/tetragon/pkg/k8s/client/listers/cilium.io/v1alpha1/expansion_generated.go +++ b/vendor/github.com/cilium/tetragon/pkg/k8s/client/listers/cilium.io/v1alpha1/expansion_generated.go @@ -5,6 +5,14 @@ package v1alpha1 +// PodInfoListerExpansion allows custom methods to be added to +// PodInfoLister. +type PodInfoListerExpansion interface{} + +// PodInfoNamespaceListerExpansion allows custom methods to be added to +// PodInfoNamespaceLister. +type PodInfoNamespaceListerExpansion interface{} + // TracingPolicyListerExpansion allows custom methods to be added to // TracingPolicyLister. type TracingPolicyListerExpansion interface{} diff --git a/vendor/github.com/cilium/tetragon/pkg/k8s/client/listers/cilium.io/v1alpha1/podinfo.go b/vendor/github.com/cilium/tetragon/pkg/k8s/client/listers/cilium.io/v1alpha1/podinfo.go new file mode 100644 index 00000000000..c04d518f27a --- /dev/null +++ b/vendor/github.com/cilium/tetragon/pkg/k8s/client/listers/cilium.io/v1alpha1/podinfo.go @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Authors of Tetragon + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// PodInfoLister helps list PodInfo. +// All objects returned here must be treated as read-only. +type PodInfoLister interface { + // List lists all PodInfo in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.PodInfo, err error) + // PodInfo returns an object that can list and get PodInfo. + PodInfo(namespace string) PodInfoNamespaceLister + PodInfoListerExpansion +} + +// podInfoLister implements the PodInfoLister interface. +type podInfoLister struct { + indexer cache.Indexer +} + +// NewPodInfoLister returns a new PodInfoLister. +func NewPodInfoLister(indexer cache.Indexer) PodInfoLister { + return &podInfoLister{indexer: indexer} +} + +// List lists all PodInfo in the indexer. +func (s *podInfoLister) List(selector labels.Selector) (ret []*v1alpha1.PodInfo, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.PodInfo)) + }) + return ret, err +} + +// PodInfo returns an object that can list and get PodInfo. +func (s *podInfoLister) PodInfo(namespace string) PodInfoNamespaceLister { + return podInfoNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// PodInfoNamespaceLister helps list and get PodInfo. +// All objects returned here must be treated as read-only. +type PodInfoNamespaceLister interface { + // List lists all PodInfo in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.PodInfo, err error) + // Get retrieves the PodInfo from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha1.PodInfo, error) + PodInfoNamespaceListerExpansion +} + +// podInfoNamespaceLister implements the PodInfoNamespaceLister +// interface. +type podInfoNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all PodInfo in the indexer for a given namespace. +func (s podInfoNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.PodInfo, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.PodInfo)) + }) + return ret, err +} + +// Get retrieves the PodInfo from the indexer for a given namespace and name. +func (s podInfoNamespaceLister) Get(name string) (*v1alpha1.PodInfo, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("podinfo"), name) + } + return obj.(*v1alpha1.PodInfo), nil +}