func (p *PodWatcher) Run(ctx context.Context) {
	informer := cache.NewSharedIndexInformer(
		cache.NewListWatchFromClient(p.client.CoreV1().RESTClient(), "pods", p.namespace, fields.Everything()),
		&v1.Pod{},
		0,  
		cache.Indexers{},
	)
	informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc:    p.add,
		DeleteFunc: p.del,
	})
	go informer.Run(ctx.Done())
	if !cache.WaitForCacheSync(ctx.Done(), informer.HasSynced) {
		log.Errorf("Timed out waiting for caches to sync")
		return
	}
	log.Info("Synced Pod watcher")
}
Run setups up a shared informer for listing and watching changes to pods and
starts listening for events.
package main
import (
	"context"
	"strings"
	log "github.com/sirupsen/logrus"
	"k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/fields"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/tools/cache"
)
type PodEvent struct {
	Role      string
	Name      string
	Namespace string
	Deletion  bool
}
type PodWatcher struct {
	client    kubernetes.Interface
	podEvents chan<- *PodEvent
	namespace string
}
func NewPodWatcher(client kubernetes.Interface, namespace string, podEvents chan<- *PodEvent) *PodWatcher {
	return &PodWatcher{
		client:    client,
		namespace: namespace,
		podEvents: podEvents,
	}
}