Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use available informers in quota replenishment #36329

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 28 additions & 6 deletions pkg/controller/resourcequota/replenishment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,37 @@ func NewReplenishmentControllerFactoryFromClient(kubeClient clientset.Interface)
return NewReplenishmentControllerFactory(nil, kubeClient)
}

func (r *replenishmentControllerFactory) NewController(options *ReplenishmentControllerOptions) (cache.ControllerInterface, error) {
var result cache.ControllerInterface
// controllerFor returns a replenishment controller for the specified group resource.
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 {
metrics.RegisterMetricAndTrackRateLimiterUsage("replenishment_controller", r.kubeClient.Core().RESTClient().GetRateLimiter())
}

switch options.GroupKind {
case api.Kind("Pod"):
if r.sharedInformerFactory != nil {
podInformer := r.sharedInformerFactory.Pods().Informer()
podInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
result, err = controllerFor(api.Resource("pods"), r.sharedInformerFactory, cache.ResourceEventHandlerFuncs{
UpdateFunc: PodReplenishmentUpdateFunc(options),
DeleteFunc: ObjectReplenishmentDeleteFunc(options),
})
result = podInformer.GetController()
break
}
result = informers.NewPodInformer(r.kubeClient, options.ResyncPeriod())
case api.Kind("Service"):
// TODO move to informer when defined
_, result = cache.NewInformer(
&cache.ListWatch{
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
Expand All @@ -149,6 +161,7 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
},
)
case api.Kind("ReplicationController"):
// TODO move to informer when defined
_, result = cache.NewInformer(
&cache.ListWatch{
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
Expand All @@ -165,6 +178,13 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
},
)
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(
&cache.ListWatch{
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
Expand All @@ -181,6 +201,7 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
},
)
case api.Kind("Secret"):
// TODO move to informer when defined
_, result = cache.NewInformer(
&cache.ListWatch{
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
Expand All @@ -197,6 +218,7 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
},
)
case api.Kind("ConfigMap"):
// TODO move to informer when defined
_, result = cache.NewInformer(
&cache.ListWatch{
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
Expand All @@ -215,7 +237,7 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
default:
return nil, NewUnhandledGroupKindError(options.GroupKind)
}
return result, nil
return result, err
}

// ServiceReplenishmentUpdateFunc will replenish if the service was quota tracked has changed service type
Expand Down