DeploymentController 对象从 NewDeploymentController 方法开始创建,我们首先看这个方法
1 // NewDeploymentController creates a new DeploymentController. 2 func NewDeploymentController(ctx context.Context, dInformer appsinformers.DeploymentInformer, rsInformer appsinformers.ReplicaSetInformer, podInformer coreinformers.PodInformer, client clientset.Interface) (*DeploymentController, error) { 3 eventBroadcaster := record.NewBroadcaster() 4 logger := klog.FromContext(ctx) 5 dc := &DeploymentController{ 6 client: client, 7 eventBroadcaster: eventBroadcaster, 8 eventRecorder: eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "deployment-controller"}), 9 queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "deployment"), 10 } 11 dc.rsControl = controller.RealRSControl{ 12 KubeClient: client, 13 Recorder: dc.eventRecorder, 14 } 15 16 dInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ 17 AddFunc: func(obj interface{}) { 18 dc.addDeployment(logger, obj) 19 }, 20 UpdateFunc: func(oldObj, newObj interface{}) { 21 dc.updateDeployment(logger, oldObj, newObj) 22 }, 23 // This will enter the sync loop and no-op, because the deployment has been deleted from the store. 24 DeleteFunc: func(obj interface{}) { 25 dc.deleteDeployment(logger, obj) 26 }, 27 }) 28 rsInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ 29 AddFunc: func(obj interface{}) { 30 dc.addReplicaSet(logger, obj) 31 }, 32 UpdateFunc: func(oldObj, newObj interface{}) { 33 dc.updateReplicaSet(logger, oldObj, newObj) 34 }, 35 DeleteFunc: func(obj interface{}) { 36 dc.deleteReplicaSet(logger, obj) 37 }, 38 }) 39 podInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ 40 DeleteFunc: func(obj interface{}) { 41 dc.deletePod(logger, obj) 42 }, 43 }) 44 45 dc.syncHandler = dc.syncDeployment 46 dc.enqueueDeployment = dc.enqueue 47 48 dc.dLister = dInformer.Lister() 49 dc.rsLister = rsInformer.Lister() 50 dc.podLister = podInformer.Lister() 51 dc.dListerSynced = dInformer.Informer().HasSynced 52 dc.rsListerSynced = rsInformer.Informer().HasSynced 53 dc.podListerSynced = podInformer.Informer().HasSynced 54 return dc, nil 55 }
标签:obj,kubernetes,DeploymentController,dc,源码,func,interface,logger,Informer From: https://www.cnblogs.com/mrpei/p/18197498