Skip to content

Commit b6fdbe1

Browse files
authored
Merge pull request #170 from shawn-hurley/bugs/issue-153
Adding string methods for the sources.
2 parents ddf0390 + dcf51f8 commit b6fdbe1

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

pkg/source/source.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ func (ks *Kind) Start(handler handler.EventHandler, queue workqueue.RateLimiting
9595
return nil
9696
}
9797

98+
func (ks *Kind) String() string {
99+
if ks.Type != nil && ks.Type.GetObjectKind() != nil {
100+
return fmt.Sprintf("kind source: %v", ks.Type.GetObjectKind().GroupVersionKind().String())
101+
}
102+
return fmt.Sprintf("kind source: unknown GVK")
103+
}
104+
98105
var _ inject.Cache = &Kind{}
99106

100107
// InjectCache is internal should be called only by the Controller. InjectCache is used to inject
@@ -132,6 +139,10 @@ type Channel struct {
132139
destLock sync.Mutex
133140
}
134141

142+
func (cs *Channel) String() string {
143+
return fmt.Sprintf("channel source: %p", cs)
144+
}
145+
135146
var _ inject.Stoppable = &Channel{}
136147

137148
// InjectStopChannel is internal should be called only by the Controller.
@@ -240,18 +251,22 @@ var _ Source = &Informer{}
240251

241252
// Start is internal and should be called only by the Controller to register an EventHandler with the Informer
242253
// to enqueue reconcile.Requests.
243-
func (ks *Informer) Start(handler handler.EventHandler, queue workqueue.RateLimitingInterface,
254+
func (is *Informer) Start(handler handler.EventHandler, queue workqueue.RateLimitingInterface,
244255
prct ...predicate.Predicate) error {
245256

246257
// Informer should have been specified by the user.
247-
if ks.Informer == nil {
258+
if is.Informer == nil {
248259
return fmt.Errorf("must specify Informer.Informer")
249260
}
250261

251-
ks.Informer.AddEventHandler(internal.EventHandler{Queue: queue, EventHandler: handler, Predicates: prct})
262+
is.Informer.AddEventHandler(internal.EventHandler{Queue: queue, EventHandler: handler, Predicates: prct})
252263
return nil
253264
}
254265

266+
func (is *Informer) String() string {
267+
return fmt.Sprintf("informer source: %p", is.Informer)
268+
}
269+
255270
// Func is a function that implements Source
256271
type Func func(handler.EventHandler, workqueue.RateLimitingInterface, ...predicate.Predicate) error
257272

@@ -260,3 +275,7 @@ func (f Func) Start(evt handler.EventHandler, queue workqueue.RateLimitingInterf
260275
pr ...predicate.Predicate) error {
261276
return f(evt, queue, pr...)
262277
}
278+
279+
func (f Func) String() string {
280+
return fmt.Sprintf("func source: %p", f)
281+
}

0 commit comments

Comments
 (0)