for informerType, informer := range f.informers { if !f.startedInformers[informerType] { // 调用sharedIndexInformer.Run()函数 go informer.Run(stopCh) f.startedInformers[informerType] = true } } }
1.dInformer.Informer() dInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: dc.addDeployment, UpdateFunc: dc.updateDeployment, // This will enter the sync loop and no-op, because the deployment has been deleted from the store. DeleteFunc: dc.deleteDeployment, }) 2.rsInformer.Informer() rsInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: dc.addReplicaSet, UpdateFunc: dc.updateReplicaSet, DeleteFunc: dc.deleteReplicaSet, }) 3.podInformer.Informer() podInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ DeleteFunc: dc.deletePod, })
// syncDeployment will sync the deployment with the given key. // This function is not meant to be invoked concurrently with the same key. func(dc *DeploymentController)syncDeployment(key string)error { // 根据key获取namespace和name namespace, name, err := cache.SplitMetaNamespaceKey(key) // 根据namespace和name获取到队列中deployment的信息 deployment, err := dc.dLister.Deployments(namespace).Get(name)
// Deep-copy otherwise we are mutating our cache. // TODO: Deep-copy only when needed. d := deployment.DeepCopy()
everything := metav1.LabelSelector{} if reflect.DeepEqual(d.Spec.Selector, &everything) { dc.eventRecorder.Eventf(d, v1.EventTypeWarning, "SelectingAll", "This deployment is selecting all pods. A non-empty selector is required.") if d.Status.ObservedGeneration < d.Generation { d.Status.ObservedGeneration = d.Generation dc.client.AppsV1().Deployments(d.Namespace).UpdateStatus(context.TODO(), d, metav1.UpdateOptions{}) } returnnil }