arttor / helmify

Creates Helm chart from Kubernetes yaml
MIT License
1.46k stars 133 forks source link

Incorrect labels for StatefulSet selector section #131

Open andreiionutdamian opened 11 months ago

andreiionutdamian commented 11 months ago

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 }}
arttor commented 10 months ago

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.