Skip to content

Commit e73536d

Browse files
[release-1.19] Fix: PodAutoscaler not reconciled due to missing class annotation (#16191)
* Fix: PodAutoscaler not reconciled due to missing class annotation race condition setting the annotation before creating the PA eliminating the race condition * use constant for autoscaling.knative.dev/class --------- Co-authored-by: Nader Ziada <nziada@gmail.com>
1 parent 7f16f6b commit e73536d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pkg/reconciler/revision/cruds.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"knative.dev/pkg/logging"
3131
autoscalingv1alpha1 "knative.dev/serving/pkg/apis/autoscaling/v1alpha1"
3232
v1 "knative.dev/serving/pkg/apis/serving/v1"
33+
"knative.dev/serving/pkg/client/injection/reconciler/autoscaling/v1alpha1/podautoscaler"
3334
"knative.dev/serving/pkg/reconciler/revision/config"
3435
"knative.dev/serving/pkg/reconciler/revision/resources"
3536
)
@@ -104,5 +105,17 @@ func (c *Reconciler) createPA(
104105
deployment *appsv1.Deployment,
105106
) (*autoscalingv1alpha1.PodAutoscaler, error) {
106107
pa := resources.MakePA(rev, deployment)
108+
109+
// Ensure autoscaling annotations are set before creating PA.
110+
// This avoids a race condition where the informer cache sees the PA
111+
// before the webhook defaulting completes.
112+
cfg := config.FromContext(ctx)
113+
if pa.Annotations == nil {
114+
pa.Annotations = make(map[string]string)
115+
}
116+
if _, ok := pa.Annotations[podautoscaler.ClassAnnotationKey]; !ok && cfg.Autoscaler.PodAutoscalerClass != "" {
117+
pa.Annotations[podautoscaler.ClassAnnotationKey] = cfg.Autoscaler.PodAutoscalerClass
118+
}
119+
107120
return c.client.AutoscalingV1alpha1().PodAutoscalers(pa.Namespace).Create(ctx, pa, metav1.CreateOptions{})
108121
}

0 commit comments

Comments
 (0)