Skip to content

Add release-specific selector labels to Services #71

@monrax

Description

@monrax

From: https://github.com/tigerpeng2001/graylog-helm/blob/main/evaluation.txt

The Service resources in the chart use a single hard-coded label for selection:

selector:
app: graylog-app

selector:
app: graylog-datanode

Meanwhile, the StatefulSet pods have multiple labels:

selector:
matchLabels:
app: graylog-app
{{- include "graylog.selectorLabels" . | nindent 6 }}

selector:
matchLabels:
app: graylog-datanode
{{- include "graylog.selectorLabels" . | nindent 6 }}

With graylog.selectorLabels defined in _helpers.tpl as release-specific labels:

{{/*
Selector labels
*/}}
{{- define "graylog.selectorLabels" -}}
app.kubernetes.io/name: {{ include "graylog.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

If someone installs multiple releases of this chart in the same namespace (e.g., helm install prod-graylog ... and helm install staging-graylog ...), both deployments will have pods with app: graylog-app. The Services would then route traffic to pods from both releases indiscriminately.

How to reproduce?

  1. Install one release of the chart in a given namespace
helm install graylog-prod graylog/graylog -n graylog --create-namespace --set graylog.replicas=1 --set datanode.replicas=1 --set mongodb.replicas=1 --set mongodb.arbiters=0 --set graylog.config.rootPassword="foo123"
  1. Install another release of the same chart in the same namespace
helm install graylog-dev graylog/graylog -n graylog --set graylog.replicas=1 --set datanode.replicas=1 --set mongodb.replicas=1 --set mongodb.arbiters=0 --set graylog.config.rootPassword="bar456"
  1. Get endpoints and verify both services have the same endpoints (when they shouldn't)
kubectl describe svc graylog-dev-svc -n graylog | grep Endpoints
kubectl describe svc graylog-prod-svc -n graylog | grep Endpoints

diff -s <(kubectl describe svc graylog-dev-svc -n graylog | grep Endpoints) <(kubectl describe svc graylog-prod-svc -n graylog | grep Endpoints)
  1. Get pod addresses and verify that all addresses exist in both services
kubectl get pod -n graylog -o wide | grep "graylog-\(dev\|prod\)-0"

diff -s <(kubectl describe svc graylog-dev-svc -n graylog | grep Endpoints) <(kubectl describe svc graylog-dev-svc -n graylog | grep Endpoints | grep $(kubectl get pod graylog-dev-0 -n graylog -o custom-columns=IP:.status.podIP | grep -v "IP"))

diff -s <(kubectl describe svc graylog-dev-svc -n graylog | grep Endpoints) <(kubectl describe svc graylog-dev-svc -n graylog | grep Endpoints | grep $(kubectl get pod graylog-prod-0 -n graylog -o custom-columns=IP:.status.podIP | grep -v "IP"))
  1. Expose one of the services
helm upgrade graylog-prod graylog/graylog -n graylog --reuse-values --set graylog.service.type=LoadBalancer
  1. Browse to the external address
open http://$(kubectl get svc --namespace graylog graylog-prod-svc --template "{{ with (index .status.loadBalancer.ingress 0) }}{{ or .hostname .ip }}{{ end }}"):9000/
  1. Verify you cannot log in with any of the credentials set in steps 1 and 2
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions