Skip to content

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

@blixem777

Description

@blixem777

Description

When the kustomize input contains app.kubernetes.io/name in selector/matchLabels fields, helmify emits both the hardcoded original value and the chart.selectorLabels include, which also contains app.kubernetes.io/name. This produces duplicate YAML mapping keys that are rejected by strict YAML parsers (e.g. ArgoCD).

Version

helmify v0.4.19

Steps to reproduce

  1. Have a standard Kubebuilder project with app.kubernetes.io/name in config/manager/manager.yaml and config/default/metrics_service.yaml (default Kubebuilder scaffolding)
  2. Run kustomize build config/default | helmify

Kustomize input (relevant section)

The Deployment in the kustomize output contains:

spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: platform-operator
      control-plane: controller-manager
  template:
    metadata:
      labels:
        app.kubernetes.io/name: platform-operator
        control-plane: controller-manager

The Service selector contains:

spec:
  selector:
    app.kubernetes.io/name: platform-operator
    control-plane: controller-manager

Actual output

deployment.yaml:

spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: platform-operator     # hardcoded from kustomize
      control-plane: controller-manager
    {{- include "chart.selectorLabels" . | nindent 6 }}  # also emits app.kubernetes.io/name

metrics-service.yaml:

spec:
  selector:
    app.kubernetes.io/name: platform-operator     # hardcoded from kustomize
    control-plane: controller-manager
    {{- include "chart.selectorLabels" . | nindent 4 }}  # also emits app.kubernetes.io/name

Where chart.selectorLabels is defined as:

{{- define "chart.selectorLabels" -}}
app.kubernetes.io/name: {{ include "chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

Expected output

The hardcoded app.kubernetes.io/name should be omitted from selectors when chart.selectorLabels is already included, since that helper already provides the same key:

spec:
  selector:
    matchLabels:
      control-plane: controller-manager
    {{- include "chart.selectorLabels" . | nindent 6 }}

Impact

ArgoCD (and other strict YAML parsers) reject the rendered manifests:

error decoding resources yaml: unmarshal errors:
  line 1952: mapping key "app.kubernetes.io/name" already defined at line 1950

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions