Skip to content

Commit

Permalink
controllers: ensure all sources implement fmt.Stringer (#6481)
Browse files Browse the repository at this point in the history
prevents race conditions that cause a panic

for more info, see
kubernetes-sigs/controller-runtime#3057

Signed-off-by: Nick Santos <nick.santos@docker.com>
  • Loading branch information
nicks authored Jan 3, 2025
1 parent 0d4e855 commit 03b64de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/controllers/core/podlogstream/podsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type podWatch struct {
}

var _ source.Source = &PodSource{}
var _ fmt.Stringer = &PodSource{}

func NewPodSource(ctx context.Context, kClient k8s.Client, scheme *runtime.Scheme, clock clockwork.Clock) *PodSource {
return &PodSource{
Expand All @@ -59,6 +60,10 @@ func NewPodSource(ctx context.Context, kClient k8s.Client, scheme *runtime.Schem
}
}

func (s *PodSource) String() string {
return "pod-source"
}

func (s *PodSource) Start(ctx context.Context, q workqueue.TypedRateLimitingInterface[reconcile.Request]) error {
s.mu.Lock()
defer s.mu.Unlock()
Expand Down
6 changes: 6 additions & 0 deletions internal/controllers/indexer/requeuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package indexer

import (
"context"
"fmt"
"sync"
"time"

Expand All @@ -18,11 +19,16 @@ type Requeuer struct {
}

var _ source.Source = &Requeuer{}
var _ fmt.Stringer = &Requeuer{}

func NewRequeuer() *Requeuer {
return &Requeuer{}
}

func (s *Requeuer) String() string {
return "requeuer"
}

func (s *Requeuer) Start(ctx context.Context, q workqueue.TypedRateLimitingInterface[reconcile.Request]) error {
s.mu.Lock()
defer s.mu.Unlock()
Expand Down

0 comments on commit 03b64de

Please sign in to comment.