Custom Controller 之 Informer(二)

In Edit

1. 概述

2. GenericInformer

informers/generic.go:58

type GenericInformer interface {
   Informer() cache.SharedIndexInformer
   Lister() cache.GenericLister
}

type genericInformer struct {
   informer cache.SharedIndexInformer
   resource schema.GroupResource
}

2.1. SharedIndexInformer

2.2. GenericLister

3. SharedInformerFactory

informers/factory.go:185

type SharedInformerFactory interface {
   internalinterfaces.SharedInformerFactory
   ForResource(resource schema.GroupVersionResource) (GenericInformer, error)
   WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool

   Admissionregistration() admissionregistration.Interface
   Apps() apps.Interface
   Auditregistration() auditregistration.Interface
   Autoscaling() autoscaling.Interface
   Batch() batch.Interface
   Certificates() certificates.Interface
   Coordination() coordination.Interface
   Core() core.Interface
   Events() events.Interface
   Extensions() extensions.Interface
   Networking() networking.Interface
   Policy() policy.Interface
   Rbac() rbac.Interface
   Scheduling() scheduling.Interface
   Settings() settings.Interface
   Storage() storage.Interface
}

3.1. apps.Interface

1556211911682

从 apps.Interface 一路到 DeploymentInformer

informers/apps/interface.go:29

type Interface interface {
   // V1 provides access to shared informers for resources in V1.
   V1() v1.Interface
   // V1beta1 provides access to shared informers for resources in V1beta1.
   V1beta1() v1beta1.Interface
   // V1beta2 provides access to shared informers for resources in V1beta2.
   V1beta2() v1beta2.Interface
}

3.1.1. v1.Interface

informers/apps/v1/interface.go:26

type Interface interface {
   // ControllerRevisions returns a ControllerRevisionInformer.
   ControllerRevisions() ControllerRevisionInformer
   // DaemonSets returns a DaemonSetInformer.
   DaemonSets() DaemonSetInformer
   // Deployments returns a DeploymentInformer.
   Deployments() DeploymentInformer
   // ReplicaSets returns a ReplicaSetInformer.
   ReplicaSets() ReplicaSetInformer
   // StatefulSets returns a StatefulSetInformer.
   StatefulSets() StatefulSetInformer
}

3.1.2. DeploymentInformer

informers/apps/v1/deployment.go:36

type DeploymentInformer interface {
   Informer() cache.SharedIndexInformer
   Lister() v1.DeploymentLister
}

deploymentInformer

informers/apps/v1/deployment.go:41

type deploymentInformer struct {
   factory          internalinterfaces.SharedInformerFactory
   tweakListOptions internalinterfaces.TweakListOptionsFunc
   namespace        string
}

informers/apps/v1/deployment.go:79

func (f *deploymentInformer) defaultInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
    return NewFilteredDeploymentInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
}

func (f *deploymentInformer) Informer() cache.SharedIndexInformer {
   return f.factory.InformerFor(&appsv1.Deployment{}, f.defaultInformer)
}

func (f *deploymentInformer) Lister() v1.DeploymentLister {
   return v1.NewDeploymentLister(f.Informer().GetIndexer())
}

3.2. sharedInformerFactory

informers/factory.go:53

type sharedInformerFactory struct {
   client           kubernetes.Interface
   namespace        string
   tweakListOptions internalinterfaces.TweakListOptionsFunc
   lock             sync.Mutex
   defaultResync    time.Duration
   customResync     map[reflect.Type]time.Duration

   informers map[reflect.Type]cache.SharedIndexInformer
   // startedInformers is used for tracking which informers have been started.
   // This allows Start() to be called multiple times safely.
   startedInformers map[reflect.Type]bool
}

3.2.1. kubernetes.Interface

1556213817097

3.2.2. Clientset

type Clientset struct {
   *discovery.DiscoveryClient
   admissionregistrationV1alpha1 *admissionregistrationv1alpha1.AdmissionregistrationV1alpha1Client
   admissionregistrationV1beta1  *admissionregistrationv1beta1.AdmissionregistrationV1beta1Client
   appsV1beta1                   *appsv1beta1.AppsV1beta1Client
   appsV1beta2                   *appsv1beta2.AppsV1beta2Client
   appsV1                        *appsv1.AppsV1Client
   // ……
   coreV1                        *corev1.CoreV1Client
   eventsV1beta1                 *eventsv1beta1.EventsV1beta1Client
   extensionsV1beta1             *extensionsv1beta1.ExtensionsV1beta1Client
   // ……
}

3.2.3. appsv1.AppsV1Client

kubernetes/typed/apps/v1/apps_client.go:38

type AppsV1Client struct {
   restClient rest.Interface
}

3.2.4. rest.Interface

type Interface interface {
   GetRateLimiter() flowcontrol.RateLimiter
   Verb(verb string) *Request
   Post() *Request
   Put() *Request
   Patch(pt types.PatchType) *Request
   Get() *Request
   Delete() *Request
   APIVersion() schema.GroupVersion
}

3.2.5. RESTClient

rest/client.go:61

type RESTClient struct {
   // base is the root URL for all invocations of the client
   base *url.URL
   versionedAPIPath string
   contentConfig ContentConfig
   serializers Serializers
   createBackoffMgr func() BackoffManager
   Throttle flowcontrol.RateLimiter
   Client *http.Client
}
Copyright © farmer.hutao@outlook.com 2019 all right reserved,powered by Gitbook该文件修订时间: 2019-06-20 14:58:28

results matching ""

    No results matching ""

    results matching ""

      No results matching ""