// NewController returns a new wso2am controller
NewController returns a new wso2am controller
// NewController returns a new wso2am controller
func NewController(
	kubeclientset kubernetes.Interface,
	sampleclientset clientset.Interface,
	deploymentInformer appsinformers.DeploymentInformer,
	serviceInformer coreinformers.ServiceInformer,
	apimanagerInformer informers.ApimanagerInformer) *Controller {
	utilruntime.Must(samplescheme.AddToScheme(scheme.Scheme))
	klog.V(4).Info("Creating event broadcaster")
	eventBroadcaster := record.NewBroadcaster()
	eventBroadcaster.StartLogging(klog.Infof)
	eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeclientset.CoreV1().Events("")})
	recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName})
	controller := &Controller{
		kubeclientset:     kubeclientset,
		sampleclientset:   sampleclientset,
		deploymentsLister: deploymentInformer.Lister(),
		deploymentsSynced: deploymentInformer.Informer().HasSynced,
		servicesLister:    serviceInformer.Lister(),
		servicesSynced:    serviceInformer.Informer().HasSynced,
		apimanagerslister: apimanagerInformer.Lister(),
		apimanagersSynced: apimanagerInformer.Informer().HasSynced,
		workqueue:         workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Apimanagers"),
		recorder:          recorder,
	}
	klog.Info("Setting up event handlers")
	apimanagerInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc: controller.enqueueApimanager,
		UpdateFunc: func(old, new interface{}) {
			controller.enqueueApimanager(new)
		},
	})
	deploymentInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc: controller.handleObject,
		UpdateFunc: func(old, new interface{}) {
			newDepl := new.(*appsv1.Deployment)
			oldDepl := old.(*appsv1.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{}) {
			newServ := new.(*corev1.Service)
			oldServ := old.(*corev1.Service)
			if newServ.ResourceVersion == oldServ.ResourceVersion {
				return
			}
			controller.handleObject(new)
		},
		DeleteFunc: controller.handleObject,
	})
	return controller
}
func NewController ( kubeclientset kubernetes . Interface , sampleclientset clientset . Interface , deploymentInformer appsinformers . DeploymentInformer , serviceInformer coreinformers . ServiceInformer , apimanagerInformer informers . ApimanagerInformer ) * Controller { utilruntime . Must ( samplescheme . AddToScheme ( scheme . Scheme ) ) klog . V ( 4 ) . Info ( " " ) eventBroadcaster := record . NewBroadcaster ( ) eventBroadcaster . StartLogging ( klog . Infof ) eventBroadcaster . StartRecordingToSink ( & typedcorev1 . EventSinkImpl { Interface : kubeclientset . CoreV1 ( ) . Events ( " " ) } ) recorder := eventBroadcaster . NewRecorder ( scheme . Scheme , corev1 . EventSource { Component : controllerAgentName } ) controller := & Controller { kubeclientset : kubeclientset , sampleclientset : sampleclientset , deploymentsLister : deploymentInformer . Lister ( ) , deploymentsSynced : deploymentInformer . Informer ( ) . HasSynced , servicesLister : serviceInformer . Lister ( ) , servicesSynced : serviceInformer . Informer ( ) . HasSynced , apimanagerslister : apimanagerInformer . Lister ( ) , apimanagersSynced : apimanagerInformer . Informer ( ) . HasSynced , workqueue : workqueue . NewNamedRateLimitingQueue ( workqueue . DefaultControllerRateLimiter ( ) , " " ) , recorder : recorder , } klog . Info ( " " ) apimanagerInformer . Informer ( ) . AddEventHandler ( cache . ResourceEventHandlerFuncs { AddFunc : controller . enqueueApimanager , UpdateFunc : func ( old , new interface { } ) { controller . enqueueApimanager ( new ) } , } ) deploymentInformer . Informer ( ) . AddEventHandler ( cache . ResourceEventHandlerFuncs { AddFunc : controller . handleObject , UpdateFunc : func ( old , new interface { } ) { newDepl := new . ( * appsv1 . Deployment ) oldDepl := old . ( * appsv1 . 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 { } ) { newServ := new . ( * corev1 . Service ) oldServ := old . ( * corev1 . Service ) if newServ . ResourceVersion == oldServ . ResourceVersion { return } controller . handleObject ( new ) } , DeleteFunc : controller . handleObject , } ) return controller }
NewController returns a new wso2am controller
NewController returns a new wso2am controller
// Create event broadcaster. // Add apim-controller types to the default Kubernetes Scheme so Events can be logged for apim-controller types. // Set up an event handler for when Apimanager resources change // Set up an event handler for when Deployment resources change. This handler will lookup the owner of the given // Deployment, and if it is owned by a Apimanager resource will enqueue that Apimanager resource for processing. // This way, we don't need to implement custom logic for handling Deployment 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. // Two different versions of the same Deployment will always have different RVs. // Periodic resync will send update events for all known Services. // Two different versions of the same Service will always have different RVs.