{{- /* Copyright Broadcom, Inc. All Rights Reserved. SPDX-License-Identifier: APACHE-2.0 */}} {{- if not .Values.configsvr.external.host }} apiVersion: apps/v1 kind: StatefulSet metadata: name: {{ printf "%s-configsvr" (include "common.names.fullname" .) }} namespace: {{ include "common.names.namespace" . | quote }} labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }} app.kubernetes.io/component: configsvr {{- if .Values.commonAnnotations }} annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} {{- end }} spec: {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.configsvr.podLabels .Values.common.podLabels .Values.commonLabels ) "context" . ) }} selector: matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 6 }} app.kubernetes.io/component: configsvr serviceName: {{ printf "%s-headless" (include "common.names.fullname" .) }} replicas: {{ .Values.configsvr.replicaCount }} podManagementPolicy: {{ .Values.configsvr.podManagementPolicy }} updateStrategy: {{- toYaml .Values.configsvr.updateStrategy | nindent 4 }} template: metadata: labels: {{- include "common.labels.standard" ( dict "customLabels" $podLabels "context" $ ) | nindent 8 }} app.kubernetes.io/component: configsvr {{- if or .Values.common.podAnnotations .Values.configsvr.podAnnotations .Values.metrics.enabled }} annotations: {{- if or .Values.common.podAnnotations .Values.configsvr.podAnnotations }} {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.configsvr.podAnnotations .Values.common.podAnnotations ) "context" . ) }} {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $ ) | nindent 8 }} {{- end }} {{- if .Values.metrics.enabled }} {{- include "common.tplvalues.render" ( dict "value" .Values.metrics.podAnnotations "context" $ ) | nindent 8 }} {{- end }} {{- end }} spec: {{- if .Values.configsvr.schedulerName }} schedulerName: {{ .Values.configsvr.schedulerName | quote }} {{- end }} serviceAccountName: {{ include "mongodb-sharded.serviceAccountName" (dict "component" "configsvr" "value" .Values.configsvr.serviceAccount "context" $) }} automountServiceAccountToken: {{ .Values.configsvr.automountServiceAccountToken }} {{- if .Values.configsvr.hostAliases }} hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.configsvr.hostAliases "context" $) | nindent 8 }} {{- end }} {{- if .Values.configsvr.affinity }} affinity: {{- include "common.tplvalues.render" (dict "value" .Values.configsvr.affinity "context" $) | nindent 8 }} {{- else }} affinity: podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.configsvr.podAffinityPreset "component" "configsvr" "customLabels" $podLabels "context" $) | nindent 10 }} podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.configsvr.podAntiAffinityPreset "component" "configsvr" "customLabels" $podLabels "context" $) | nindent 10 }} nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.configsvr.nodeAffinityPreset.type "key" .Values.configsvr.nodeAffinityPreset.key "values" .Values.configsvr.nodeAffinityPreset.values) | nindent 10 }} {{- end }} {{- if .Values.configsvr.nodeSelector }} nodeSelector: {{- include "common.tplvalues.render" (dict "value" .Values.configsvr.nodeSelector "context" $) | nindent 8 }} {{- end }} {{- if .Values.configsvr.tolerations }} tolerations: {{- include "common.tplvalues.render" (dict "value" .Values.configsvr.tolerations "context" $) | nindent 8 }} {{- end }} {{- if .Values.configsvr.priorityClassName }} priorityClassName: {{ .Values.configsvr.priorityClassName | quote }} {{- end }} {{- if .Values.configsvr.topologySpreadConstraints }} topologySpreadConstraints: {{- include "common.tplvalues.render" (dict "value" .Values.configsvr.topologySpreadConstraints "context" $) | nindent 8 }} {{- end }} {{- if .Values.configsvr.podSecurityContext.enabled }} securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.configsvr.podSecurityContext "context" $) | nindent 8 }} {{- end }} {{- if .Values.configsvr.terminationGracePeriodSeconds }} terminationGracePeriodSeconds: {{ .Values.configsvr.terminationGracePeriodSeconds }} {{- end }} {{- include "mongodb-sharded.imagePullSecrets" . | nindent 6 }} initContainers: {{- if and .Values.volumePermissions.enabled .Values.configsvr.persistence.enabled }} - name: volume-permissions image: {{ include "mongodb-sharded.volumePermissions.image" . }} imagePullPolicy: {{ .Values.volumePermissions.image.pullPolicy | quote }} command: - /bin/bash args: - -ec - | mkdir -p {{ .Values.configsvr.persistence.mountPath }}{{- if .Values.configsvr.persistence.subPath }}/{{ include "common.tplvalues.render" (dict "value" .Values.configsvr.persistence.subPath "context" $) }}{{- end }} chown {{ .Values.configsvr.containerSecurityContext.runAsUser }}:{{ .Values.configsvr.podSecurityContext.fsGroup }} {{ .Values.configsvr.persistence.mountPath }}{{- if .Values.configsvr.persistence.subPath }}/{{ include "common.tplvalues.render" (dict "value" .Values.configsvr.persistence.subPath "context" $) }}{{- end }} find {{ .Values.configsvr.persistence.mountPath }} -mindepth 1 -maxdepth 1 -not -name ".snapshot" -not -name "lost+found" | xargs -r chown -R {{ .Values.configsvr.containerSecurityContext.runAsUser }}:{{ .Values.configsvr.podSecurityContext.fsGroup }} securityContext: runAsUser: 0 {{- if .Values.volumePermissions.resources }} resources: {{- toYaml .Values.volumePermissions.resources | nindent 12 }} {{- else if ne .Values.volumePermissions.resourcesPreset "none" }} resources: {{- include "common.resources.preset" (dict "type" .Values.volumePermissions.resourcesPreset) | nindent 12 }} {{- end }} volumeMounts: - name: datadir mountPath: {{ .Values.configsvr.persistence.mountPath }} {{- if .Values.configsvr.persistence.subPath }} subPath: {{ include "common.tplvalues.render" (dict "value" .Values.configsvr.persistence.subPath "context" $) }} {{- end }} - name: empty-dir mountPath: /tmp subPath: tmp-dir {{- end }} {{- with .Values.configsvr.initContainers }} {{- include "common.tplvalues.render" ( dict "value" . "context" $ ) | nindent 8 }} {{- end }} {{- with .Values.common.initContainers }} {{- include "common.tplvalues.render" ( dict "value" . "context" $ ) | nindent 8 }} {{- end }} {{- include "mongodb-sharded.initContainer.logDir" $ | nindent 8 }} containers: - name: mongodb image: {{ include "mongodb-sharded.image" . }} imagePullPolicy: {{ .Values.image.pullPolicy }} {{- if .Values.configsvr.containerSecurityContext.enabled }} securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.configsvr.containerSecurityContext "context" $) | nindent 12 }} {{- end }} ports: - containerPort: {{ .Values.common.containerPorts.mongodb }} name: mongodb env: - name: GLIBC_TUNABLES value: glibc.pthread.rseq=0 - name: MONGODB_ENABLE_NUMACTL value: {{ ternary "yes" "no" .Values.common.mongodbEnableNumactl | quote }} - name: BITNAMI_DEBUG value: {{ ternary "true" "false" (or .Values.image.debug .Values.diagnosticMode.enabled) | quote }} - name: MONGODB_SYSTEM_LOG_VERBOSITY value: {{ .Values.common.mongodbSystemLogVerbosity | quote }} - name: MONGODB_DISABLE_SYSTEM_LOG {{- if .Values.common.mongodbDisableSystemLog }} value: "yes" {{- else }} value: "no" {{- end }} - name: MONGODB_INIT_RETRY_ATTEMPTS value: {{ .Values.common.mongodbInitRetryAttempts | quote }} - name: MONGODB_INIT_RETRY_DELAY value: {{ .Values.common.mongodbInitRetryDelay | quote }} - name: MONGODB_SHARDING_MODE value: "configsvr" - name: MONGODB_POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: MONGODB_PORT_NUMBER value: {{ .Values.common.containerPorts.mongodb | quote }} - name: MONGODB_INITIAL_PRIMARY_HOST value: {{ include "mongodb-sharded.configServer.primaryHost" . }} - name: MONGODB_REPLICA_SET_NAME value: {{ printf "%s-configsvr" ( include "common.names.fullname" . ) }} {{- if .Values.common.useHostnames }} - name: MONGODB_ADVERTISED_HOSTNAME value: {{ printf "$(MONGODB_POD_NAME).%s-headless.%s.svc.%s" (include "common.names.fullname" .) (include "common.names.namespace" .) .Values.clusterDomain }} {{- end }} {{- if .Values.auth.enabled }} - name: MONGODB_ROOT_USER value: {{ .Values.auth.rootUser | quote }} {{- if .Values.auth.usePasswordFiles }} - name: MONGODB_ROOT_PASSWORD_FILE value: "/bitnami/mongodb/secrets/mongodb-root-password" - name: MONGODB_REPLICA_SET_KEY_FILE value: "/bitnami/mongodb/secrets/mongodb-replica-set-key" {{- else }} - name: MONGODB_ROOT_PASSWORD valueFrom: secretKeyRef: name: {{ include "mongodb-sharded.secret" . }} key: mongodb-root-password - name: MONGODB_REPLICA_SET_KEY valueFrom: secretKeyRef: name: {{ include "mongodb-sharded.secret" . }} key: mongodb-replica-set-key {{- end }} {{- end }} - name: MONGODB_ENABLE_IPV6 {{- if .Values.common.mongodbEnableIPv6 }} value: "yes" {{- else }} value: "no" {{- end }} - name: MONGODB_ENABLE_DIRECTORY_PER_DB {{- if .Values.common.mongodbDirectoryPerDB }} value: "yes" {{- else }} value: "no" {{- end }} {{- if .Values.configsvr.mongodbExtraFlags }} - name: MONGODB_EXTRA_FLAGS value: {{ .Values.configsvr.mongodbExtraFlags | join " " | quote }} {{- end }} {{- if .Values.common.extraEnvVars }} {{- include "common.tplvalues.render" ( dict "value" .Values.common.extraEnvVars "context" $ ) | nindent 12 }} {{- end }} {{- if .Values.configsvr.extraEnvVars }} {{- include "common.tplvalues.render" ( dict "value" .Values.configsvr.extraEnvVars "context" $ ) | nindent 12 }} {{- end }} {{- if or .Values.common.extraEnvVarsCM .Values.common.extraEnvVarsSecret .Values.configsvr.extraEnvVarsCM .Values.configsvr.extraEnvVarsSecret }} envFrom: {{- if .Values.common.extraEnvVarsCM }} - configMapRef: name: {{ include "common.tplvalues.render" ( dict "value" .Values.common.extraEnvVarsCM "context" $ ) }} {{- end }} {{- if .Values.common.extraEnvVarsSecret }} - secretRef: name: {{ include "common.tplvalues.render" ( dict "value" .Values.common.extraEnvVarsSecret "context" $ ) }} {{- end }} {{- if .Values.configsvr.extraEnvVarsCM }} - configMapRef: name: {{ include "common.tplvalues.render" ( dict "value" .Values.configsvr.extraEnvVarsCM "context" $ ) }} {{- end }} {{- if .Values.configsvr.extraEnvVarsSecret }} - secretRef: name: {{ include "common.tplvalues.render" ( dict "value" .Values.configsvr.extraEnvVarsSecret "context" $ ) }} {{- end }} {{- end }} {{- if .Values.diagnosticMode.enabled }} command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }} args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }} {{- else }} {{- if .Values.configsvr.command }} command: {{- include "common.tplvalues.render" (dict "value" .Values.configsvr.command "context" $) | nindent 12 }} {{- end }} {{- if .Values.configsvr.args }} args: {{- include "common.tplvalues.render" (dict "value" .Values.configsvr.args "context" $) | nindent 12 }} {{- end }} {{- if .Values.configsvr.customLivenessProbe }} livenessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.configsvr.customLivenessProbe "context" $) | nindent 12 }} {{- else if .Values.configsvr.livenessProbe.enabled }} livenessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.configsvr.livenessProbe "enabled") "context" $) | nindent 12 }} exec: command: - pgrep - mongod {{- end }} {{- if .Values.configsvr.customReadinessProbe }} readinessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.configsvr.customReadinessProbe "context" $) | nindent 12 }} {{- else if .Values.configsvr.readinessProbe.enabled }} readinessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.configsvr.readinessProbe "enabled") "context" $) | nindent 12 }} exec: command: - /bin/sh - -c - mongosh --port $MONGODB_PORT_NUMBER --eval "db.adminCommand('ping')" {{- end }} {{- if .Values.configsvr.customStartupProbe }} startupProbe: {{- include "common.tplvalues.render" (dict "value" .Values.configsvr.customStartupProbe "context" $) | nindent 12 }} {{- else if .Values.configsvr.startupProbe.enabled }} startupProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.configsvr.startupProbe "enabled") "context" $) | nindent 12 }} tcpSocket: port: mongodb {{- end }} {{- end }} {{- if $.Values.configsvr.lifecycleHooks }} lifecycle: {{- include "common.tplvalues.render" (dict "value" $.Values.configsvr.lifecycleHooks "context" $) | nindent 12 }} {{- end }} volumeMounts: - name: empty-dir mountPath: /tmp subPath: tmp-dir - name: empty-dir mountPath: /opt/bitnami/mongodb/conf subPath: app-conf-dir - name: empty-dir mountPath: /opt/bitnami/mongodb/tmp subPath: app-tmp-dir - name: empty-dir mountPath: /opt/bitnami/mongodb/logs subPath: app-logs-dir - name: empty-dir mountPath: /.mongodb subPath: app-mongosh-dir - name: replicaset-entrypoint-configmap mountPath: /entrypoint - name: datadir mountPath: {{ .Values.configsvr.persistence.mountPath }} {{- if .Values.configsvr.persistence.subPath }} subPath: {{ include "common.tplvalues.render" (dict "value" .Values.configsvr.persistence.subPath "context" $) }} {{- end }} {{- if or .Values.configsvr.config .Values.configsvr.configCM }} - name: config mountPath: /bitnami/mongodb/conf/ {{- end }} {{- if .Values.auth.usePasswordFiles }} - name: secrets mountPath: /bitnami/mongodb/secrets/ {{- end }} {{- if .Values.common.initScriptsCM }} - name: custom-init-scripts-cm mountPath: /docker-entrypoint-initdb.d/cm {{- end }} {{- if .Values.common.initScriptsSecret }} - name: custom-init-scripts-secret mountPath: /docker-entrypoint-initdb.d/secret {{- end }} {{- if .Values.common.extraVolumeMounts }} {{- include "common.tplvalues.render" ( dict "value" .Values.common.extraVolumeMounts "context" $ ) | nindent 12 }} {{- end }} {{- if .Values.configsvr.extraVolumeMounts }} {{- include "common.tplvalues.render" ( dict "value" .Values.configsvr.extraVolumeMounts "context" $ ) | nindent 12 }} {{- end }} {{- if .Values.configsvr.resources }} resources: {{- toYaml .Values.configsvr.resources | nindent 12 }} {{- else if ne .Values.configsvr.resourcesPreset "none" }} resources: {{- include "common.resources.preset" (dict "type" .Values.configsvr.resourcesPreset) | nindent 12 }} {{- end }} {{- if $.Values.pmmMetrics.enabled | default false }} {{- include "mongodb-sharded.pmmClientContainer" $ | nindent 8 }} {{- end }} {{- if .Values.metrics.enabled }} - name: metrics image: {{ include "mongodb-sharded.metrics.image" . }} imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }} {{- if .Values.metrics.containerSecurityContext.enabled }} securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.metrics.containerSecurityContext "context" $) | nindent 12 }} {{- end }} env: {{- if .Values.auth.enabled }} - name: MONGODB_ROOT_USER value: {{ .Values.auth.rootUser | quote }} {{- if .Values.auth.usePasswordFiles }} - name: MONGODB_ROOT_PASSWORD_FILE value: "/bitnami/mongodb/secrets/mongodb-root-password" {{- else }} - name: MONGODB_ROOT_PASSWORD valueFrom: secretKeyRef: name: {{ include "mongodb-sharded.secret" . }} key: mongodb-root-password {{- end }} {{- end }} {{- if .Values.diagnosticMode.enabled }} command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }} args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }} {{- else }} command: - sh - -ec - |- #!/bin/sh {{- if .Values.auth.usePasswordFiles }} export MONGODB_ROOT_PASSWORD="$(cat "${MONGODB_ROOT_PASSWORD_FILE}")" {{- end }} /bin/mongodb_exporter --collect-all --compatible-mode --web.listen-address ":{{ .Values.metrics.containerPorts.metrics }}" --mongodb.uri mongodb://$(echo $MONGODB_ROOT_USER):$(echo $MONGODB_ROOT_PASSWORD | sed -r "s/@/%40/g;s/:/%3A/g")@localhost:{{ .Values.common.containerPorts.mongodb }}/admin{{ ternary "?ssl=true" "" $.Values.metrics.useTLS }} {{ .Values.metrics.extraArgs }} {{- end }} volumeMounts: - name: empty-dir mountPath: /tmp subPath: tmp-dir {{- if .Values.auth.usePasswordFiles }} - name: secrets mountPath: /bitnami/mongodb/secrets/ {{- end }} ports: - name: metrics containerPort: {{ .Values.metrics.containerPorts.metrics }} {{- if not .Values.diagnosticMode.enabled }} {{- if .Values.metrics.customLivenessProbe }} livenessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.customLivenessProbe "context" $) | nindent 12 }} {{- else if .Values.metrics.livenessProbe.enabled }} livenessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.metrics.livenessProbe "enabled") "context" $) | nindent 12 }} tcpSocket: port: metrics {{- end }} {{- if .Values.metrics.customReadinessProbe }} readinessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.customReadinessProbe "context" $) | nindent 12 }} {{- else if .Values.metrics.readinessProbe.enabled }} readinessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.metrics.readinessProbe "enabled") "context" $) | nindent 12 }} httpGet: path: /metrics port: metrics {{- end }} {{- if .Values.metrics.customStartupProbe }} startupProbe: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.customStartupProbe "context" $) | nindent 12 }} {{- else if .Values.metrics.startupProbe.enabled }} startupProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.metrics.startupProbe "enabled") "context" $) | nindent 12 }} tcpSocket: port: metrics {{- end }} {{- end }} {{- if .Values.metrics.resources }} resources: {{- toYaml .Values.metrics.resources | nindent 12 }} {{- else if ne .Values.metrics.resourcesPreset "none" }} resources: {{- include "common.resources.preset" (dict "type" .Values.metrics.resourcesPreset) | nindent 12 }} {{- end }} {{- end }} {{- with .Values.configsvr.sidecars }} {{- include "common.tplvalues.render" ( dict "value" . "context" $ ) | nindent 8 }} {{- end }} {{- with .Values.common.sidecars }} {{- include "common.tplvalues.render" ( dict "value" . "context" $ ) | nindent 8 }} {{- end }} volumes: - name: empty-dir emptyDir: {} - name: replicaset-entrypoint-configmap configMap: name: {{ printf "%s-replicaset-entrypoint" (include "common.names.fullname" .) }} {{- if .Values.auth.usePasswordFiles }} - name: secrets secret: secretName: {{ include "mongodb-sharded.secret" . }} {{- end }} {{- if or .Values.configsvr.config .Values.configsvr.configCM }} - name: config configMap: name: {{ include "mongodb-sharded.configsvr.configCM" . }} {{- end }} {{- if .Values.common.initScriptsCM }} - name: custom-init-scripts-cm configMap: name: {{ include "mongodb-sharded.initScriptsCM" . }} defaultMode: 0755 {{- end }} {{- if .Values.common.initScriptsSecret }} - name: custom-init-scripts-secret secret: secretName: {{ include "mongodb-sharded.initScriptsSecret" . }} defaultMode: 0755 {{- end }} {{- if .Values.common.extraVolumes }} {{- include "common.tplvalues.render" ( dict "value" .Values.common.extraVolumes "context" $ ) | nindent 8 }} {{- end }} {{- if .Values.configsvr.extraVolumes }} {{- include "common.tplvalues.render" ( dict "value" .Values.configsvr.extraVolumes "context" $ ) | nindent 8 }} {{- end }} {{- if not .Values.configsvr.persistence.enabled }} - name: datadir emptyDir: {} {{- else }} {{- if .Values.configsvr.persistentVolumeClaimRetentionPolicy.enabled }} persistentVolumeClaimRetentionPolicy: whenDeleted: {{ .Values.configsvr.persistentVolumeClaimRetentionPolicy.whenDeleted }} whenScaled: {{ .Values.configsvr.persistentVolumeClaimRetentionPolicy.whenScaled }} {{- end }} volumeClaimTemplates: - apiVersion: v1 kind: PersistentVolumeClaim metadata: name: datadir {{- if or .Values.configsvr.persistence.annotations .Values.commonAnnotations .Values.configsvr.persistence.resourcePolicy }} {{- if or .Values.commonAnnotations .Values.configsvr.persistence.annotations .Values.configsvr.persistence.resourcePolicy }} annotations: {{- if .Values.commonAnnotations }} {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 10 }} {{- end }} {{- if .Values.configsvr.persistence.annotations }} {{- include "common.tplvalues.render" ( dict "value" .Values.configsvr.persistence.annotations "context" $) | nindent 10 }} {{- end }} {{- end }} {{- end }} spec: accessModes: {{- range .Values.configsvr.persistence.accessModes }} - {{ . | quote }} {{- end }} resources: requests: storage: {{ .Values.configsvr.persistence.size | quote }} {{- include "common.storage.class" (dict "persistence" .Values.configsvr.persistence "global" .Values.global) | nindent 8 }} {{- end }} {{- end }}