Skip to content

fix: keep metadata added outside the chart when it renders a null map - #1102

Merged
yxxhero merged 2 commits into
databus23:masterfrom
jaredhicks:fix/three-way-null-metadata-maps
Nov 7, 2026
Merged

yxxhero merged 2 commits into
databus23:masterfrom
jaredhicks:fix/three-way-null-metadata-maps

Conversation

@jaredhicks

Copy link
Copy Markdown
Contributor

Fixes #1101

Problem

A chart that renders annotations: or labels: with nothing under it leaves the map null.
On the strategic merge path, the three-way patch helm-diff computes then deletes the whole map, so --three-way-merge reports every annotation or label added outside the chart as removed.
helm upgrade keeps them, because it merges the release's ownership metadata into every object before it computes its own patch (setMetadataVisitor, pkg/action/validate.go), so the map it sends is never null.

Fix

Add the same ownership metadata to the new manifest before createPatch, so the patch matches the one the upgrade sends.
A new WithRelease(name, namespace) option to manifest.Generate carries the release identity; helm diff upgrade sets it.

The custom resource path is unaffected: cleanMetadataForPatch already removes these keys, and any map they leave empty, before comparing, so the added metadata does not count as a chart change.
The Helm keys are pruned from the output as before.

Tests

🤖 Generated with Claude Code

jaredhicks and others added 2 commits November 5, 2026 16:20
helm install, upgrade and rollback merge the release's ownership metadata
(meta.helm.sh/release-name, meta.helm.sh/release-namespace and the
app.kubernetes.io/managed-by label) into every object before computing the
three-way patch. helm-diff computed the patch from the rendered manifest
alone, so when a chart renders `annotations:` or `labels:` with nothing under
it, the patch nulled the whole map. The server-side dry-run then dropped every
annotation or label added outside the chart and reported their removal, while
the real upgrade keeps them.

Add the same ownership metadata to the new manifest before createPatch, via a
WithRelease option that the upgrade command sets. The custom resource path is
unaffected: it tidies these keys away before comparing the manifests.

Behavioral change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rename the script so scripts/issues/run.sh picks it up, and link the issue.

Structural change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified in the changes aligning three-way patch generation with Helm ownership metadata.

No open issues 🎉

What changed in this PR

Addresses #1101 by aligning three-way patch generation with Helm’s ownership metadata handling, preventing false removal reports for externally added annotations and labels when a chart renders null metadata maps.

Changes:

  • Passes the release name and namespace into manifest generation.
  • Adds Helm ownership metadata to a copy of the target object before computing patches.
  • Adds unit and cluster regression tests for metadata preservation and chart-owned annotation drift.
File Description
scripts/​issues/​1101.sh Exercises null-map preservation, client merge mode, drift detection, and Helm upgrade behavior.
manifest/​generate.go Adds release options and injects ownership metadata before patch creation.
manifest/​generate_test.go Verifies strategic patches preserve externally added annotations and labels.
cmd/​upgrade.go Resolves the release namespace and passes release identity to manifest generation.

Review effort: Balanced

@yxxhero
yxxhero merged commit e1ec92f into databus23:master Nov 7, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--three-way-merge reports removal of annotations/labels added outside the chart when the chart renders an empty map

3 participants