...

Source file src/k8s.io/client-go/informers/core/v1/pod.go

Documentation: k8s.io/client-go/informers/core/v1

     1  /*
     2  Copyright The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // Code generated by informer-gen. DO NOT EDIT.
    18  
    19  package v1
    20  
    21  import (
    22  	"context"
    23  	time "time"
    24  
    25  	corev1 "k8s.io/api/core/v1"
    26  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    27  	runtime "k8s.io/apimachinery/pkg/runtime"
    28  	watch "k8s.io/apimachinery/pkg/watch"
    29  	internalinterfaces "k8s.io/client-go/informers/internalinterfaces"
    30  	kubernetes "k8s.io/client-go/kubernetes"
    31  	v1 "k8s.io/client-go/listers/core/v1"
    32  	cache "k8s.io/client-go/tools/cache"
    33  )
    34  
    35  // PodInformer provides access to a shared informer and lister for
    36  // Pods.
    37  type PodInformer interface {
    38  	Informer() cache.SharedIndexInformer
    39  	Lister() v1.PodLister
    40  }
    41  
    42  type podInformer struct {
    43  	factory          internalinterfaces.SharedInformerFactory
    44  	tweakListOptions internalinterfaces.TweakListOptionsFunc
    45  	namespace        string
    46  }
    47  
    48  // NewPodInformer constructs a new informer for Pod type.
    49  // Always prefer using an informer factory to get a shared informer instead of getting an independent
    50  // one. This reduces memory footprint and number of connections to the server.
    51  func NewPodInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
    52  	return NewFilteredPodInformer(client, namespace, resyncPeriod, indexers, nil)
    53  }
    54  
    55  // NewFilteredPodInformer constructs a new informer for Pod type.
    56  // Always prefer using an informer factory to get a shared informer instead of getting an independent
    57  // one. This reduces memory footprint and number of connections to the server.
    58  func NewFilteredPodInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
    59  	return cache.NewSharedIndexInformer(
    60  		&cache.ListWatch{
    61  			ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
    62  				if tweakListOptions != nil {
    63  					tweakListOptions(&options)
    64  				}
    65  				return client.CoreV1().Pods(namespace).List(context.TODO(), options)
    66  			},
    67  			WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
    68  				if tweakListOptions != nil {
    69  					tweakListOptions(&options)
    70  				}
    71  				return client.CoreV1().Pods(namespace).Watch(context.TODO(), options)
    72  			},
    73  		},
    74  		&corev1.Pod{},
    75  		resyncPeriod,
    76  		indexers,
    77  	)
    78  }
    79  
    80  func (f *podInformer) defaultInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
    81  	return NewFilteredPodInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
    82  }
    83  
    84  func (f *podInformer) Informer() cache.SharedIndexInformer {
    85  	return f.factory.InformerFor(&corev1.Pod{}, f.defaultInformer)
    86  }
    87  
    88  func (f *podInformer) Lister() v1.PodLister {
    89  	return v1.NewPodLister(f.Informer().GetIndexer())
    90  }
    91  

View as plain text