diff --git a/.gitignore b/.gitignore index 4eef7fb5d..63fac3f1e 100644 --- a/.gitignore +++ b/.gitignore @@ -68,6 +68,7 @@ output.txt .vscode # Chart dependencies -/build/charts/yorkie-cluster/charts/*.tgz +**/charts/*.tgz /build/charts/yorkie-argocd/charts/ /build/charts/yorkie-monitoring/charts/ +/build/charts/yorkie-mongodb/charts/ diff --git a/build/charts/yorkie-cluster/charts/mongodb/Chart.yaml b/build/charts/yorkie-cluster/charts/mongodb/Chart.yaml deleted file mode 100644 index cca965a43..000000000 --- a/build/charts/yorkie-cluster/charts/mongodb/Chart.yaml +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: v2 -name: mongodb -description: A mongodb Helm chart dependency for yorkie-cluster - -# 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.1.0 - -# 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. -# It is recommended to use it with quotes. -appVersion: "1.16.0" diff --git a/build/charts/yorkie-cluster/values.yaml b/build/charts/yorkie-cluster/values.yaml index 92f699b2e..0772fa324 100644 --- a/build/charts/yorkie-cluster/values.yaml +++ b/build/charts/yorkie-cluster/values.yaml @@ -1,7 +1,7 @@ # Configuration for Yorkie cluster yorkie: name: yorkie - namespace: &namespace yorkie + namespace: yorkie autoscaling: enabled: false @@ -13,8 +13,8 @@ yorkie: tag: "" args: - dbUrl: &mongoUrl mongodb - dbPort: &mongoPort 27017 + dbUrl: mongodb.mongodb.svc.cluster.local + dbPort: 27017 ports: rpcPort: 8080 @@ -22,17 +22,6 @@ yorkie: resources: {} -# Configuration for internal mongoDB -mongodb: - enabled: true - - namespace: *namespace - name: *mongoUrl - port: *mongoPort - - storageClassName: standard - storageSize: 1Gi - # Configuration for istio ingress gateway ingressGateway: consistentHash: @@ -43,7 +32,7 @@ ingressGateway: maglev: enabled: true tableSize: 65537 - + ringHash: enabled: false minimumRingSize: 1024 @@ -63,7 +52,7 @@ ingress: hosts: enabled: false apiHost: api.yorkie.dev - + alb: enabled: false certArn: arn:aws:acm:ap-northeast-2:123412341234:certificate/1234-1234-1234-1234-1234 diff --git a/build/charts/yorkie-cluster/charts/mongodb/.helmignore b/build/charts/yorkie-mongodb/.helmignore similarity index 100% rename from build/charts/yorkie-cluster/charts/mongodb/.helmignore rename to build/charts/yorkie-mongodb/.helmignore diff --git a/build/charts/yorkie-mongodb/Chart.lock b/build/charts/yorkie-mongodb/Chart.lock new file mode 100644 index 000000000..397448d5d --- /dev/null +++ b/build/charts/yorkie-mongodb/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: mongodb-sharded + repository: https://charts.bitnami.com/bitnami + version: 7.2.2 +digest: sha256:ae306fa705473ca5e99f02fcca27ebb5900cf4bdf4357472f8b5006c9c4fca24 +generated: "2024-01-23T20:44:36.400805+09:00" diff --git a/build/charts/yorkie-mongodb/Chart.yaml b/build/charts/yorkie-mongodb/Chart.yaml new file mode 100644 index 000000000..44d510740 --- /dev/null +++ b/build/charts/yorkie-mongodb/Chart.yaml @@ -0,0 +1,20 @@ +apiVersion: v2 +name: yorkie-mongodb +description: yorkie-mongodb provides the deployment of MongoDB for the yorkie server, supporting both standalone mode and sharded cluster mode. +type: application +icon: https://raw.githubusercontent.com/yorkie-team/yorkie-team.github.io/main/public/favicon-512x512.png +maintainers: + - name: hackerwins + email: susukang98@gmail.com + - name: krapie + email: krapi0314@gmail.com + +version: 0.4.13 +appVersion: "0.4.13" +kubeVersion: ">=1.23.0-0" + +dependencies: + - name: mongodb-sharded + version: "7.2.2" + repository: "https://charts.bitnami.com/bitnami" + condition: sharded.enabled diff --git a/build/charts/yorkie-mongodb/README.md b/build/charts/yorkie-mongodb/README.md new file mode 100644 index 000000000..eed6956fb --- /dev/null +++ b/build/charts/yorkie-mongodb/README.md @@ -0,0 +1,70 @@ +# yorkie-mongodb + +Installs MongoDB for the yorkie server, supporting both standalone mode and sharded cluster mode for storing yorkie data. + +## Prerequisites + +- Kubernetes 1.24+ +- Helm 3+ + +## Get Helm Repository Info + +```bash +helm repo add yorkie-team https://yorkie-team.github.io/yorkie/helm-charts +helm repo update +``` + +_See [`helm repo`](https://helm.sh/docs/helm/helm_repo/) for command documentation._ + +## Install Helm Chart + +```bash +# Create mongodb namespace +kubectl create namespace mongodb + +# Install yorkie monitoring helm chart +helm install [RELEASE_NAME] yorkie-team/yorkie-mongodb --namespace mongodb --set=sharded.enabled=true +``` + +_See [configuration](#configuration) below for custom installation_ + +_See [`helm install`](https://helm.sh/docs/helm/helm_install/) for command documentation._ + +## Dependencies + +By default this chart installs additional, dependent charts: + +- [mongodb-sharded](https://github.com/bitnami/charts/tree/main/bitnami/mongodb-sharded) + +_See [`helm dependency`](https://helm.sh/docs/helm/helm_dependency/) for command documentation._ + +## Uninstall Helm Chart + +```bash +helm uninstall [RELEASE_NAME] -n mongodb +``` + +This removes all the Kubernetes components associated with the chart and deletes the release. + +_See [`helm uninstall`](https://helm.sh/docs/helm/helm_uninstall/) for command documentation._ + +## Upgrading Chart + +```bash +helm upgrade [RELEASE_NAME] yorkie-team/yorkie-mongodb -n mongodb +``` + +With Helm v3, CRDs created by this chart are not updated by default and should be manually updated. +Consult also the [Helm Documentation on CRDs](https://helm.sh/docs/chart_best_practices/custom_resource_definitions). + +_See [`helm upgrade`](https://helm.sh/docs/helm/helm_upgrade/) for command documentation._ + +## Configuration + +See [Customizing the Chart Before Installing](https://helm.sh/docs/intro/using_helm/#customizing-the-chart-before-installing). To see all configurable options with detailed comments: + +```console +helm show values yorkie-team/yorkie-mongodb +``` + +You may also `helm show values` on this chart's [dependencies](#dependencies) for additional options. diff --git a/build/charts/yorkie-mongodb/templates/NOTES.txt b/build/charts/yorkie-mongodb/templates/NOTES.txt new file mode 100644 index 000000000..4c95465ea --- /dev/null +++ b/build/charts/yorkie-mongodb/templates/NOTES.txt @@ -0,0 +1,9 @@ +--- Install Complete --- +{{ .Release.Name }} successfully installed! + +For next steps, follow: + $ curl https://github.com/yorkie-team/yorkie/tree/main/charts/yorkie-mongodb + +To learn more about the release, try: + $ helm status {{ .Release.Name }} + $ helm get all {{ .Release.Name }} diff --git a/build/charts/yorkie-mongodb/templates/sharded/_helpers.tpl b/build/charts/yorkie-mongodb/templates/sharded/_helpers.tpl new file mode 100644 index 000000000..6bf8c8e87 --- /dev/null +++ b/build/charts/yorkie-mongodb/templates/sharded/_helpers.tpl @@ -0,0 +1,31 @@ +{{- define "configReplName" -}} +{{- $name := index . 0 -}} +{{- printf "%s-configsvr" $name -}} +{{- end -}} + +{{- define "configReplAddr" -}} +{{- $name := index . 0 -}} +{{- $replIndex := index . 1 -}} +{{- $domainSuffix := index . 2 -}} +{{- printf "%s-configsvr-%d.%s-headless.%s" $name $replIndex $name $domainSuffix -}} +{{- end -}} + +{{- define "shardReplName" -}} +{{- $name := index . 0 -}} +{{- $index := index . 1 -}} +{{- printf "%s-shard-%d" $name $index -}} +{{- end -}} + +{{- define "shardReplAddr" -}} +{{- $name := index . 0 -}} +{{- $shardIndex := index . 1 -}} +{{- $replIndex := index . 2 -}} +{{- $domainSuffix := index . 3 -}} +{{- printf "%s-shard%d-data-%d.%s-headless.%s" $name $shardIndex $replIndex $name $domainSuffix -}} +{{- end -}} + +{{- define "mongosAddr" -}} +{{- $name := index . 0 -}} +{{- $domainSuffix := index . 1 -}} +{{- printf "%s-mongos-0.%s.%s" $name $name $domainSuffix -}} +{{- end -}} diff --git a/build/charts/yorkie-mongodb/templates/sharded/configmap.yaml b/build/charts/yorkie-mongodb/templates/sharded/configmap.yaml new file mode 100644 index 000000000..200de93d7 --- /dev/null +++ b/build/charts/yorkie-mongodb/templates/sharded/configmap.yaml @@ -0,0 +1,69 @@ +{{- if and .Values.sharded.enabled .Values.sharded.setup.enabled }} +{{- $domainSuffix := printf "%s.svc.%s:%d" $.Values.namespace $.Values.clusterDomain ($.Values.port | int ) }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Values.name }}-setup-script + namespace: {{ .Values.namespace }} + labels: + app.kubernetes.io/component: mongodb + app.kubernetes.io/part-of: yorkie +data: + setup.sh: | + #!/bin/bash + + function waitUntilReady { + while true; do + mongosh $1 --quiet --eval "db.runCommand('ping').ok" + if [ $? -eq 0 ]; then + break + fi + sleep 5 + done + } + + {{ $configsvrAddr := include "configReplAddr" (list $.Values.name 0 $domainSuffix) }} + echo "Wait until config server is ready..." + configsvrAddr="{{ $configsvrAddr }}" + echo "Config server address: ${configsvrAddr}" + waitUntilReady $configsvrAddr + echo "Configure config server" + mongosh $configsvrAddr --eval 'rs.initiate({"_id":"{{ include "configReplName" (list $.Values.name) }}", "members":[{"_id":0,"host":"{{ $configsvrAddr }}","priority":5}]})' + + {{ range $i, $e := until ($.Values.sharded.shards | int) }} + {{ $shardsvrAddr := include "shardReplAddr" (list $.Values.name $i 0 $domainSuffix) }} + echo "{{ printf "Wait until shard%d is ready..." $i }}" + shardsvrAddr="{{ $shardsvrAddr }}" + echo "{{ printf "Shard%d address: %s" $i $shardsvrAddr }}" + waitUntilReady $shardsvrAddr + echo "{{ printf "Configure shard%d" $i }}" + mongosh $shardsvrAddr --eval 'rs.initiate({"_id":"{{ include "shardReplName" (list $.Values.name $i) }}", "members":[{"_id":0,"host":"{{ $shardsvrAddr }}","priority":5}]})' + {{ end }} + + {{ $mongosAddr := include "mongosAddr" (list $.Values.name $domainSuffix) }} + echo "Wait until mongos is ready..." + mongosAddr="{{ $mongosAddr }}" + echo "Mongos address: ${mongosAddr}" + waitUntilReady $mongosAddr + echo "Configure mongos" + mongosh $mongosAddr --eval <