diff --git a/charts/mongodb/Chart.yaml b/charts/mongodb/Chart.yaml new file mode 100644 index 0000000..3a8550f --- /dev/null +++ b/charts/mongodb/Chart.yaml @@ -0,0 +1,39 @@ +apiVersion: v2 +name: mongodb +description: NoSQL document-oriented database that stores JSON-like documents with dynamic schemas. +icon: https://minio.lab.sspcloud.fr/projet-onyxia/assets/servicesImg/mongodb.png +keywords: + - nosql + - Database + - json +home: https://www.mongodb.com/ +sources: + - https://github.com/InseeFrLab/helm-charts-datascience/tree/master/charts/mongodb + - https://github.com/bitnami/charts/tree/master/bitnami/mongodb + - https://github.com/bitnami/bitnami-docker-mongodb +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.2.3 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +appVersion: "1" +dependencies: + - name: mongodb + version: 14.12.3 + repository: https://charts.bitnami.com/bitnami + - name: library-chart + version: 1.5.21 + repository: https://inseefrlab.github.io/helm-charts-interactive-services diff --git a/charts/mongodb/README.md b/charts/mongodb/README.md new file mode 100644 index 0000000..4d92a1c --- /dev/null +++ b/charts/mongodb/README.md @@ -0,0 +1,40 @@ +# mongodb + +![Version: 0.2.3](https://img.shields.io/badge/Version-0.2.3-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1](https://img.shields.io/badge/AppVersion-1-informational?style=flat-square) + +NoSQL document-oriented database that stores JSON-like documents with dynamic schemas. + +**Homepage:** + +## Source Code + +* +* +* + +## Requirements + +| Repository | Name | Version | +|------------|------|---------| +| https://charts.bitnami.com/bitnami | mongodb | 13.18.5 | +| https://inseefrlab.github.io/helm-charts-interactive-services | library-chart | 1.5.18 | + +## Values + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| fullnameOverride | string | `"mongodb"` | | +| mongodb.architecture | string | `"replicaset"` | | +| mongodb.auth.database | string | `"defaultdb"` | | +| mongodb.auth.password | string | `"changeme"` | | +| mongodb.auth.rootPassword | string | `"changeme"` | | +| mongodb.auth.username | string | `"username"` | | +| mongodb.discoverable.allow | bool | `true` | | +| mongodb.fullnameOverride | string | `"mongodb"` | | +| mongodb.image.tag | string | `"4.4"` | | +| mongodb.replicaCount | int | `2` | | +| mongodb.resources | object | `{}` | | +| security.networkPolicy.enabled | bool | `true` | | + +---------------------------------------------- +Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0) diff --git a/charts/mongodb/templates/NOTES.txt b/charts/mongodb/templates/NOTES.txt new file mode 100644 index 0000000..b14acf7 --- /dev/null +++ b/charts/mongodb/templates/NOTES.txt @@ -0,0 +1,36 @@ +{{- $replicaCount := int .Values.mongodb.replicaCount }} +{{- $portNumber := int .Values.mongodb.service.ports.mongodb }} +{{- $fullname := include "library-chart.fullname" . }} +{{- $user := .Values.mongodb.auth.username }} +{{- $password := .Values.mongodb.auth.password }} +{{- $rootPassword := .Values.mongodb.auth.rootPassword }} +{{- $db := .Values.mongodb.auth.database }} +{{- $pvcList := list }} +{{- $mongoList := list }} +{{- range $e, $i := until $replicaCount }} +{{- $pvcList = append $pvcList (printf "datadir-%s-%d" $fullname $i) }} +{{- $mongoList = append $mongoList (printf "%s-%d.%s-headless:%d" $fullname $i $fullname $portNumber) }} +{{- end }} +- the connection string is : + +**`mongodb://{{ $user }}:{{ $password }}@{{ (include "mongoList" .)}}/{{ $db }}?authSource={{ $db }}`** +- example for python : + +``` +from pymongo import MongoClient +client = MongoClient('mongodb://{{ $user }}:{{ $password }}@{{ (include "mongoList" .) }}/{{ $db }}') +db=client.{{ $db }} +``` +- example for mongosh : + + * as user in {{ $db }} + `mongo -u {{ $user }} -p {{ $password }} --authenticationDatabase {{ $db }}` + * as root + `mongo -u root -p {{ $rootPassword }}` + +*NOTES about deletion :* + +- **You can safely delete this chart and recreate one later** +- Data volumes will not be deleted +- If you start a new {{ .Chart.Name }}, it will reuse those volumes silently. +- If you want to delete those volume definitily : `kubectl delete pvc {{ join " " $pvcList }}` \ No newline at end of file diff --git a/charts/mongodb/templates/_helpers.tpl b/charts/mongodb/templates/_helpers.tpl new file mode 100644 index 0000000..3599cf2 --- /dev/null +++ b/charts/mongodb/templates/_helpers.tpl @@ -0,0 +1,10 @@ +{{- define "mongoList" -}} +{{- $replicaCount := int .Values.mongodb.replicaCount }} +{{- $portNumber := int .Values.mongodb.service.ports.mongodb }} +{{- $fullname := include "library-chart.fullname" . }} +{{- $mongoList := list }} +{{- range $e, $i := until $replicaCount }} +{{- $mongoList = append $mongoList (printf "%s-%d.%s-headless:%d" $fullname $i $fullname $portNumber) }} +{{- end }} +{{- printf "%s" (join "," $mongoList) -}} +{{- end }} diff --git a/charts/mongodb/templates/discovery-secret.yaml b/charts/mongodb/templates/discovery-secret.yaml new file mode 100644 index 0000000..4aef021 --- /dev/null +++ b/charts/mongodb/templates/discovery-secret.yaml @@ -0,0 +1,27 @@ +{{- if .Values.mongodb.discoverable.allow }} +{{- $fullname := include "library-chart.fullname" . }} +{{- $secretName := printf "%s-%s" "discoverable" $fullname -}} +apiVersion: v1 +kind: Secret +metadata: + name: {{ $secretName }} + annotations: + onyxia/discovery: "mongodb" +type: Opaque +data: + mongodb-service: {{ (include "mongoList" .) | b64enc | quote }} + mongodb-name: {{ printf "%s" $fullname | b64enc | quote }} + {{- if .Values.mongodb.auth.password }} + mongodb-password: {{ .Values.mongodb.auth.password | b64enc | quote }} + {{- end }} + {{- if .Values.mongodb.auth.username }} + mongodb-username: {{ .Values.mongodb.auth.username | b64enc | quote }} + {{- end }} + {{- if .Values.mongodb.auth.database }} + mongodb-database: {{ .Values.mongodb.auth.database | b64enc | quote }} + {{- end }} + {{- if .Values.mongodb.auth.rootPassword }} + mongodb-rootPassword: {{ .Values.mongodb.auth.rootPassword | b64enc | quote }} + {{- end }} + +{{- end -}} diff --git a/charts/mongodb/templates/tests/test-db-connection-custom-user.yaml b/charts/mongodb/templates/tests/test-db-connection-custom-user.yaml new file mode 100644 index 0000000..7a6b04b --- /dev/null +++ b/charts/mongodb/templates/tests/test-db-connection-custom-user.yaml @@ -0,0 +1,28 @@ +{{- if .Values.mongodb.auth.enabled }} +{{- if not (empty .Values.mongodb.auth.username) }} +{{- if not (empty .Values.mongodb.auth.password) }} +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "library-chart.fullname" . }}-test-db-connection-custom-user" + labels: + {{- include "library-chart.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test + "helm.sh/hook-delete-policy": hook-succeeded +spec: + containers: + - name: {{ include "library-chart.fullname" . }}-test-connection-custom-user + image: "bitnami/mongodb:7.0.2" + env: + - name: DATABASE_NAME + value: {{ .Values.mongodb.auth.database }} + - name: USER + value: {{ .Values.mongodb.auth.username }} + - name: PASSWORD + value: {{ .Values.mongodb.auth.password }} + command: ["sh", "-c", " mongosh mongodb://$USER:$PASSWORD@{{ include "mongoList" . }}/$DATABASE_NAME?authSource=$DATABASE_NAME" ] + restartPolicy: Never +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/mongodb/templates/tests/test-db-connection-root-user.yaml b/charts/mongodb/templates/tests/test-db-connection-root-user.yaml new file mode 100644 index 0000000..69337f9 --- /dev/null +++ b/charts/mongodb/templates/tests/test-db-connection-root-user.yaml @@ -0,0 +1,25 @@ +{{- if .Values.mongodb.auth.enabled }} +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "library-chart.fullname" . }}-test-db-connection-root-user" + labels: + {{- include "library-chart.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test + "helm.sh/hook-delete-policy": hook-succeeded +spec: + containers: + - name: {{ include "library-chart.fullname" . }}-test-connection-root-user + image: "bitnami/mongodb:7.0.2" + env: + - name: ROOT_USER + value: {{ .Values.mongodb.auth.rootUser }} + - name: PASSWORD + valueFrom: + secretKeyRef: + name: {{ include "library-chart.fullname" . }} + key: mongodb-root-password + command: ["sh", "-c", " mongosh mongodb://$ROOT_USER:$PASSWORD@{{ include "mongoList" . }}/?authSource=admin "] + restartPolicy: Never +{{- end }} diff --git a/charts/mongodb/values.schema.json b/charts/mongodb/values.schema.json new file mode 100644 index 0000000..4c5da8d --- /dev/null +++ b/charts/mongodb/values.schema.json @@ -0,0 +1,193 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "mongodb": { + "description": "mongodb specific configuration", + "type": "object", + "properties": { + "image": { + "description": "image specific configuration", + "type": "object", + "properties": { + "tag": { + "description": "mongodb major version", + "type": "string", + "enum": ["4.0", "4.2", "4.4"], + "default": "4.4" + } + } + }, + "auth": { + "description": "auth specific configuration", + "type": "object", + "properties": { + "rootPassword": { + "description": "root password", + "type": "string", + "default": "changeme", + "x-form": { + "value": "{{project.password}}" + }, + "x-onyxia": { + "overwriteDefaultWith": "{{project.password}}" + } + }, + "database": { + "description": "default db", + "type": "string", + "default": "defaultdb" + }, + "username": { + "description": "user name of the default database", + "type": "string", + "default": "user", + "x-form": { + "value": "{{project.id}}" + }, + "x-onyxia": { + "overwriteDefaultWith": "{{project.id}}" + } + }, + "password": { + "description": "password of the user", + "type": "string", + "default": "changeme", + "x-form": { + "value": "{{project.password}}" + }, + "x-onyxia": { + "overwriteDefaultWith": "{{project.password}}" + } + } + } + }, + "persistence": { + "description": "Configuration for persistence", + "type": "object", + "properties": { + "enabled": { + "type": "boolean", + "description": "Create a persistent volume", + "default": true + }, + "size": { + "type": "string", + "title": "Persistent volume size", + "description": "Size of the persistent volume", + "default": "10Gi", + "form": true, + "render": "slider", + "sliderMin": 1, + "sliderMax": 100, + "sliderStep": 1, + "sliderUnit": "Gi", + "hidden": { + "value": false, + "path": "mongodb/persistence/enabled" + } + } + } + }, + "resources": { + "description": "Your service will have at least the requested resources and never more than its limits. No limit for a resource and you can consume everything left on the host machine.", + "type": "object", + "properties": { + "requests": { + "description": "Guaranteed resources", + "type": "object", + "properties": { + "cpu": { + "description": "The amount of cpu guaranteed", + "title": "CPU", + "type": "string", + "default": "100m", + "render": "slider", + "sliderMin": 50, + "sliderMax": 40000, + "sliderStep": 50, + "sliderUnit": "m", + "sliderExtremity": "down", + "sliderExtremitySemantic": "guaranteed", + "sliderRangeId": "cpu" + }, + "memory": { + "description": "The amount of memory guaranteed", + "title": "memory", + "type": "string", + "default": "2Gi", + "render": "slider", + "sliderMin": 1, + "sliderMax": 200, + "sliderStep": 1, + "sliderUnit": "Gi", + "sliderExtremity": "down", + "sliderExtremitySemantic": "guaranteed", + "sliderRangeId": "memory" + } + } + }, + "limits": { + "description": "max resources", + "type": "object", + "properties": { + "cpu": { + "description": "The maximum amount of cpu", + "title": "CPU", + "type": "string", + "default": "30000m", + "render": "slider", + "sliderMin": 50, + "sliderMax": 40000, + "sliderStep": 50, + "sliderUnit": "m", + "sliderExtremity": "up", + "sliderExtremitySemantic": "Maximum", + "sliderRangeId": "cpu" + }, + "memory": { + "description": "The maximum amount of memory", + "title": "Memory", + "type": "string", + "default": "50Gi", + "render": "slider", + "sliderMin": 1, + "sliderMax": 200, + "sliderStep": 1, + "sliderUnit": "Gi", + "sliderExtremity": "up", + "sliderExtremitySemantic": "Maximum", + "sliderRangeId": "memory" + } + } + } + } + } + } + }, + "security": { + "description": "security specific configuration", + "type": "object", + "properties": { + "networkPolicy": { + "type": "object", + "description": "Define access policy to the service", + "properties": { + "enabled": { + "type": "boolean", + "title": "Enable network policy", + "description": "Only pod from the same namespace will be allowed", + "default": true, + "x-form": { + "value": "{{region.defaultNetworkPolicy}}" + }, + "x-onyxia": { + "overwriteDefaultWith": "region.defaultNetworkPolicy" + } + } + } + } + } + } + } +} diff --git a/charts/mongodb/values.yaml b/charts/mongodb/values.yaml new file mode 100644 index 0000000..05dded5 --- /dev/null +++ b/charts/mongodb/values.yaml @@ -0,0 +1,111 @@ +mongodb: + resources: {} + fullnameOverride: mongodb + architecture: replicaset + useStatefulSet: true + image: + tag: "4.4" + auth: + rootPassword: changeme + username: username + password: changeme + database: defaultdb + replicaCount: 2 + discoverable: + allow: true + configuration: |- + # where and how to store data. + storage: + dbPath: /bitnami/mongodb/data/db + journal: + enabled: true + directoryPerDB: false + + # where to write logging data + systemLog: + destination: file + quiet: false + logAppend: true + logRotate: reopen + path: /opt/bitnami/mongodb/logs/mongodb.log + verbosity: 0 + + # network interfaces + net: + port: 27017 + unixDomainSocket: + enabled: true + pathPrefix: /opt/bitnami/mongodb/tmp + ipv6: false + bindIpAll: true + + # replica set options + #replication: + # replSetName: replicaset + # enableMajorityReadConcern: true + + # process management options + processManagement: + fork: false + pidFilePath: /opt/bitnami/mongodb/tmp/mongodb.pid + + # set parameter options + setParameter: + enableLocalhostAuthBypass: true + + # security options + #security: + # authorization: enabled + # keyFile: /opt/bitnami/mongodb/conf/keyfile + + arbiter: + enabled: true + configuration: |- + # where and how to store data. + storage: + dbPath: /bitnami/mongodb/data/db + journal: + enabled: true + directoryPerDB: false + + # where to write logging data + systemLog: + destination: file + quiet: false + logAppend: true + logRotate: reopen + path: /opt/bitnami/mongodb/logs/mongodb.log + verbosity: 0 + + # network interfaces + net: + port: 27017 + unixDomainSocket: + enabled: true + pathPrefix: /opt/bitnami/mongodb/tmp + ipv6: false + bindIpAll: true + + # replica set options + #replication: + # replSetName: replicaset + # enableMajorityReadConcern: true + + # process management options + processManagement: + fork: false + pidFilePath: /opt/bitnami/mongodb/tmp/mongodb.pid + + # set parameter options + setParameter: + enableLocalhostAuthBypass: true + + # security options + #security: + # authorization: disabled + # keyFile: /opt/bitnami/mongodb/conf/keyfile + + networkPolicy: + enabled: true + +fullnameOverride: mongodb \ No newline at end of file