From d5ddbafd970f4f29922a154aacc7dcc2be604373 Mon Sep 17 00:00:00 2001 From: Nader Ziada Date: Fri, 10 Oct 2025 12:03:56 -0400 Subject: [PATCH 1/2] Fix: PodAutoscaler not reconciled due to missing class annotation race condition setting the annotation before creating the PA eliminating the race condition --- pkg/reconciler/revision/cruds.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/reconciler/revision/cruds.go b/pkg/reconciler/revision/cruds.go index a8eb1852adc3..554dafc6fb0d 100644 --- a/pkg/reconciler/revision/cruds.go +++ b/pkg/reconciler/revision/cruds.go @@ -104,5 +104,17 @@ func (c *Reconciler) createPA( deployment *appsv1.Deployment, ) (*autoscalingv1alpha1.PodAutoscaler, error) { pa := resources.MakePA(rev, deployment) + + // Ensure autoscaling annotations are set before creating PA. + // This avoids a race condition where the informer cache sees the PA + // before the webhook defaulting completes. + cfg := config.FromContext(ctx) + if pa.Annotations == nil { + pa.Annotations = make(map[string]string) + } + if _, ok := pa.Annotations["autoscaling.knative.dev/class"]; !ok && cfg.Autoscaler.PodAutoscalerClass != "" { + pa.Annotations["autoscaling.knative.dev/class"] = cfg.Autoscaler.PodAutoscalerClass + } + return c.client.AutoscalingV1alpha1().PodAutoscalers(pa.Namespace).Create(ctx, pa, metav1.CreateOptions{}) } From b8dc14ed1507c8f94ad634b419e3b01d8e391e5c Mon Sep 17 00:00:00 2001 From: Nader Ziada Date: Tue, 14 Oct 2025 15:11:54 -0400 Subject: [PATCH 2/2] use constant for autoscaling.knative.dev/class --- pkg/reconciler/revision/cruds.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/reconciler/revision/cruds.go b/pkg/reconciler/revision/cruds.go index 554dafc6fb0d..4e3c7855562e 100644 --- a/pkg/reconciler/revision/cruds.go +++ b/pkg/reconciler/revision/cruds.go @@ -30,6 +30,7 @@ import ( "knative.dev/pkg/logging" autoscalingv1alpha1 "knative.dev/serving/pkg/apis/autoscaling/v1alpha1" v1 "knative.dev/serving/pkg/apis/serving/v1" + "knative.dev/serving/pkg/client/injection/reconciler/autoscaling/v1alpha1/podautoscaler" "knative.dev/serving/pkg/reconciler/revision/config" "knative.dev/serving/pkg/reconciler/revision/resources" ) @@ -112,8 +113,8 @@ func (c *Reconciler) createPA( if pa.Annotations == nil { pa.Annotations = make(map[string]string) } - if _, ok := pa.Annotations["autoscaling.knative.dev/class"]; !ok && cfg.Autoscaler.PodAutoscalerClass != "" { - pa.Annotations["autoscaling.knative.dev/class"] = cfg.Autoscaler.PodAutoscalerClass + if _, ok := pa.Annotations[podautoscaler.ClassAnnotationKey]; !ok && cfg.Autoscaler.PodAutoscalerClass != "" { + pa.Annotations[podautoscaler.ClassAnnotationKey] = cfg.Autoscaler.PodAutoscalerClass } return c.client.AutoscalingV1alpha1().PodAutoscalers(pa.Namespace).Create(ctx, pa, metav1.CreateOptions{})