Skip to content
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

Don't block metadata startup on pod/node list #1611

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
update
Signed-off-by: Michelle Nguyen <michellenguyen@pixielabs.ai>
  • Loading branch information
aimichelle committed Jul 11, 2023
commit 333f1fd906c57063fae523cc07a20a75526db172
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sync"
"time"

log "github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
Expand All @@ -43,6 +44,7 @@ type Controller struct {
// watcher watches a k8s resource type and forwards the updates to the given update channel.
type watcher interface {
StartWatcher(chan struct{})
InitWatcher() error
}

// NewController creates a new Controller.
Expand Down Expand Up @@ -81,9 +83,16 @@ func NewControllerWithClientSet(updateCh chan *K8sResourceMessage, clientset kub

mc := &Controller{quitCh: quitCh, updateCh: updateCh, watchers: watchers}

for _, w := range mc.watchers {
go w.StartWatcher(quitCh)
}
go func() {
for _, w := range mc.watchers {
err := w.InitWatcher()
if err != nil {
// Still return the informer because the rest of the system can recover from this.
log.WithError(err).Error("Failed to run watcher init")
}
go w.StartWatcher(quitCh)
}
}()

return mc, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"context"
"time"

log "github.com/sirupsen/logrus"
apps "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -52,12 +51,6 @@ func (i *informerWatcher) send(msg *K8sResourceMessage, et watch.EventType) {

// StartWatcher starts a watcher.
func (i *informerWatcher) StartWatcher(quitCh chan struct{}) {
err := i.init()
if err != nil {
// Still return the informer because the rest of the system can recover from this.
log.WithError(err).Error("Failed to run watcher init")
}

_, _ = i.inf.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
msg := i.convert(obj)
Expand All @@ -81,6 +74,14 @@ func (i *informerWatcher) StartWatcher(quitCh chan struct{}) {
i.inf.Run(quitCh)
}

// InitWatcher initializes a watcher, for example to perform a list.
func (i *informerWatcher) InitWatcher() error {
if i.init != nil {
return i.init()
}
return nil
}

func podWatcher(resource string, ch chan *K8sResourceMessage, clientset kubernetes.Interface) *informerWatcher {
factory := informers.NewSharedInformerFactory(clientset, 12*time.Hour)

Expand Down