bitnami / charts

Bitnami Helm Charts
https://bitnami.com
Other
8.97k stars 9.2k forks source link

bitnami/mongodb Including role type label in service to differentiate Primary or Secondary #6115

Closed kwill4026 closed 3 years ago

kwill4026 commented 3 years ago

Which chart: bitnami/mongodb

Is your feature request related to a problem? Please describe. No problem just an improvement

Describe the solution you'd like Similar to how bitnami/postgresql does it, is it possible for the bitnami/mongodb chart to include labels in the services to differentiate between the primary pod and secondary? The bitnami/postgresql chart has two separate services, one which has a label of role:Primary and another with the label role role:read. The bitnami/mongodb however has a single service which, depending on the replicaCount number, will produce that amount of services with the name-0 to the mongodb full name to denote primary and name-1,name-2, etc to denote the secondaries. It would be better if there was a label associate with name-0 to denote it as primary and for the replicas to contain a label in the service denoting it as secondaries.

Describe alternatives you've considered A way to have the services included primary and secondary labels. I attempted to do it but because the chart uses a single service, I have difficulties implementing it.

Additional context Current setup for the external service is as so:

{{- if and (eq .Values.architecture "replicaset") .Values.externalAccess.enabled (not (eq .Values.externalAccess.service.type "ClusterIP"))}}
{{- $fullName := include "mongodb.fullname" . }}
{{- $replicaCount := .Values.replicaCount | int }}
{{- $root := . }}

{{- range $i, $e := until $replicaCount }}
{{- $targetPod := printf "%s-%d" (printf "%s" $fullName) $i }}
{{- $_ := set $ "targetPod" $targetPod }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ $fullName }}-{{ $i }}-external
  namespace: {{ include "mongodb.namespace" $ }}
  labels: {{- include "common.labels.standard" $ | nindent 4 }}
    app.kubernetes.io/component: mongodb
    pod: {{ $targetPod }}
  .
  .
  .

I would like if the external service yaml file included a label of role type to be Primary for the first mongo pod that gets spun and a role type of Secondary for the remaining mongos that follow. I can of course just write in the yaml file role:primary as seen below, but that just applies the label to all pods that get spun up.

{{- if and (eq .Values.architecture "replicaset") .Values.externalAccess.enabled (not (eq .Values.externalAccess.service.type "ClusterIP"))}}
{{- $fullName := include "mongodb.fullname" . }}
{{- $replicaCount := .Values.replicaCount | int }}
{{- $root := . }}

{{- range $i, $e := until $replicaCount }}
{{- $targetPod := printf "%s-%d" (printf "%s" $fullName) $i }}
{{- $_ := set $ "targetPod" $targetPod }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ $fullName }}-{{ $i }}-external
  namespace: {{ include "mongodb.namespace" $ }}
  labels: {{- include "common.labels.standard" $ | nindent 4 }}
    app.kubernetes.io/component: mongodb
    pod: {{ $targetPod }}
    role: primary 
  .
  .
  .
migruiz4 commented 3 years ago

Hi @kwill4026,

The main difference with the PostgreSQL chart is that if the MongoDB primary node fails, the other nodes in the replica set will choose a new primary.

If that happened, the service label wouldn't match be pod role as they are set at deployment time.

For that reason we can not implement this feature request.

github-actions[bot] commented 3 years ago

This Issue has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thanks for the feedback.

github-actions[bot] commented 3 years ago

Due to the lack of activity in the last 5 days since it was marked as "stale", we proceed to close this Issue. Do not hesitate to reopen it later if necessary.