func newSparkPodMonitor(
	kubeClient clientset.Interface,
	driverStateReportingChan chan<- driverStateUpdate,
	executorStateReportingChan chan<- executorStateUpdate) *sparkPodMonitor {
	monitor := &sparkPodMonitor{
		kubeClient:                 kubeClient,
		driverStateReportingChan:   driverStateReportingChan,
		executorStateReportingChan: executorStateReportingChan,
	}
	restClient := kubeClient.CoreV1().RESTClient()
	watchlist := cache.NewListWatchFromClient(restClient, "pods", apiv1.NamespaceAll, fields.Everything())
	sparkPodWatchList := &cache.ListWatch{
		ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
			options.LabelSelector = sparkRoleLabel
			return watchlist.List(options)
		},
		WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
			options.LabelSelector = sparkRoleLabel
			return watchlist.Watch(options)
		},
	}
	_, monitor.sparkPodController = cache.NewInformer(
		sparkPodWatchList,
		&apiv1.Pod{},
		0*time.Second,
		cache.ResourceEventHandlerFuncs{
			AddFunc:    monitor.onPodAdded,
			UpdateFunc: monitor.onPodUpdated,
			DeleteFunc: monitor.onPodDeleted,
		},
	)
	return monitor
}
newSparkPodMonitor creates a new sparkPodMonitor instance.
package controller
import (
	"time"
	"github.com/golang/glog"
	"github.com/liyinan926/spark-operator/pkg/apis/v1alpha1"
	"github.com/liyinan926/spark-operator/pkg/config"
	apiv1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/fields"
	"k8s.io/apimachinery/pkg/runtime"
	utilruntime "k8s.io/apimachinery/pkg/util/runtime"
	"k8s.io/apimachinery/pkg/watch"
	clientset "k8s.io/client-go/kubernetes"
	"k8s.io/client-go/tools/cache"
)
type sparkPodMonitor struct {
	kubeClient clientset.Interface
	sparkPodController cache.Controller
	driverStateReportingChan chan<- driverStateUpdate
	executorStateReportingChan chan<- executorStateUpdate
}
type driverStateUpdate struct {
	appID    string
	podName  string
	nodeName string
	podPhase apiv1.PodPhase
}
type executorStateUpdate struct {
	appID      string
	podName    string
	executorID string
	state      v1alpha1.ExecutorState
}