Skip to content

Commit 787af40

Browse files
committed
don't remove annotations that are added by defaulting/webhooks
1 parent 3a16186 commit 787af40

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

pkg/reconciler/revision/reconcile_resources.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package revision
1919
import (
2020
"context"
2121
"fmt"
22+
"maps"
2223

2324
"go.uber.org/zap"
2425
"knative.dev/pkg/tracker"
@@ -183,7 +184,7 @@ func (c *Reconciler) reconcilePA(ctx context.Context, rev *v1.Revision) error {
183184
// We no longer require immutability, so need to reconcile PA each time.
184185
tmpl := resources.MakePA(rev, deployment)
185186
logger.Debugf("Desired PASpec: %#v", tmpl.Spec)
186-
if !equality.Semantic.DeepEqual(tmpl.Spec, pa.Spec) || !equality.Semantic.DeepEqual(tmpl.Annotations, pa.Annotations) {
187+
if !equality.Semantic.DeepEqual(tmpl.Spec, pa.Spec) || !annotationsPresent(pa.Annotations, tmpl.Annotations) {
187188
// Can't realistically fail on PASpec.
188189
if diff, _ := kmp.SafeDiff(tmpl.Spec, pa.Spec); diff != "" {
189190
logger.Infof("PA %q spec needs reconciliation, diff(-want,+got):\n%s", pa.Name, diff)
@@ -195,16 +196,31 @@ func (c *Reconciler) reconcilePA(ctx context.Context, rev *v1.Revision) error {
195196

196197
want := pa.DeepCopy()
197198
want.Spec = tmpl.Spec
198-
want.Annotations = tmpl.Annotations
199199

200-
if pa, err = c.client.AutoscalingV1alpha1().PodAutoscalers(ns).Update(ctx, want, metav1.UpdateOptions{}); err != nil {
201-
return fmt.Errorf("failed to update PA %q: %w", paName, err)
202-
}
200+
// copy template annotations over while preserving existing ones
201+
maps.Copy(want.Annotations, tmpl.Annotations)
202+
203+
_, err := c.client.AutoscalingV1alpha1().PodAutoscalers(ns).Update(ctx, want, metav1.UpdateOptions{})
204+
return err
203205
}
204206

205207
return nil
206208
}
207209

210+
func annotationsPresent(dst, src map[string]string) bool {
211+
for k, want := range src {
212+
got, ok := dst[k]
213+
if !ok {
214+
return false
215+
}
216+
217+
if got != want {
218+
return false
219+
}
220+
}
221+
return true
222+
}
223+
208224
func hasDeploymentTimedOut(deployment *appsv1.Deployment) bool {
209225
// as per https://kubernetes.io/docs/concepts/workloads/controllers/deployment
210226
for _, cond := range deployment.Status.Conditions {

0 commit comments

Comments
 (0)