Skip to content

Adding string methods for the sources. #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions pkg/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ func (ks *Kind) Start(handler handler.EventHandler, queue workqueue.RateLimiting
return nil
}

func (ks *Kind) String() string {
if ks.Type != nil && ks.Type.GetObjectKind() != nil {
return fmt.Sprintf("kind source: %v", ks.Type.GetObjectKind().GroupVersionKind().String())
}
return fmt.Sprintf("kind source: unknown GVK")
}

var _ inject.Cache = &Kind{}

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

func (cs *Channel) String() string {
return fmt.Sprintf("channel source: %p", cs)
}

var _ inject.Stoppable = &Channel{}

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

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

// Informer should have been specified by the user.
if ks.Informer == nil {
if is.Informer == nil {
return fmt.Errorf("must specify Informer.Informer")
}

ks.Informer.AddEventHandler(internal.EventHandler{Queue: queue, EventHandler: handler, Predicates: prct})
is.Informer.AddEventHandler(internal.EventHandler{Queue: queue, EventHandler: handler, Predicates: prct})
return nil
}

func (is *Informer) String() string {
return fmt.Sprintf("informer source: %p", is.Informer)
}

// Func is a function that implements Source
type Func func(handler.EventHandler, workqueue.RateLimitingInterface, ...predicate.Predicate) error

Expand All @@ -260,3 +275,7 @@ func (f Func) Start(evt handler.EventHandler, queue workqueue.RateLimitingInterf
pr ...predicate.Predicate) error {
return f(evt, queue, pr...)
}

func (f Func) String() string {
return fmt.Sprintf("func source: %p", f)
}