From 339ecd3ba01b97459fd8a790ba4026a2167679bd Mon Sep 17 00:00:00 2001 From: Vishal Choudhary Date: Sun, 7 Jul 2024 20:42:08 +0530 Subject: [PATCH] fix: simplify watch Signed-off-by: Vishal Choudhary --- pkg/api/cephr.go | 47 ++++++++++++++++++++++++----------------------- pkg/api/cpolr.go | 47 ++++++++++++++++++++++++----------------------- pkg/api/ephr.go | 47 ++++++++++++++++++++++++----------------------- pkg/api/polr.go | 47 ++++++++++++++++++++++++----------------------- 4 files changed, 96 insertions(+), 92 deletions(-) diff --git a/pkg/api/cephr.go b/pkg/api/cephr.go index 248cb77..64fd839 100644 --- a/pkg/api/cephr.go +++ b/pkg/api/cephr.go @@ -274,29 +274,30 @@ func (c *cephrStore) DeleteCollection(ctx context.Context, deleteValidation rest func (c *cephrStore) Watch(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { klog.Infof("watching cluster ephemeral reports rv=%s", options.ResourceVersion) - switch options.ResourceVersion { - case "", "0": - return c.broadcaster.Watch() - default: - break - } - items, err := c.List(ctx, options) - if err != nil { - return nil, err - } - list, ok := items.(*reportsv1.ClusterEphemeralReportList) - if !ok { - return nil, fmt.Errorf("failed to convert runtime object into cluster ephemeral report list") - } - events := make([]watch.Event, len(list.Items)) - for i, pol := range list.Items { - report := pol.DeepCopy() - events[i] = watch.Event{ - Type: watch.Added, - Object: report, - } - } - return c.broadcaster.WatchWithPrefix(events) + return c.broadcaster.Watch() + // switch options.ResourceVersion { + // case "", "0": + // return c.broadcaster.Watch() + // default: + // break + // } + // items, err := c.List(ctx, options) + // if err != nil { + // return nil, err + // } + // list, ok := items.(*reportsv1.ClusterEphemeralReportList) + // if !ok { + // return nil, fmt.Errorf("failed to convert runtime object into cluster ephemeral report list") + // } + // events := make([]watch.Event, len(list.Items)) + // for i, pol := range list.Items { + // report := pol.DeepCopy() + // events[i] = watch.Event{ + // Type: watch.Added, + // Object: report, + // } + // } + // return c.broadcaster.WatchWithPrefix(events) } func (c *cephrStore) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1beta1.Table, error) { diff --git a/pkg/api/cpolr.go b/pkg/api/cpolr.go index ad3ff02..624fac7 100644 --- a/pkg/api/cpolr.go +++ b/pkg/api/cpolr.go @@ -273,29 +273,30 @@ func (c *cpolrStore) DeleteCollection(ctx context.Context, deleteValidation rest func (c *cpolrStore) Watch(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { klog.Infof("watching cluster policy reports rv=%s", options.ResourceVersion) - switch options.ResourceVersion { - case "", "0": - return c.broadcaster.Watch() - default: - break - } - items, err := c.List(ctx, options) - if err != nil { - return nil, err - } - list, ok := items.(*v1alpha2.ClusterPolicyReportList) - if !ok { - return nil, fmt.Errorf("failed to convert runtime object into cluster policy report list") - } - events := make([]watch.Event, len(list.Items)) - for i, pol := range list.Items { - report := pol.DeepCopy() - events[i] = watch.Event{ - Type: watch.Added, - Object: report, - } - } - return c.broadcaster.WatchWithPrefix(events) + return c.broadcaster.Watch() + // switch options.ResourceVersion { + // case "", "0": + // return c.broadcaster.Watch() + // default: + // break + // } + // items, err := c.List(ctx, options) + // if err != nil { + // return nil, err + // } + // list, ok := items.(*v1alpha2.ClusterPolicyReportList) + // if !ok { + // return nil, fmt.Errorf("failed to convert runtime object into cluster policy report list") + // } + // events := make([]watch.Event, len(list.Items)) + // for i, pol := range list.Items { + // report := pol.DeepCopy() + // events[i] = watch.Event{ + // Type: watch.Added, + // Object: report, + // } + // } + // return c.broadcaster.WatchWithPrefix(events) } func (c *cpolrStore) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1beta1.Table, error) { diff --git a/pkg/api/ephr.go b/pkg/api/ephr.go index d71fced..8e84d05 100644 --- a/pkg/api/ephr.go +++ b/pkg/api/ephr.go @@ -294,29 +294,30 @@ func (p *ephrStore) DeleteCollection(ctx context.Context, deleteValidation rest. func (p *ephrStore) Watch(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { klog.Infof("watching ephemeral reports rv=%s", options.ResourceVersion) - switch options.ResourceVersion { - case "", "0": - return p.broadcaster.Watch() - default: - break - } - items, err := p.List(ctx, options) - if err != nil { - return nil, err - } - list, ok := items.(*reportsv1.EphemeralReportList) - if !ok { - return nil, fmt.Errorf("failed to convert runtime object into ephemeral report list") - } - events := make([]watch.Event, len(list.Items)) - for i, pol := range list.Items { - report := pol.DeepCopy() - events[i] = watch.Event{ - Type: watch.Added, - Object: report, - } - } - return p.broadcaster.WatchWithPrefix(events) + return p.broadcaster.Watch() + // switch options.ResourceVersion { + // case "", "0": + // return p.broadcaster.Watch() + // default: + // break + // } + // items, err := p.List(ctx, options) + // if err != nil { + // return nil, err + // } + // list, ok := items.(*reportsv1.EphemeralReportList) + // if !ok { + // return nil, fmt.Errorf("failed to convert runtime object into ephemeral report list") + // } + // events := make([]watch.Event, len(list.Items)) + // for i, pol := range list.Items { + // report := pol.DeepCopy() + // events[i] = watch.Event{ + // Type: watch.Added, + // Object: report, + // } + // } + // return p.broadcaster.WatchWithPrefix(events) } func (p *ephrStore) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1beta1.Table, error) { diff --git a/pkg/api/polr.go b/pkg/api/polr.go index 717fec5..21f78d9 100644 --- a/pkg/api/polr.go +++ b/pkg/api/polr.go @@ -294,29 +294,30 @@ func (p *polrStore) DeleteCollection(ctx context.Context, deleteValidation rest. func (p *polrStore) Watch(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) { klog.Infof("watching policy reports rv=%s", options.ResourceVersion) - switch options.ResourceVersion { - case "", "0": - return p.broadcaster.Watch() - default: - break - } - items, err := p.List(ctx, options) - if err != nil { - return nil, err - } - list, ok := items.(*v1alpha2.PolicyReportList) - if !ok { - return nil, fmt.Errorf("failed to convert runtime object into policy report list") - } - events := make([]watch.Event, len(list.Items)) - for i, pol := range list.Items { - report := pol.DeepCopy() - events[i] = watch.Event{ - Type: watch.Added, - Object: report, - } - } - return p.broadcaster.WatchWithPrefix(events) + return p.broadcaster.Watch() + // switch options.ResourceVersion { + // case "", "0": + // return p.broadcaster.Watch() + // default: + // break + // } + // items, err := p.List(ctx, options) + // if err != nil { + // return nil, err + // } + // list, ok := items.(*v1alpha2.PolicyReportList) + // if !ok { + // return nil, fmt.Errorf("failed to convert runtime object into policy report list") + // } + // events := make([]watch.Event, len(list.Items)) + // for i, pol := range list.Items { + // report := pol.DeepCopy() + // events[i] = watch.Event{ + // Type: watch.Added, + // Object: report, + // } + // } + // return p.broadcaster.WatchWithPrefix(events) } func (p *polrStore) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1beta1.Table, error) {