Skip to content

Commit

Permalink
Fix build for controller-runtime breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jotak committed Jun 17, 2024
1 parent b5eb28c commit 5514536
Show file tree
Hide file tree
Showing 6 changed files with 489 additions and 231 deletions.
270 changes: 198 additions & 72 deletions bundle/manifests/flows.netobserv.io_flowcollectors.yaml

Large diffs are not rendered by default.

270 changes: 198 additions & 72 deletions config/crd/bases/flows.netobserv.io_flowcollectors.yaml

Large diffs are not rendered by default.

144 changes: 72 additions & 72 deletions docs/FlowCollector.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pkg/narrowcache/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (c *Client) callHandlers(ctx context.Context, key string, ev watch.Event) {
}
}

func (c *Client) GetSource(ctx context.Context, obj client.Object) (source.Source, error) {
func (c *Client) GetSource(ctx context.Context, obj client.Object, h handler.EventHandler) (source.Source, error) {
// Prepare a Source and make sure it is associated with a watch
rlog := log.FromContext(ctx).WithName("narrowcache")
rlog.WithValues("name", obj.GetName(), "namespace", obj.GetNamespace()).Info("Getting Source:")
Expand All @@ -223,7 +223,8 @@ func (c *Client) GetSource(ctx context.Context, obj client.Object) (source.Sourc
}

return &NarrowSource{
onStart: func(ctx context.Context, h handler.EventHandler, q workqueue.RateLimitingInterface) {
handler: h,
onStart: func(ctx context.Context, q workqueue.RateLimitingInterface) {
c.addHandler(key, handlerOnQueue{handler: h, queue: q})
},
}, nil
Expand Down
12 changes: 8 additions & 4 deletions pkg/narrowcache/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ package narrowcache

import (
"context"
"errors"

"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/source"
)

type NarrowSource struct {
source.Source
onStart func(ctx context.Context, h handler.EventHandler, q workqueue.RateLimitingInterface)
handler handler.EventHandler
onStart func(ctx context.Context, q workqueue.RateLimitingInterface)
}

func (s *NarrowSource) Start(ctx context.Context, h handler.EventHandler, q workqueue.RateLimitingInterface, _ ...predicate.Predicate) error {
s.onStart(ctx, h, q)
func (s *NarrowSource) Start(ctx context.Context, q workqueue.RateLimitingInterface) error {
if s.handler == nil {
return errors.New("must specify NarrowSource.handler")
}
s.onStart(ctx, q)
return nil
}
19 changes: 10 additions & 9 deletions pkg/watchers/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,9 @@ func (w *Watcher) watch(ctx context.Context, cl *narrowcache.Client, kind flowsl
// Don't register again
return nil
}
s, err := cl.GetSource(ctx, obj)
if err != nil {
return err
}
// Note that currently, watches are never removed (they can't - cf https://github.com/kubernetes-sigs/controller-runtime/issues/1884)
// This isn't a big deal here, as the number of watches that we set is very limited and not meant to grow over and over
// (unless user keeps reconfiguring cert references endlessly)
err = w.ctrl.Watch(
s,
s, err := cl.GetSource(
ctx,
obj,
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, o client.Object) []reconcile.Request {
// The watch might be registered, but inactive
k := key(kind, o.GetName(), o.GetNamespace())
Expand All @@ -104,6 +98,13 @@ func (w *Watcher) watch(ctx context.Context, cl *narrowcache.Client, kind flowsl
if err != nil {
return err
}
// Note that currently, watches are never removed (they can't - cf https://github.com/kubernetes-sigs/controller-runtime/issues/1884)
// This isn't a big deal here, as the number of watches that we set is very limited and not meant to grow over and over
// (unless user keeps reconfiguring cert references endlessly)
err = w.ctrl.Watch(s)
if err != nil {
return err
}
return nil
}

Expand Down

0 comments on commit 5514536

Please sign in to comment.