From a57361561d883797886d50309500f34a2d859be3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20B=C3=B6wing?= Date: Mon, 26 Jan 2026 14:16:43 +0100 Subject: [PATCH] Reduce deployment updates --- pkg/reconciler/revision/cruds.go | 10 +++++----- pkg/reconciler/revision/table_test.go | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pkg/reconciler/revision/cruds.go b/pkg/reconciler/revision/cruds.go index da5422a57016..4250b6fcfeeb 100644 --- a/pkg/reconciler/revision/cruds.go +++ b/pkg/reconciler/revision/cruds.go @@ -63,11 +63,6 @@ func (c *Reconciler) checkAndUpdateDeployment(ctx context.Context, rev *v1.Revis // TODO(dprotaso): determine other immutable properties. deployment.Spec.Selector = have.Spec.Selector - // If the spec we want is the spec we have, then we're good. - if equality.Semantic.DeepEqual(have.Spec, deployment.Spec) { - return have, nil - } - // Otherwise attempt an update (with ONLY the spec changes). desiredDeployment := have.DeepCopy() desiredDeployment.Spec = deployment.Spec @@ -80,6 +75,11 @@ func (c *Reconciler) checkAndUpdateDeployment(ctx context.Context, rev *v1.Revis desiredDeployment.Spec.Template.Labels = mergeMetadata(deployment.Spec.Template.Labels, have.Spec.Template.Labels) desiredDeployment.Spec.Template.Annotations = mergeMetadata(deployment.Spec.Template.Annotations, have.Spec.Template.Annotations) + // If the spec we want is the spec we have, then we're good. + if equality.Semantic.DeepEqual(have.Spec, desiredDeployment.Spec) { + return have, nil + } + d, err := c.kubeclient.AppsV1().Deployments(deployment.Namespace).Update(ctx, desiredDeployment, metav1.UpdateOptions{}) if err != nil { return nil, err diff --git a/pkg/reconciler/revision/table_test.go b/pkg/reconciler/revision/table_test.go index 6f1b5b011d5e..8d92163c6494 100644 --- a/pkg/reconciler/revision/table_test.go +++ b/pkg/reconciler/revision/table_test.go @@ -223,6 +223,16 @@ func TestReconcile(t *testing.T) { Object: addDeploymentMetadata(deploy(t, "foo", "preserve-annotations"), false), }}, Key: "foo/preserve-annotations", + }, { + Name: "do not update deployments with no spec changes", + Objects: []runtime.Object{ + Revision("foo", "preserve-annotations", + WithLogURL, allUnknownConditions, withDefaultContainerStatuses(), WithRevisionObservedGeneration(1)), + pa("foo", "preserve-annotations", WithReachabilityUnknown), + addDeploymentMetadata(deploy(t, "foo", "preserve-annotations"), false), + image("foo", "preserve-annotations"), + }, + Key: "foo/preserve-annotations", }, { Name: "failure updating deployment", // Test that we handle an error updating the deployment properly.