mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
To add service account informer
This commit is contained in:
parent
c19569f03f
commit
a745872b94
39
pkg/client/cache/listers_core.go
vendored
39
pkg/client/cache/listers_core.go
vendored
@ -204,6 +204,45 @@ func (s *StoreToReplicationControllerLister) GetPodControllers(pod *api.Pod) (co
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StoreToServiceAccountLister helps list service accounts
|
||||||
|
type StoreToServiceAccountLister struct {
|
||||||
|
Indexer Indexer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StoreToServiceAccountLister) List(selector labels.Selector) (ret []*api.ServiceAccount, err error) {
|
||||||
|
err = ListAll(s.Indexer, selector, func(m interface{}) {
|
||||||
|
ret = append(ret, m.(*api.ServiceAccount))
|
||||||
|
})
|
||||||
|
return ret, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StoreToServiceAccountLister) ServiceAccounts(namespace string) storeServiceAccountsNamespacer {
|
||||||
|
return storeServiceAccountsNamespacer{s.Indexer, namespace}
|
||||||
|
}
|
||||||
|
|
||||||
|
type storeServiceAccountsNamespacer struct {
|
||||||
|
indexer Indexer
|
||||||
|
namespace string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s storeServiceAccountsNamespacer) List(selector labels.Selector) (ret []*api.ServiceAccount, err error) {
|
||||||
|
err = ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
|
||||||
|
ret = append(ret, m.(*api.ServiceAccount))
|
||||||
|
})
|
||||||
|
return ret, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s storeServiceAccountsNamespacer) Get(name string) (*api.ServiceAccount, error) {
|
||||||
|
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
return nil, errors.NewNotFound(api.Resource("serviceaccount"), name)
|
||||||
|
}
|
||||||
|
return obj.(*api.ServiceAccount), nil
|
||||||
|
}
|
||||||
|
|
||||||
// StoreToLimitRangeLister helps list limit ranges
|
// StoreToLimitRangeLister helps list limit ranges
|
||||||
type StoreToLimitRangeLister struct {
|
type StoreToLimitRangeLister struct {
|
||||||
Indexer Indexer
|
Indexer Indexer
|
||||||
|
@ -349,3 +349,57 @@ func NewLimitRangeInformer(client clientset.Interface, resyncPeriod time.Duratio
|
|||||||
|
|
||||||
return sharedIndexInformer
|
return sharedIndexInformer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
// ServiceAccountInformer is type of SharedIndexInformer which watches and lists all ServiceAccounts.
|
||||||
|
// Interface provides constructor for informer and lister for ServiceAccounts
|
||||||
|
type ServiceAccountInformer interface {
|
||||||
|
Informer() cache.SharedIndexInformer
|
||||||
|
Lister() *cache.StoreToServiceAccountLister
|
||||||
|
}
|
||||||
|
|
||||||
|
type serviceAccountInformer struct {
|
||||||
|
*sharedInformerFactory
|
||||||
|
}
|
||||||
|
|
||||||
|
// Informer checks whether ServiceAccountInformer exists in sharedInformerFactory and if not, it creates new informer of type
|
||||||
|
// ServiceAccountInformer and connects it to sharedInformerFactory
|
||||||
|
func (f *serviceAccountInformer) Informer() cache.SharedIndexInformer {
|
||||||
|
f.lock.Lock()
|
||||||
|
defer f.lock.Unlock()
|
||||||
|
|
||||||
|
informerType := reflect.TypeOf(&api.ServiceAccount{})
|
||||||
|
informer, exists := f.informers[informerType]
|
||||||
|
if exists {
|
||||||
|
return informer
|
||||||
|
}
|
||||||
|
informer = NewServiceAccountInformer(f.client, f.defaultResync)
|
||||||
|
f.informers[informerType] = informer
|
||||||
|
|
||||||
|
return informer
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lister returns lister for ServiceAccountInformer
|
||||||
|
func (f *serviceAccountInformer) Lister() *cache.StoreToServiceAccountLister {
|
||||||
|
informer := f.Informer()
|
||||||
|
return &cache.StoreToServiceAccountLister{Indexer: informer.GetIndexer()}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewServiceAccountInformer returns a SharedIndexInformer that lists and watches all ServiceAccounts
|
||||||
|
func NewServiceAccountInformer(client clientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
|
||||||
|
sharedIndexInformer := cache.NewSharedIndexInformer(
|
||||||
|
&cache.ListWatch{
|
||||||
|
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
|
||||||
|
return client.Core().ServiceAccounts(api.NamespaceAll).List(options)
|
||||||
|
},
|
||||||
|
WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
|
||||||
|
return client.Core().ServiceAccounts(api.NamespaceAll).Watch(options)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&api.ServiceAccount{},
|
||||||
|
resyncPeriod,
|
||||||
|
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
|
||||||
|
|
||||||
|
return sharedIndexInformer
|
||||||
|
}
|
||||||
|
@ -36,6 +36,7 @@ type SharedInformerFactory interface {
|
|||||||
Namespaces() NamespaceInformer
|
Namespaces() NamespaceInformer
|
||||||
PersistentVolumeClaims() PVCInformer
|
PersistentVolumeClaims() PVCInformer
|
||||||
PersistentVolumes() PVInformer
|
PersistentVolumes() PVInformer
|
||||||
|
ServiceAccounts() ServiceAccountInformer
|
||||||
|
|
||||||
DaemonSets() DaemonSetInformer
|
DaemonSets() DaemonSetInformer
|
||||||
Deployments() DeploymentInformer
|
Deployments() DeploymentInformer
|
||||||
@ -108,6 +109,11 @@ func (f *sharedInformerFactory) PersistentVolumes() PVInformer {
|
|||||||
return &pvInformer{sharedInformerFactory: f}
|
return &pvInformer{sharedInformerFactory: f}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ServiceAccounts returns a SharedIndexInformer that lists and watches all service accounts.
|
||||||
|
func (f *sharedInformerFactory) ServiceAccounts() ServiceAccountInformer {
|
||||||
|
return &serviceAccountInformer{sharedInformerFactory: f}
|
||||||
|
}
|
||||||
|
|
||||||
// DaemonSets returns a SharedIndexInformer that lists and watches all daemon sets.
|
// DaemonSets returns a SharedIndexInformer that lists and watches all daemon sets.
|
||||||
func (f *sharedInformerFactory) DaemonSets() DaemonSetInformer {
|
func (f *sharedInformerFactory) DaemonSets() DaemonSetInformer {
|
||||||
return &daemonSetInformer{sharedInformerFactory: f}
|
return &daemonSetInformer{sharedInformerFactory: f}
|
||||||
|
Loading…
Reference in New Issue
Block a user