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