Skip to content

Commit

Permalink
Reconcile on all private service events in KPA.
Browse files Browse the repository at this point in the history
We used to have a metrics service which the KPA watched and reacted to. We got rid of that and now have a race condition if we specify minScale but the SKS becomes ready with less than minScale pods. Nothing after that will ever kick the KPA to reconcile again.

This fixes that by watching the private services to make sure the KPA sees every change in deployment size. It itself keys off of the private services too to calculate the current replicas, closing the loop here.
  • Loading branch information
markusthoemmes committed Apr 6, 2020
1 parent b958769 commit d5f3cad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions pkg/reconciler/autoscaling/kpa/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (
"knative.dev/pkg/controller"
pkgreconciler "knative.dev/pkg/reconciler"
"knative.dev/serving/pkg/apis/autoscaling"
"knative.dev/serving/pkg/apis/networking"
"knative.dev/serving/pkg/apis/serving"
autoscalerconfig "knative.dev/serving/pkg/autoscaler/config"
servingreconciler "knative.dev/serving/pkg/reconciler"
areconciler "knative.dev/serving/pkg/reconciler/autoscaling"
Expand Down Expand Up @@ -115,15 +117,10 @@ func NewController(
})

endpointsInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: pkgreconciler.LabelExistsFilterFunc(autoscaling.KPALabelKey),
Handler: controller.HandleAll(impl.EnqueueLabelOfNamespaceScopedResource("", autoscaling.KPALabelKey)),
FilterFunc: pkgreconciler.LabelFilterFunc(networking.ServiceTypeKey, string(networking.ServiceTypePrivate), false),
Handler: controller.HandleAll(impl.EnqueueLabelOfNamespaceScopedResource("", serving.RevisionLabelKey)),
})

// Watch all the services that we have created.
serviceInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: onlyKpaClass,
Handler: controller.HandleAll(impl.EnqueueControllerOf),
})
sksInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: onlyKpaClass,
Handler: controller.HandleAll(impl.EnqueueControllerOf),
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/serverlessservice/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewController(
// Watch all the SKS objects.
sksInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue))

// Watch all the endpoints that we have attached our label to.
// Watch all the private service endpoints.
endpointsInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: pkgreconciler.LabelExistsFilterFunc(networking.SKSLabelKey),
Handler: controller.HandleAll(impl.EnqueueLabelOfNamespaceScopedResource("" /*any namespace*/, networking.SKSLabelKey)),
Expand Down

0 comments on commit d5f3cad

Please sign in to comment.