helm-chart-sonarqube icon indicating copy to clipboard operation
helm-chart-sonarqube copied to clipboard

Fix Service selectors

Open felipeng opened this issue 1 month ago • 2 comments

Service is using the wrong labels on selector.

Example, labels on the Deployment are app.kubernetes.io/:

helm template sonarqube charts/sonarqube/ -f values.yaml  | egrep 'kind: Deployment' -A 12
kind: Deployment
metadata:
  name: sonarqube
  labels:
    helm.sh/chart: sonarqube-2025.5.0
    app.kubernetes.io/name: sonarqube
    app.kubernetes.io/instance: sonarqube
    app.kubernetes.io/version: "2025.5.0"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: sonarqube
    app.kubernetes.io/instance: sonarqube
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/part-of: sonarqube

Service is selecting labels with: app and release

helm template sonarqube charts/sonarqube/ -f values.yaml  | egrep 'kind: Service$' -A 20
kind: Service
metadata:
  name: sonarqube
  labels:
    helm.sh/chart: sonarqube-2025.5.0
    app.kubernetes.io/name: sonarqube
    app.kubernetes.io/instance: sonarqube
    app.kubernetes.io/version: "2025.5.0"
    app.kubernetes.io/managed-by: Helm
spec:
  type: ClusterIP
  ports:
    - port: 9000
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app: sonarqube
    release: sonarqube

felipeng avatar Oct 08 '25 18:10 felipeng

hello @felipeng, Thanks a lot for the messagen sadly I cannot reproduce your issue, on my side:

helm template sonarqube . --set monitoringPasscode=aaa,edition=developer,deploymentType=Deployment | grep Deployment -9
# Source: sonarqube/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sonarqube-sonarqube
  labels:
    app: sonarqube
    chart: sonarqube-2025.6.0
    release: sonarqube
    heritage: Helm
    app.kubernetes.io/name: sonarqube
    app.kubernetes.io/instance: sonarqube

From the code standpoint, we have this helper:

{{/*
Common labels
*/}}
{{- define "sonarqube.labels" -}}
app: {{ include "sonarqube.name" . }}
chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- end -}}

That is used inside sonarqube.workloadLabels which is used inside the Deployment.

Can you share your value file ? to see if we might have a templating issue due to this ?

Nonetheless, i agree we could maybe improve this area of the chart

Thanks again.

jCOTINEAU avatar Oct 09 '25 07:10 jCOTINEAU

Hi @jCOTINEAU I've identified why you cannot reproduce it.

Firstly on my previous comments I was looking at the Deployment labels .metadata.labels but the selector filter by the .spec.template.metadata.labels, however, on both cases the labels are the same.

The reason you cannot reproduce is because I am using the sonarqube helm chart as dependency of another one in order to add some custom/external objects like SecretStore and ExternalSecrets, for example:

helm version: 3.19

values.yaml

sonarqube:
  monitoringPasscode: "1234"
  community:
    enabled: true
  deploymentType: "Deployment"

Chart.yaml for the chart that uses the sonarqube as dependency

apiVersion: v2
name: sonarqube
description: A SonarQube wrap with External Secrets Operator and SonarQube official chart as dependency.
type: application
version: "2025.5.0"
appVersion: "2025.5.0"
dependencies:
- name: sonarqube
  version: "2025.5.0"
  repository: "https://SonarSource.github.io/helm-chart-sonarqube"

Using this way the labels are app.kubernetes.io/ using the sonarqube helm chart directly (your case) the labels are [app|chart]:.

So, I was reading some documentation and this chart should migrate to new labels:

By the way, would be nice to implement the extraDeploy feature, this way we won't need to use as dependency :)

felipeng avatar Oct 09 '25 15:10 felipeng