mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Use available informers in quota replenishment
This commit is contained in:
parent
a10975d05d
commit
669ce59b9b
@ -113,8 +113,21 @@ func NewReplenishmentControllerFactoryFromClient(kubeClient clientset.Interface)
|
|||||||
return NewReplenishmentControllerFactory(nil, kubeClient)
|
return NewReplenishmentControllerFactory(nil, kubeClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *replenishmentControllerFactory) NewController(options *ReplenishmentControllerOptions) (cache.ControllerInterface, error) {
|
// controllerFor returns a replenishment controller for the specified group resource.
|
||||||
var result cache.ControllerInterface
|
func controllerFor(
|
||||||
|
groupResource unversioned.GroupResource,
|
||||||
|
f informers.SharedInformerFactory,
|
||||||
|
handlerFuncs cache.ResourceEventHandlerFuncs) (cache.ControllerInterface, error) {
|
||||||
|
genericInformer, err := f.ForResource(groupResource)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
informer := genericInformer.Informer()
|
||||||
|
informer.AddEventHandler(handlerFuncs)
|
||||||
|
return informer.GetController(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *replenishmentControllerFactory) NewController(options *ReplenishmentControllerOptions) (result cache.ControllerInterface, err error) {
|
||||||
if r.kubeClient != nil && r.kubeClient.Core().RESTClient().GetRateLimiter() != nil {
|
if r.kubeClient != nil && r.kubeClient.Core().RESTClient().GetRateLimiter() != nil {
|
||||||
metrics.RegisterMetricAndTrackRateLimiterUsage("replenishment_controller", r.kubeClient.Core().RESTClient().GetRateLimiter())
|
metrics.RegisterMetricAndTrackRateLimiterUsage("replenishment_controller", r.kubeClient.Core().RESTClient().GetRateLimiter())
|
||||||
}
|
}
|
||||||
@ -122,16 +135,15 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
|
|||||||
switch options.GroupKind {
|
switch options.GroupKind {
|
||||||
case api.Kind("Pod"):
|
case api.Kind("Pod"):
|
||||||
if r.sharedInformerFactory != nil {
|
if r.sharedInformerFactory != nil {
|
||||||
podInformer := r.sharedInformerFactory.Pods().Informer()
|
result, err = controllerFor(api.Resource("pods"), r.sharedInformerFactory, cache.ResourceEventHandlerFuncs{
|
||||||
podInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
|
||||||
UpdateFunc: PodReplenishmentUpdateFunc(options),
|
UpdateFunc: PodReplenishmentUpdateFunc(options),
|
||||||
DeleteFunc: ObjectReplenishmentDeleteFunc(options),
|
DeleteFunc: ObjectReplenishmentDeleteFunc(options),
|
||||||
})
|
})
|
||||||
result = podInformer.GetController()
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
result = informers.NewPodInformer(r.kubeClient, options.ResyncPeriod())
|
result = informers.NewPodInformer(r.kubeClient, options.ResyncPeriod())
|
||||||
case api.Kind("Service"):
|
case api.Kind("Service"):
|
||||||
|
// TODO move to informer when defined
|
||||||
_, result = cache.NewInformer(
|
_, result = cache.NewInformer(
|
||||||
&cache.ListWatch{
|
&cache.ListWatch{
|
||||||
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
|
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
|
||||||
@ -149,6 +161,7 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
case api.Kind("ReplicationController"):
|
case api.Kind("ReplicationController"):
|
||||||
|
// TODO move to informer when defined
|
||||||
_, result = cache.NewInformer(
|
_, result = cache.NewInformer(
|
||||||
&cache.ListWatch{
|
&cache.ListWatch{
|
||||||
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
|
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
|
||||||
@ -165,6 +178,13 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
case api.Kind("PersistentVolumeClaim"):
|
case api.Kind("PersistentVolumeClaim"):
|
||||||
|
if r.sharedInformerFactory != nil {
|
||||||
|
result, err = controllerFor(api.Resource("persistentvolumeclaims"), r.sharedInformerFactory, cache.ResourceEventHandlerFuncs{
|
||||||
|
DeleteFunc: ObjectReplenishmentDeleteFunc(options),
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// TODO (derekwaynecarr) remove me when we can require a sharedInformerFactory in all code paths...
|
||||||
_, result = cache.NewInformer(
|
_, result = cache.NewInformer(
|
||||||
&cache.ListWatch{
|
&cache.ListWatch{
|
||||||
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
|
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
|
||||||
@ -181,6 +201,7 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
case api.Kind("Secret"):
|
case api.Kind("Secret"):
|
||||||
|
// TODO move to informer when defined
|
||||||
_, result = cache.NewInformer(
|
_, result = cache.NewInformer(
|
||||||
&cache.ListWatch{
|
&cache.ListWatch{
|
||||||
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
|
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
|
||||||
@ -197,6 +218,7 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
case api.Kind("ConfigMap"):
|
case api.Kind("ConfigMap"):
|
||||||
|
// TODO move to informer when defined
|
||||||
_, result = cache.NewInformer(
|
_, result = cache.NewInformer(
|
||||||
&cache.ListWatch{
|
&cache.ListWatch{
|
||||||
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
|
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
|
||||||
@ -215,7 +237,7 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
|
|||||||
default:
|
default:
|
||||||
return nil, NewUnhandledGroupKindError(options.GroupKind)
|
return nil, NewUnhandledGroupKindError(options.GroupKind)
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceReplenishmentUpdateFunc will replenish if the service was quota tracked has changed service type
|
// ServiceReplenishmentUpdateFunc will replenish if the service was quota tracked has changed service type
|
||||||
|
Loading…
Reference in New Issue
Block a user