Skip to content

Commit 188daa5

Browse files
committed
fix: improve debug logging
1 parent a3ac9be commit 188daa5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

internal/kubernetes_crudding.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,15 @@ func CreateOrUpdateResource(
288288
"namespace", namespace,
289289
)
290290

291-
// Capture pre-mutation state for diff logging
292291
var snapshotJSON []byte
293-
if obj.GetResourceVersion() != "" {
294-
snapshotJSON, _ = json.Marshal(obj)
295-
}
296292

297293
result, err := controllerutil.CreateOrUpdate(ctx, c, obj, func() error {
294+
// Capture pre-mutation state for diff logging (must be inside closure,
295+
// after CreateOrUpdate has fetched the object from the API server)
296+
if obj.GetResourceVersion() != "" {
297+
snapshotJSON, _ = json.Marshal(obj)
298+
}
299+
298300
// For existing objects, validate managed-by label before allowing mutations
299301
if obj.GetResourceVersion() != "" {
300302
labels := obj.GetLabels()

0 commit comments

Comments
 (0)