Skip to content

Commit

Permalink
Revert "fix: simplify watch"
Browse files Browse the repository at this point in the history
This reverts commit 339ecd3.
  • Loading branch information
vishal-chdhry committed Jul 7, 2024
1 parent 339ecd3 commit ca35f64
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 96 deletions.
47 changes: 23 additions & 24 deletions pkg/api/cephr.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,30 +274,29 @@ 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)
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)
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) {
Expand Down
47 changes: 23 additions & 24 deletions pkg/api/cpolr.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,30 +273,29 @@ 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)
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)
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) {
Expand Down
47 changes: 23 additions & 24 deletions pkg/api/ephr.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,30 +294,29 @@ 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)
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)
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) {
Expand Down
47 changes: 23 additions & 24 deletions pkg/api/polr.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,30 +294,29 @@ 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)
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)
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) {
Expand Down

0 comments on commit ca35f64

Please sign in to comment.