func NewController(
	kubeclientset kubernetes.Interface,
	sampleclientset clientset.Interface,
	kubeInformerFactory kubeinformers.SharedInformerFactory,
	sampleInformerFactory informers.SharedInformerFactory,
) *Controller {

	// obtain references to shared index informers for the Deployment and Foo
	// types.
	podInformer := kubeInformerFactory.Core().V1().Pods()
	serviceInformer := kubeInformerFactory.Core().V1().Services()
	endpointInformer := kubeInformerFactory.Core().V1().Endpoints()
	configMapInformer := kubeInformerFactory.Core().V1().ConfigMaps()
	statefulSetInformer := kubeInformerFactory.Apps().V1beta2().StatefulSets()
	deploymentInformer := kubeInformerFactory.Apps().V1beta2().Deployments()

	fooInformer := sampleInformerFactory.Example().V1alpha1().Rabbitmqs()

	// Create event broadcaster
	// Add sample-controller types to the default Kubernetes Scheme so Events can be
	// logged for sample-controller types.
	samplescheme.AddToScheme(scheme.Scheme)
	glog.V(4).Info("Creating event broadcaster")
	eventBroadcaster := record.NewBroadcaster()
	eventBroadcaster.StartLogging(glog.Infof)
	eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeclientset.CoreV1().Events("")})
	recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName})

	cacheSyncs := []cache.InformerSynced{
		podInformer.Informer().HasSynced,
		deploymentInformer.Informer().HasSynced,
		serviceInformer.Informer().HasSynced,
		endpointInformer.Informer().HasSynced,
		configMapInformer.Informer().HasSynced,
		statefulSetInformer.Informer().HasSynced,
		fooInformer.Informer().HasSynced,
	}

	controller := &Controller{
		kubeclientset:     kubeclientset,
		sampleclientset:   sampleclientset,
		podLister:         podInformer.Lister(),
		serviceLister:     serviceInformer.Lister(),
		endpointsLister:   endpointInformer.Lister(),
		configMapLister:   configMapInformer.Lister(),
		deploymentsLister: deploymentInformer.Lister(),
		statefulSetLister: statefulSetInformer.Lister(),
		foosLister:        fooInformer.Lister(),
		cacheSyncs:        cacheSyncs,
		recorder:          recorder,
		workqueue:         workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), samplev1alpha1.CustomResourceKind+"s"),
		logger:            logrus.WithField("pkg", "controller"),
		//Config:            cfg,
		//redises: make(map[string]*redis.Redis),
	}

	glog.Info("Setting up event handlers")
	// Set up an event handler for when Foo resources change
	fooInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc: controller.enqueueFoo,
		UpdateFunc: func(old, new interface{}) {
			controller.enqueueFoo(new)
		},
	})

	// Set up an event handler for when Deployment/StatefulSet resources change. This
	// handler will lookup the owner of the given Deployment/StatefulSet, and if it is
	// owned by a Foo resource will enqueue that Foo resource for
	// processing. This way, we don't need to implement custom logic for
	// handling Deployment/StatefulSet resources. More info on this pattern:
	// https://github.com/kubernetes/community/blob/8cafef897a22026d42f5e5bb3f104febe7e29830/contributors/devel/controllers.md
	statefulSetInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc: controller.handleObject,
		UpdateFunc: func(old, new interface{}) {
			newSts := new.(*appsv1beta2.StatefulSet)
			oldSts := old.(*appsv1beta2.StatefulSet)
			if newSts.ResourceVersion == oldSts.ResourceVersion {
				// Periodic resync will send update events for all known Deployments/StatefulSets.
				// Two different versions of the same Deployment/StatefulSet will always have different RVs.
				return
			}
			controller.handleObject(new)
		},
		DeleteFunc: controller.handleObject,
	})

	//	deploymentInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
	//		AddFunc: controller.handleObject,
	//		UpdateFunc: func(old, new interface{}) {
	//			newDepl := new.(*appsv1beta2.Deployment)
	//			oldDepl := old.(*appsv1beta2.Deployment)
	//			if newDepl.ResourceVersion == oldDepl.ResourceVersion {
	//				return
	//			}
	//			controller.handleObject(new)
	//		},
	//		DeleteFunc: controller.handleObject,
	//	})

	serviceInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc: controller.handleObject,
		UpdateFunc: func(old, new interface{}) {
			newSvc := new.(*corev1.Service)
			oldSvc := old.(*corev1.Service)
			if newSvc.ResourceVersion == oldSvc.ResourceVersion {
				return
			}
			controller.handleObject(new)
		},
		DeleteFunc: controller.handleObject,
	})

	return controller

}
//type controllerConfigFunc func(*Controller)
type controllerConfigFunc func(*Controller)
// type controllerConfigFunc func ( * Controller )
func NewController(
	kubeclientset kubernetes.Interface,
	sampleclientset clientset.Interface,
	kubeInformerFactory kubeinformers.SharedInformerFactory,
	sampleInformerFactory informers.SharedInformerFactory,
) *Controller {
	podInformer := kubeInformerFactory.Core().V1().Pods()
	serviceInformer := kubeInformerFactory.Core().V1().Services()
	endpointInformer := kubeInformerFactory.Core().V1().Endpoints()
	configMapInformer := kubeInformerFactory.Core().V1().ConfigMaps()
	statefulSetInformer := kubeInformerFactory.Apps().V1beta2().StatefulSets()
	deploymentInformer := kubeInformerFactory.Apps().V1beta2().Deployments()
	fooInformer := sampleInformerFactory.Example().V1alpha1().Rabbitmqs()
	samplescheme.AddToScheme(scheme.Scheme)
	glog.V(4).Info("Creating event broadcaster")
	eventBroadcaster := record.NewBroadcaster()
	eventBroadcaster.StartLogging(glog.Infof)
	eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeclientset.CoreV1().Events("")})
	recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName})
	cacheSyncs := []cache.InformerSynced{
		podInformer.Informer().HasSynced,
		deploymentInformer.Informer().HasSynced,
		serviceInformer.Informer().HasSynced,
		endpointInformer.Informer().HasSynced,
		configMapInformer.Informer().HasSynced,
		statefulSetInformer.Informer().HasSynced,
		fooInformer.Informer().HasSynced,
	}
	controller := &Controller{
		kubeclientset:     kubeclientset,
		sampleclientset:   sampleclientset,
		podLister:         podInformer.Lister(),
		serviceLister:     serviceInformer.Lister(),
		endpointsLister:   endpointInformer.Lister(),
		configMapLister:   configMapInformer.Lister(),
		deploymentsLister: deploymentInformer.Lister(),
		statefulSetLister: statefulSetInformer.Lister(),
		foosLister:        fooInformer.Lister(),
		cacheSyncs:        cacheSyncs,
		recorder:          recorder,
		workqueue:         workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), samplev1alpha1.CustomResourceKind+"s"),
		logger:            logrus.WithField("pkg", "controller"),
	}
	glog.Info("Setting up event handlers")
	fooInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc: controller.enqueueFoo,
		UpdateFunc: func(old, new interface{}) {
			controller.enqueueFoo(new)
		},
	})
	statefulSetInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc: controller.handleObject,
		UpdateFunc: func(old, new interface{}) {
			newSts := new.(*appsv1beta2.StatefulSet)
			oldSts := old.(*appsv1beta2.StatefulSet)
			if newSts.ResourceVersion == oldSts.ResourceVersion {
				return
			}
			controller.handleObject(new)
		},
		DeleteFunc: controller.handleObject,
	})
	serviceInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc: controller.handleObject,
		UpdateFunc: func(old, new interface{}) {
			newSvc := new.(*corev1.Service)
			oldSvc := old.(*corev1.Service)
			if newSvc.ResourceVersion == oldSvc.ResourceVersion {
				return
			}
			controller.handleObject(new)
		},
		DeleteFunc: controller.handleObject,
	})
	return controller
}
func NewController ( kubeclientset kubernetes . Interface , sampleclientset clientset . Interface , kubeInformerFactory kubeinformers . SharedInformerFactory , sampleInformerFactory informers . SharedInformerFactory , ) * Controller { podInformer := kubeInformerFactory . Core ( ) . V1 ( ) . Pods ( ) serviceInformer := kubeInformerFactory . Core ( ) . V1 ( ) . Services ( ) endpointInformer := kubeInformerFactory . Core ( ) . V1 ( ) . Endpoints ( ) configMapInformer := kubeInformerFactory . Core ( ) . V1 ( ) . ConfigMaps ( ) statefulSetInformer := kubeInformerFactory . Apps ( ) . V1beta2 ( ) . StatefulSets ( ) deploymentInformer := kubeInformerFactory . Apps ( ) . V1beta2 ( ) . Deployments ( ) fooInformer := sampleInformerFactory . Example ( ) . V1alpha1 ( ) . Rabbitmqs ( ) samplescheme . AddToScheme ( scheme . Scheme ) glog . V ( 4 ) . Info ( " " ) eventBroadcaster := record . NewBroadcaster ( ) eventBroadcaster . StartLogging ( glog . Infof ) eventBroadcaster . StartRecordingToSink ( & typedcorev1 . EventSinkImpl { Interface : kubeclientset . CoreV1 ( ) . Events ( " " ) } ) recorder := eventBroadcaster . NewRecorder ( scheme . Scheme , corev1 . EventSource { Component : controllerAgentName } ) cacheSyncs := [ ] cache . InformerSynced { podInformer . Informer ( ) . HasSynced , deploymentInformer . Informer ( ) . HasSynced , serviceInformer . Informer ( ) . HasSynced , endpointInformer . Informer ( ) . HasSynced , configMapInformer . Informer ( ) . HasSynced , statefulSetInformer . Informer ( ) . HasSynced , fooInformer . Informer ( ) . HasSynced , } controller := & Controller { kubeclientset : kubeclientset , sampleclientset : sampleclientset , podLister : podInformer . Lister ( ) , serviceLister : serviceInformer . Lister ( ) , endpointsLister : endpointInformer . Lister ( ) , configMapLister : configMapInformer . Lister ( ) , deploymentsLister : deploymentInformer . Lister ( ) , statefulSetLister : statefulSetInformer . Lister ( ) , foosLister : fooInformer . Lister ( ) , cacheSyncs : cacheSyncs , recorder : recorder , workqueue : workqueue . NewNamedRateLimitingQueue ( workqueue . DefaultControllerRateLimiter ( ) , samplev1alpha1 . CustomResourceKind + " " ) , logger : logrus . WithField ( " " , " " ) , } glog . Info ( " " ) fooInformer . Informer ( ) . AddEventHandler ( cache . ResourceEventHandlerFuncs { AddFunc : controller . enqueueFoo , UpdateFunc : func ( old , new interface { } ) { controller . enqueueFoo ( new ) } , } ) statefulSetInformer . Informer ( ) . AddEventHandler ( cache . ResourceEventHandlerFuncs { AddFunc : controller . handleObject , UpdateFunc : func ( old , new interface { } ) { newSts := new . ( * appsv1beta2 . StatefulSet ) oldSts := old . ( * appsv1beta2 . StatefulSet ) if newSts . ResourceVersion == oldSts . ResourceVersion { return } controller . handleObject ( new ) } , DeleteFunc : controller . handleObject , } ) serviceInformer . Informer ( ) . AddEventHandler ( cache . ResourceEventHandlerFuncs { AddFunc : controller . handleObject , UpdateFunc : func ( old , new interface { } ) { newSvc := new . ( * corev1 . Service ) oldSvc := old . ( * corev1 . Service ) if newSvc . ResourceVersion == oldSvc . ResourceVersion { return } controller . handleObject ( new ) } , DeleteFunc : controller . handleObject , } ) return controller }
type controllerConfigFunc func(*Controller)
type controllerConfigFunc func ( * Controller )
// obtain references to shared index informers for the Deployment and Foo // types. // Create event broadcaster // Add sample-controller types to the default Kubernetes Scheme so Events can be // logged for sample-controller types. //Config:            cfg, //redises: make(map[string]*redis.Redis), // Set up an event handler for when Foo resources change // Set up an event handler for when Deployment/StatefulSet resources change. This // handler will lookup the owner of the given Deployment/StatefulSet, and if it is // owned by a Foo resource will enqueue that Foo resource for // processing. This way, we don't need to implement custom logic for // handling Deployment/StatefulSet resources. More info on this pattern: // https://github.com/kubernetes/community/blob/8cafef897a22026d42f5e5bb3f104febe7e29830/contributors/devel/controllers.md // Periodic resync will send update events for all known Deployments/StatefulSets. // Two different versions of the same Deployment/StatefulSet will always have different RVs. //	deploymentInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ //		AddFunc: controller.handleObject, //		UpdateFunc: func(old, new interface{}) { //			newDepl := new.(*appsv1beta2.Deployment) //			oldDepl := old.(*appsv1beta2.Deployment) //			if newDepl.ResourceVersion == oldDepl.ResourceVersion { //				return //			} //			controller.handleObject(new) //		}, //		DeleteFunc: controller.handleObject, //	})