Skip to content

Commit

Permalink
Merge pull request #80 from StackStorm/enhancement/mongodb-replicaset…
Browse files Browse the repository at this point in the history
…-url

Compose MongoDB-HA cluster connection string for many nodes
  • Loading branch information
armab authored Aug 26, 2019
2 parents be47ae5 + f4004dc commit 93fe06e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## v0.20.0
* Add option to disable MongoDB and RabbitMQ in-cluster deployment and configuration (#79)
* Compose multi-node connection string for MongoDB cluster instead of using loadbalancer single host (#80)

## v0.19.0
* Configure RabbitMQ Queue mirroring by default, see https://www.rabbitmq.com/ha.html (#78)
Expand Down
2 changes: 1 addition & 1 deletion Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
# Update StackStorm version here to rely on other Docker images tags
appVersion: 3.2dev
name: stackstorm-ha
version: 0.19.0
version: 0.20.0
description: StackStorm K8s Helm Chart, optimized for running StackStorm in HA environment.
home: https://stackstorm.com/#product
icon: https://avatars1.githubusercontent.com/u/4969009
Expand Down
2 changes: 1 addition & 1 deletion requirements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dependencies:
repository: https://kubernetes-charts.storage.googleapis.com/
condition: rabbitmq-ha.enabled
- name: mongodb-replicaset
version: 3.9.2
version: 3.9.6
repository: https://kubernetes-charts.storage.googleapis.com/
alias: mongodb-ha
condition: mongodb-ha.enabled
Expand Down
25 changes: 25 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,28 @@ stackstorm
{{- define "hyphenPrefix" -}}
{{ if . }}-{{ . }}{{end}}
{{- end -}}

# Allow calling helpers from nested sub-chart
# https://stackoverflow.com/a/52024583/4533625
# https://github.com/helm/helm/issues/4535#issuecomment-477778391
# Usage: "{{ include "nested" (list . "mongodb-ha" "mongodb-replicaset.fullname") }}"
{{- define "nested" }}
{{- $dot := index . 0 }}
{{- $subchart := index . 1 | splitList "." }}
{{- $template := index . 2 }}
{{- $values := $dot.Values }}
{{- range $subchart }}
{{- $values = index $values . }}
{{- end }}
{{- include $template (dict "Chart" (dict "Name" (last $subchart)) "Values" $values "Release" $dot.Release "Capabilities" $dot.Capabilities) }}
{{- end }}

# Generate comma-separated list of nodes for MongoDB-HA connection string, based on number of replicas and service name
{{- define "mongodb-ha-nodes" -}}
{{- $replicas := (int (index .Values "mongodb-ha" "replicas")) }}
{{- $mongo_fullname := include "nested" (list $ "mongodb-ha" "mongodb-replicaset.fullname") }}
{{- range $index0 := until $replicas -}}
{{- $index1 := $index0 | add1 -}}
{{ $mongo_fullname }}-{{ $index0 }}.{{ $mongo_fullname }}{{ if ne $index1 $replicas }},{{ end }}
{{- end -}}
{{- end -}}
14 changes: 8 additions & 6 deletions templates/configmaps_st2-conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ data:
api_url = http://{{ .Release.Name }}-st2api{{ template "enterpriseSuffix" . }}:9101/
[coordination]
url = etcd://{{ .Release.Name }}-etcd:2379
[messaging]
{{- if index .Values "rabbitmq-ha" "enabled" }}
[messaging]
url = amqp://{{ required "rabbitmq-ha.rabbitmqUsername is required!" (index .Values "rabbitmq-ha" "rabbitmqUsername") }}:{{ required "rabbitmq-ha.rabbitmqPassword is required!" (index .Values "rabbitmq-ha" "rabbitmqPassword") }}@{{ .Release.Name }}-rabbitmq-ha-discovery:5672
{{- end }}
[database]
{{- if index .Values "mongodb-ha" "enabled" }}
# TODO: ReplicaSet connection string needs templating based on number of MongoDB nodes
[database]
{{- if index .Values "mongodb-ha" "auth" "enabled" }}
host = mongodb://{{ required "mongodb-ha.auth.adminUser is required!" (index .Values "mongodb-ha" "auth" "adminUser") }}:{{ required "mongodb-ha.auth.adminPassword is required!" (index .Values "mongodb-ha" "auth" "adminPassword") }}@{{ .Release.Name }}-mongodb-ha/?authSource=admin&replicaSet=rs0
{{ else }}
host = mongodb://{{ .Release.Name }}-mongodb-ha/?replicaSet=rs0
host = mongodb://{{ template "mongodb-ha-nodes" $ }}/?authSource=admin&replicaSet={{ index .Values "mongodb-ha" "replicaSetName" }}
username = {{ required "mongodb-ha.auth.adminUser is required!" (index .Values "mongodb-ha" "auth" "adminUser") }}
password = {{ required "mongodb-ha.auth.adminPassword is required!" (index .Values "mongodb-ha" "auth" "adminPassword") }}
{{- else }}
host = mongodb://{{ template "mongodb-ha-nodes" $ }}/?replicaSet={{ index .Values "mongodb-ha" "replicaSetName" }}
{{- end }}
port = {{ index .Values "mongodb-ha" "port" }}
{{- end }}
# User-defined st2 config with custom settings applied on top of everything else.
Expand Down

0 comments on commit 93fe06e

Please sign in to comment.