Skip to content

Commit 5514536

Browse files
committed
Fix build for controller-runtime breaking changes
Breaking changes are in: kubernetes-sigs/controller-runtime#2783
1 parent b5eb28c commit 5514536

File tree

6 files changed

+489
-231
lines changed

6 files changed

+489
-231
lines changed

bundle/manifests/flows.netobserv.io_flowcollectors.yaml

Lines changed: 198 additions & 72 deletions
Large diffs are not rendered by default.

config/crd/bases/flows.netobserv.io_flowcollectors.yaml

Lines changed: 198 additions & 72 deletions
Large diffs are not rendered by default.

docs/FlowCollector.md

Lines changed: 72 additions & 72 deletions
Large diffs are not rendered by default.

pkg/narrowcache/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func (c *Client) callHandlers(ctx context.Context, key string, ev watch.Event) {
203203
}
204204
}
205205

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

225225
return &NarrowSource{
226-
onStart: func(ctx context.Context, h handler.EventHandler, q workqueue.RateLimitingInterface) {
226+
handler: h,
227+
onStart: func(ctx context.Context, q workqueue.RateLimitingInterface) {
227228
c.addHandler(key, handlerOnQueue{handler: h, queue: q})
228229
},
229230
}, nil

pkg/narrowcache/source.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@ package narrowcache
22

33
import (
44
"context"
5+
"errors"
56

67
"k8s.io/client-go/util/workqueue"
78
"sigs.k8s.io/controller-runtime/pkg/handler"
8-
"sigs.k8s.io/controller-runtime/pkg/predicate"
99
"sigs.k8s.io/controller-runtime/pkg/source"
1010
)
1111

1212
type NarrowSource struct {
1313
source.Source
14-
onStart func(ctx context.Context, h handler.EventHandler, q workqueue.RateLimitingInterface)
14+
handler handler.EventHandler
15+
onStart func(ctx context.Context, q workqueue.RateLimitingInterface)
1516
}
1617

17-
func (s *NarrowSource) Start(ctx context.Context, h handler.EventHandler, q workqueue.RateLimitingInterface, _ ...predicate.Predicate) error {
18-
s.onStart(ctx, h, q)
18+
func (s *NarrowSource) Start(ctx context.Context, q workqueue.RateLimitingInterface) error {
19+
if s.handler == nil {
20+
return errors.New("must specify NarrowSource.handler")
21+
}
22+
s.onStart(ctx, q)
1923
return nil
2024
}

pkg/watchers/watcher.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,9 @@ func (w *Watcher) watch(ctx context.Context, cl *narrowcache.Client, kind flowsl
7979
// Don't register again
8080
return nil
8181
}
82-
s, err := cl.GetSource(ctx, obj)
83-
if err != nil {
84-
return err
85-
}
86-
// Note that currently, watches are never removed (they can't - cf https://github.com/kubernetes-sigs/controller-runtime/issues/1884)
87-
// 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
88-
// (unless user keeps reconfiguring cert references endlessly)
89-
err = w.ctrl.Watch(
90-
s,
82+
s, err := cl.GetSource(
83+
ctx,
84+
obj,
9185
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, o client.Object) []reconcile.Request {
9286
// The watch might be registered, but inactive
9387
k := key(kind, o.GetName(), o.GetNamespace())
@@ -104,6 +98,13 @@ func (w *Watcher) watch(ctx context.Context, cl *narrowcache.Client, kind flowsl
10498
if err != nil {
10599
return err
106100
}
101+
// Note that currently, watches are never removed (they can't - cf https://github.com/kubernetes-sigs/controller-runtime/issues/1884)
102+
// 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
103+
// (unless user keeps reconfiguring cert references endlessly)
104+
err = w.ctrl.Watch(s)
105+
if err != nil {
106+
return err
107+
}
107108
return nil
108109
}
109110

0 commit comments

Comments
 (0)