helmify icon indicating copy to clipboard operation
helmify copied to clipboard

Incorrect labels for StatefulSet selector section

Open andreiionutdamian opened this issue 1 year ago • 1 comments

The problem is that the StatefulSet are not correctly generated resulting in the service not being able to correctly select coresponding pods. Basically I had this original manifest (part):

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: redis-master
  labels:
    app: redis
    role: master
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
      role: master
  ...

after helmify I received:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: {{ include "sf.fullname" . }}-master
  labels:
    app: redis
    role: master
  {{- include "sf.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.master.replicas }}
  selector:
    matchLabels:
      app: redis
      role: master
  serviceName: ""
  template:
    metadata:
      labels:
        app: redis
        role: master
    ...

So the specs.selector.matchLabels and the spec.template.metadata.labels are missing a {{- include "<chart>.selectorLabels" . | nindent 6 }} while the service template has it as it should. I replicated the identical scenario with Deployment instead of StatefulSet and in the case of Deployment the results are correct as it is supposed to be (and service-pods communication works):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-master
  labels:
    app: redis
    role: master
  {{- include "stateless.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.master.replicas }}
  selector:
    matchLabels:
      app: redis
      role: master
    {{- include "stateless.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        app: redis
        role: master
      {{- include "stateless.selectorLabels" . | nindent 8 }}

andreiionutdamian avatar Dec 15 '23 05:12 andreiionutdamian

Thank you for reporting the issue. I see that StatefulSet processor is not up to date with Deployment. Probably, it makes sense to have a single processor for both StatefulSet and Deployment or copy label processing logic from Deployment to StatefulSet as a quick fix.

arttor avatar Jan 02 '24 07:01 arttor