diff --git a/pkg/api/cephr.go b/pkg/api/cephr.go index 64fd839..248cb77 100644 --- a/pkg/api/cephr.go +++ b/pkg/api/cephr.go @@ -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) { diff --git a/pkg/api/cpolr.go b/pkg/api/cpolr.go index 624fac7..ad3ff02 100644 --- a/pkg/api/cpolr.go +++ b/pkg/api/cpolr.go @@ -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) { diff --git a/pkg/api/ephr.go b/pkg/api/ephr.go index 8e84d05..d71fced 100644 --- a/pkg/api/ephr.go +++ b/pkg/api/ephr.go @@ -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) { diff --git a/pkg/api/polr.go b/pkg/api/polr.go index 21f78d9..717fec5 100644 --- a/pkg/api/polr.go +++ b/pkg/api/polr.go @@ -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) {