Skip to content

Commit c05e855

Browse files
committed
operator: avoid unnecessary reconcile
Signed-off-by: zhzhuang-zju <[email protected]>
1 parent d8473e1 commit c05e855

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

operator/pkg/controller/karmada/controller.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,17 @@ func (ctrl *Controller) onKarmadaUpdate(updateEvent event.UpdateEvent) bool {
183183
return true
184184
}
185185

186-
return !reflect.DeepEqual(newObj.Spec, oldObj.Spec)
186+
// For updates that don't touch the spec (e.g. status updates), we can short-circuit.
187+
if reflect.DeepEqual(newObj.Spec, newObj.Spec) {
188+
return false
189+
}
190+
191+
// The spec has changed. We need to check if it's a semantic change or just defaulting.
192+
// TODO(@zhzhuang-zju): If default values are set via an admission controller, the default() call below can be omitted.
193+
newCopy := newObj.DeepCopy()
194+
oldCopy := oldObj.DeepCopy()
195+
196+
operatorscheme.Scheme.Default(newCopy)
197+
operatorscheme.Scheme.Default(oldCopy)
198+
return !reflect.DeepEqual(newCopy.Spec, oldCopy.Spec)
187199
}

0 commit comments

Comments
 (0)