Repository navigation
feat: omit 'app.kubernetes.io/managed-by' label on three-way-diff - #1044
Conversation
|
@jkroepke please not if in if. |
There was a problem hiding this comment.
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.
| if a := metadata["labels"]; a != nil { | ||
| labels := a.(map[string]interface{}) | ||
| delete(labels, "app.kubernetes.io/managed-by") |
|
@jkroepke Thanks for the PR! I pushed a follow-up commit to avoid the nested 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 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 <[email protected]>
|
@yxxhero do you have a plan, when this gets released? |
|
@jkroepke soon. |
Resolve conflicts between the three-way merge for unstructured objects (PR #923) and the changes that landed on master since, most notably: - #1063 restructured createPatch to return a *resourcePatch and moved patch application into applyPatch with the client-side fallback. The three-way merge for unstructured objects (CRDs, CRs) now produces the current->merged patch as patch.data with patchType MergePatchType, so it flows through both the server dry-run and the local merge path. - #1068/#1065/#1044 rewrote the metadata tidy logic with pruneNestedMap. Keep that implementation (a superset of the annotation cleanup this PR inlined) together with the null-input and type-safety hardening of deleteStatusAndTidyMetadata. - generate_test.go was created independently on both sides; keep master's local-merge tests and re-add this PR's unstructured/CRD tests, adapted to the new createPatch signature. Signed-off-by: yxxhero <[email protected]> Signed-off-by: yxxhero <[email protected]>
Ref: #326 (comment)
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.