github.com/docker/compose-on-kubernetes@v0.5.0/api/client/informers/compose/v1alpha3/stack.go (about)

     1  package v1alpha3
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/docker/compose-on-kubernetes/api/client/clientset"
     7  	"github.com/docker/compose-on-kubernetes/api/client/informers/internalinterfaces"
     8  	"github.com/docker/compose-on-kubernetes/api/client/listers/compose/v1alpha3"
     9  	compose_v1alpha3 "github.com/docker/compose-on-kubernetes/api/compose/v1alpha3"
    10  	"k8s.io/apimachinery/pkg/apis/meta/v1"
    11  	"k8s.io/apimachinery/pkg/runtime"
    12  	"k8s.io/apimachinery/pkg/watch"
    13  	"k8s.io/client-go/tools/cache"
    14  )
    15  
    16  // StackInformer provides access to a shared informer and lister for
    17  // Stacks.
    18  type StackInformer interface {
    19  	Informer() cache.SharedIndexInformer
    20  	Lister() v1alpha3.StackLister
    21  }
    22  
    23  type stackInformer struct {
    24  	factory internalinterfaces.SharedInformerFactory
    25  }
    26  
    27  func newStackInformer(client clientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
    28  	sharedIndexInformer := cache.NewSharedIndexInformer(
    29  		&cache.ListWatch{
    30  			ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
    31  				return client.ComposeV1alpha3().Stacks(v1.NamespaceAll).List(options)
    32  			},
    33  			WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
    34  				return client.ComposeV1alpha3().Stacks(v1.NamespaceAll).Watch(options)
    35  			},
    36  		},
    37  		&compose_v1alpha3.Stack{},
    38  		resyncPeriod,
    39  		cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
    40  	)
    41  
    42  	return sharedIndexInformer
    43  }
    44  
    45  func (f *stackInformer) Informer() cache.SharedIndexInformer {
    46  	return f.factory.InformerFor(&compose_v1alpha3.Stack{}, newStackInformer)
    47  }
    48  
    49  func (f *stackInformer) Lister() v1alpha3.StackLister {
    50  	return v1alpha3.NewStackLister(f.Informer().GetIndexer())
    51  }
    52  
    53  // NewFilteredStackInformer creates a stack informer with specific list options
    54  func NewFilteredStackInformer(client clientset.Interface, resyncPeriod time.Duration, tweakListOptions func(*v1.ListOptions)) cache.SharedIndexInformer {
    55  	return cache.NewSharedIndexInformer(
    56  		&cache.ListWatch{
    57  			ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
    58  				if tweakListOptions != nil {
    59  					tweakListOptions(&options)
    60  				}
    61  				return client.ComposeV1alpha3().Stacks(v1.NamespaceAll).List(options)
    62  			},
    63  			WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
    64  				if tweakListOptions != nil {
    65  					tweakListOptions(&options)
    66  				}
    67  				return client.ComposeV1alpha3().Stacks(v1.NamespaceAll).Watch(options)
    68  			},
    69  		},
    70  		&compose_v1alpha3.Stack{},
    71  		resyncPeriod,
    72  		cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
    73  	)
    74  }