@@ -2,6 +2,7 @@ package internal
22
33import (
44 "context"
5+ "encoding/json"
56 "os"
67 "reflect"
78 "strings"
@@ -287,6 +288,12 @@ func CreateOrUpdateResource(
287288 "namespace" , namespace ,
288289 )
289290
291+ // Capture pre-mutation state for diff logging
292+ var snapshotJSON []byte
293+ if obj .GetResourceVersion () != "" {
294+ snapshotJSON , _ = json .Marshal (obj )
295+ }
296+
290297 result , err := controllerutil .CreateOrUpdate (ctx , c , obj , func () error {
291298 // For existing objects, validate managed-by label before allowing mutations
292299 if obj .GetResourceVersion () != "" {
@@ -326,6 +333,15 @@ func CreateOrUpdateResource(
326333 l .Info ("created object" )
327334 case controllerutil .OperationResultUpdated :
328335 l .Info ("updated object" )
336+ // Temporary: log before/after JSON to diagnose spurious updates
337+ if snapshotJSON != nil {
338+ afterJSON , _ := json .Marshal (obj )
339+ if string (snapshotJSON ) != string (afterJSON ) {
340+ l .Info ("DEBUG-DIFF" , "before" , string (snapshotJSON ), "after" , string (afterJSON ))
341+ } else {
342+ l .Info ("DEBUG-DIFF: JSON identical but DeepEqual said different" )
343+ }
344+ }
329345 case controllerutil .OperationResultNone :
330346 l .V (1 ).Info ("object unchanged" )
331347 }
0 commit comments