mirror of
https://github.com/bitnami/charts.git
synced 2026-08-10 14:15:55 +08:00
[bitnami/mongodb] Fix validations and Autodiscovery (#25283)
* [bitnami/mongodb] Fix validations and Autodiscovery Signed-off-by: Fran Mulero <fmulero@vmware.com> * Version bump Signed-off-by: Fran Mulero <fmulero@vmware.com> --------- Signed-off-by: Fran Mulero <fmulero@vmware.com>
This commit is contained in:
@@ -39,4 +39,4 @@ maintainers:
|
||||
name: mongodb
|
||||
sources:
|
||||
- https://github.com/bitnami/charts/tree/main/bitnami/mongodb
|
||||
version: 15.1.4
|
||||
version: 15.1.5
|
||||
|
||||
@@ -33,38 +33,6 @@ In order to replicate the container startup scripts execute this command:
|
||||
{{- $mongoList = append $mongoList (printf "%s-%d.%s-headless.%s.svc.%s:%d" $fullname $i $fullname $releaseNamespace $clusterDomain $portNumber) }}
|
||||
{{- end }}
|
||||
|
||||
{{- if and (eq .Values.architecture "replicaset") .Values.externalAccess.enabled (not .Values.externalAccess.autoDiscovery.enabled) (not (eq $replicaCount $loadBalancerIPListLength )) (eq .Values.externalAccess.service.type "LoadBalancer") }}
|
||||
|
||||
####################################################################################
|
||||
### ERROR: You enabled external access to MongoDB® nodes without specifying ###
|
||||
### the array of load balancer IPs for MongoDB® nodes. ###
|
||||
####################################################################################
|
||||
|
||||
This deployment will be incomplete until you configure the array of load balancer
|
||||
IPs for MongoDB® nodes. To complete your deployment follow the steps below:
|
||||
|
||||
1. Wait for the load balancer IPs (it may take a few minutes for them to be available):
|
||||
|
||||
kubectl get svc --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ template "mongodb.name" . }},app.kubernetes.io/instance={{ .Release.Name }},app.kubernetes.io/component=mongodb" -w
|
||||
|
||||
2. Obtain the load balancer IPs and upgrade your chart:
|
||||
|
||||
{{- range $e, $i := until $replicaCount }}
|
||||
LOAD_BALANCER_IP_{{ add $i 1 }}="$(kubectl get svc --namespace {{ $releaseNamespace }} {{ $fullname }}-{{ $i }}-external -o jsonpath='{.status.loadBalancer.ingress[0].ip}')"
|
||||
{{- end }}
|
||||
|
||||
3. Upgrade you chart:
|
||||
|
||||
helm upgrade --namespace {{ .Release.Namespace }} {{ .Release.Name }} oci://registry-1.docker.io/bitnamicharts/{{ .Chart.Name }} \
|
||||
--set mongodb.replicaCount={{ $replicaCount }} \
|
||||
--set mongodb.externalAccess.enabled=true \
|
||||
{{- range $i, $e := until $replicaCount }}
|
||||
--set mongodb.externalAccess.service.loadBalancerIPs[{{ $i }}]=$LOAD_BALANCER_IP_{{ add $i 1 }} \
|
||||
{{- end }}
|
||||
--set mongodb.externalAccess.service.type=LoadBalancer
|
||||
|
||||
{{- else }}
|
||||
|
||||
{{- if and (or (and (eq .Values.architecture "standalone") (or (eq .Values.service.type "LoadBalancer") (eq .Values.service.type "NodePort"))) (and (eq .Values.architecture "replicaset") .Values.externalAccess.enabled)) (not .Values.auth.enabled) }}
|
||||
-------------------------------------------------------------------------------
|
||||
WARNING
|
||||
@@ -72,7 +40,7 @@ IPs for MongoDB® nodes. To complete your deployment follow the steps below:
|
||||
By not enabling "mongodb.auth.enabled" you have most likely exposed the
|
||||
MongoDB® service externally without any authentication mechanism.
|
||||
|
||||
For security reasons, we strongly suggest that you enable authentiation
|
||||
For security reasons, we strongly suggest that you enable authentication
|
||||
setting the "mongodb.auth.enabled" parameter to "true".
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
@@ -108,7 +76,6 @@ To get the password for "{{ $user }}" run:
|
||||
export MONGODB_PASSWORD=$(kubectl get secret --namespace {{ include "mongodb.namespace" $ }} {{ include "mongodb.secretName" $ }} -o jsonpath="{.data.mongodb-passwords}" | base64 -d | awk -F',' '{print ${{ add 1 $index }}}')
|
||||
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
To connect to your database, create a MongoDB® client container:
|
||||
|
||||
|
||||
@@ -294,6 +294,7 @@ Compile all warnings into a single message, and call fail.
|
||||
{{- $messages := append $messages (include "mongodb.validateValues.loadBalancerIPsListLength" .) -}}
|
||||
{{- $messages := append $messages (include "mongodb.validateValues.nodePortListLength" .) -}}
|
||||
{{- $messages := append $messages (include "mongodb.validateValues.externalAccessAutoDiscoveryRBAC" .) -}}
|
||||
{{- $messages := append $messages (include "mongodb.validateValues.externalAccessAutoDiscoverySA" .) -}}
|
||||
{{- $messages := append $messages (include "mongodb.validateValues.replicaset.existingSecrets" .) -}}
|
||||
{{- $messages := append $messages (include "mongodb.validateValues.hidden.existingSecrets" .) -}}
|
||||
{{- $messages := without $messages "" -}}
|
||||
@@ -364,9 +365,14 @@ Validate values of MongoDB® - number of replicas must be the same than LoadB
|
||||
{{- define "mongodb.validateValues.loadBalancerIPsListLength" -}}
|
||||
{{- $replicaCount := int .Values.replicaCount }}
|
||||
{{- $loadBalancerListLength := len .Values.externalAccess.service.loadBalancerIPs }}
|
||||
{{- if and (eq .Values.architecture "replicaset") .Values.externalAccess.enabled (not .Values.externalAccess.autoDiscovery.enabled ) (eq .Values.externalAccess.service.type "LoadBalancer") (not (eq $replicaCount $loadBalancerListLength )) -}}
|
||||
{{- if and (eq .Values.architecture "replicaset") .Values.externalAccess.enabled (eq .Values.externalAccess.service.type "LoadBalancer") -}}
|
||||
{{- if and (not .Values.externalAccess.autoDiscovery.enabled) (eq $loadBalancerListLength 0) -}}
|
||||
mongodb: .Values.externalAccess.service.loadBalancerIPs
|
||||
Number of replicas and loadBalancerIPs array length must be the same.
|
||||
externalAccess.service.loadBalancerIPs or externalAccess.autoDiscovery.enabled are required when externalAccess is enabled.
|
||||
{{- else if and (not .Values.externalAccess.autoDiscovery.enabled) (not (eq $replicaCount $loadBalancerListLength )) -}}
|
||||
mongodb: .Values.externalAccess.service.loadBalancerIPs
|
||||
Number of replicas ({{ $replicaCount }}) and loadBalancerIPs ({{ $loadBalancerListLength }}) array length must be the same.
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
@@ -376,9 +382,14 @@ Validate values of MongoDB® - number of replicas must be the same than NodeP
|
||||
{{- define "mongodb.validateValues.nodePortListLength" -}}
|
||||
{{- $replicaCount := int .Values.replicaCount }}
|
||||
{{- $nodePortListLength := len .Values.externalAccess.service.nodePorts }}
|
||||
{{- if and (eq .Values.architecture "replicaset") .Values.externalAccess.enabled (eq .Values.externalAccess.service.type "NodePort") (not (eq $replicaCount $nodePortListLength )) -}}
|
||||
{{- if and (eq .Values.architecture "replicaset") .Values.externalAccess.enabled (eq .Values.externalAccess.service.type "NodePort") -}}
|
||||
{{- if and (not .Values.externalAccess.autoDiscovery.enabled) (eq $nodePortListLength 0) -}}
|
||||
mongodb: .Values.externalAccess.service.loadBalancerIPs
|
||||
externalAccess.service.loadBalancerIPs or externalAccess.autoDiscovery.enabled are required when externalAccess is enabled.
|
||||
{{- else if and (not .Values.externalAccess.autoDiscovery.enabled) (not (eq $replicaCount $nodePortListLength )) -}}
|
||||
mongodb: .Values.externalAccess.service.nodePorts
|
||||
Number of replicas and nodePorts array length must be the same.
|
||||
Number of replicas ({{ $replicaCount }}) and nodePorts ({{ $nodePortListLength }}) array length must be the same.
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
@@ -395,6 +406,19 @@ mongodb: rbac.create
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/*
|
||||
Validate values of MongoDB® - automountServiceAccountToken should be enabled when autoDiscovery is enabled
|
||||
*/}}
|
||||
{{- define "mongodb.validateValues.externalAccessAutoDiscoverySA" -}}
|
||||
{{- if and (eq .Values.architecture "replicaset") .Values.externalAccess.enabled .Values.externalAccess.autoDiscovery.enabled (not .Values.automountServiceAccountToken ) }}
|
||||
mongodb: automountServiceAccountToken
|
||||
By specifying "externalAccess.enabled=true" and "externalAccess.autoDiscovery.enabled=true"
|
||||
an initContainer will be used to autodetect the external IPs/ports by querying the
|
||||
K8s API. Please note this initContainer requires a service account to access K8S API.
|
||||
You can attach it to the pod by specifying "--set automountServiceAccountToken=true".
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/*
|
||||
Validate values of MongoDB® - Number of replicaset secrets must be the same than number of replicaset nodes.
|
||||
*/}}
|
||||
|
||||
@@ -41,6 +41,21 @@ spec:
|
||||
to:
|
||||
- podSelector:
|
||||
matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 14 }}
|
||||
{{- if (and .Values.externalAccess.enabled .Values.externalAccess.autoDiscovery.enabled) }}
|
||||
{{- $kubernetesEndpoints := lookup "v1" "Endpoints" (include "common.names.namespace" .) "kubernetes" }}
|
||||
{{- range $kubernetesEndpoints.subsets }}
|
||||
# Allow connection to API server, required by auto-discovery containers
|
||||
- ports:
|
||||
{{- range .ports }}
|
||||
- port: {{ .port }}
|
||||
{{- end }}
|
||||
to:
|
||||
{{- range .addresses }}
|
||||
- ipBlock:
|
||||
cidr: {{ printf "%s/32" .ip }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if .Values.networkPolicy.extraEgress }}
|
||||
{{- include "common.tplvalues.render" ( dict "value" .Values.rts.networkPolicy.extraEgress "context" $ ) | nindent 4 }}
|
||||
{{- end }}
|
||||
|
||||
Reference in New Issue
Block a user