Skip to content

feat: omit 'app.kubernetes.io/managed-by' label on three-way-diff - #1044

Merged
yxxhero merged 4 commits into
databus23:masterfrom
jkroepke:patch-1
Aug 12, 2026
Merged

feat: omit 'app.kubernetes.io/managed-by' label on three-way-diff#1044
yxxhero merged 4 commits into
databus23:masterfrom
jkroepke:patch-1

Conversation

@jkroepke

Copy link
Copy Markdown
Contributor

Ref: #326 (comment)

Worth noting, the app.kubernetes.io/managed-by: Helm label is handled the same way, but because it predates the auto-added metadata, it's present in most people's Helm templates, which is why you're not seeing it in this test-case.

I'm using helm diff with three-way-diff in a upgrade --dry-mode and I observe changes on each resource which would remove app.kubernetes.io/managed-by.

@yxxhero
yxxhero requested a balanced review from Copilot August 12, 2026 23:21
@yxxhero

yxxhero commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

@jkroepke please not if in if.

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.

Pull request overview

Omits Helm-managed labels from three-way diff output to prevent misleading removals.

Changes:

  • Removes app.kubernetes.io/managed-by.
  • Cleans up empty label maps.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread manifest/util.go Outdated
Comment on lines +39 to +41
if a := metadata["labels"]; a != nil {
labels := a.(map[string]interface{})
delete(labels, "app.kubernetes.io/managed-by")
@yxxhero

yxxhero commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

@jkroepke Thanks for the PR! I pushed a follow-up commit to avoid the nested if (no more "if in if").

I extracted a small helper so the two checks are sequential rather than nested:

func pruneNestedMap(target map[string]interface{}, key string, fields ...string) {
	sub, ok := target[key].(map[string]interface{})
	if !ok {
		return
	}
	for _, field := range fields {
		delete(sub, field)
	}
	if len(sub) == 0 {
		delete(target, key)
	}
}

The call site is now flat and both the existing annotations tidy and the new labels tidy share it:

pruneNestedMap(metadata, "annotations",
	"meta.helm.sh/release-name",
	"meta.helm.sh/release-namespace",
	"deployment.kubernetes.io/revision",
)
pruneNestedMap(metadata, "labels", "app.kubernetes.io/managed-by")

As a bonus the comma-ok assertion is a bit safer than the previous nil-check + type assertion. I also added test coverage for the label omission and the empty-labels cleanup path. PTAL.

Address review feedback to not use 'if in if'. Extract a deleteFromMap
helper that uses a comma-ok type assertion (early return) and a final
empty-check, so the two conditionals are sequential rather than nested.

Apply it to both the existing annotations tidy and the new labels tidy
(omitting app.kubernetes.io/managed-by) for consistency. Also add test
coverage for label omission and the empty-label cleanup path.

Signed-off-by: yxxhero <aiopsclub@163.com>
@yxxhero
yxxhero merged commit 1dfe2c7 into databus23:master Aug 12, 2026
25 checks passed
@jkroepke
jkroepke deleted the patch-1 branch August 13, 2026 06:02
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.

3 participants