Skip to content

fix: prevent duplicate app.kubernetes.io/name in selector labels - #203

Closed
AdamMagued wants to merge 1 commit into
arttor:mainfrom
AdamMagued:fix-duplicate-selector-label
Closed

AdamMagued wants to merge 1 commit into
arttor:mainfrom
AdamMagued:fix-duplicate-selector-label

Conversation

@AdamMagued

Copy link
Copy Markdown

Problem

When converting Kustomize manifests (such as default Kubebuilder scaffolding) containing app.kubernetes.io/name in selector/matchLabels fields, helmify outputs both the original hardcoded label and the {{- include ".selectorLabels" . | nindent X }} helper call. Because the selectorLabels template helper already defines app.kubernetes.io/name: {{ include ".name" . }}, the rendered Helm chart templates contain duplicate app.kubernetes.io/name mapping keys. Strict YAML parsers (such as ArgoCD or Kubernetes server-side apply) reject these manifests with mapping key duplicate errors.

Root Cause

Resource processors (deployment, daemonset, service, and poddisruptionbudget) construct selectors by serializing the original resource selector map and appending {{- include ".selectorLabels" . }}. Unlike resource metadata labels in pkg/processor/meta.go which strips labels managed by Helm (app.kubernetes.io/name, etc.), the selector and pod template label generation retained app.kubernetes.io/name from the incoming manifest. Furthermore, when app.kubernetes.io/name is the only selector label, serializing an empty map could produce invalid YAML ({}).

Solution

  1. In pkg/processor/deployment, pkg/processor/daemonset, pkg/processor/service, and pkg/processor/poddisruptionbudget:
    • Delete app.kubernetes.io/name from selector/matchLabels and pod template labels prior to serialization.
    • Gracefully handle cases where app.kubernetes.io/name was the sole selector label, ensuring the selector template helper is rendered cleanly without emitting empty inline dicts ({}).
  2. Added unit regression tests in pkg/processor/service, pkg/processor/deployment, pkg/processor/daemonset, and pkg/processor/poddisruptionbudget covering duplicate label removal and single-label selectors.
  3. Added end-to-end regression test in pkg/app verifying full Helm chart generation and strict Helm lint validation (helmLint.Strict = true) with 0 errors.

Fixes #196

@AdamMagued

Copy link
Copy Markdown
Author

Closing in favor of earlier community PR #199 to keep the review queue clean.

@AdamMagued AdamMagued closed this Oct 2, 2026
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.

[BUG] Duplicate app.kubernetes.io/name key in selector when kustomize input contains the label

1 participant