Skip to content

Commit

Permalink
Add option to set MongoDB URL string in a secret
Browse files Browse the repository at this point in the history
Simplify the conditional logic with "mongodb.url" helper definition.

Also remove HTTP_PROXY AND HTTPS_PROXY ENV vars outside the mongodb.enabled
conditional wrapper - I believe that was an unintentional result of two PRs
merging cleanly in close proximity:
- helm#547
- helm#554

Signed-off-by: Scott Rigby <[email protected]>
  • Loading branch information
scottrigby committed Nov 22, 2018
1 parent 34a17aa commit 70db399
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
1 change: 1 addition & 0 deletions chart/monocular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@ $ helm install monocular/monocular -f custom-domains.yaml
| `ingress.annotations` | Ingress annotations | `{ingress.kubernetes.io/rewrite-target: /, kubernetes.io/ingress.class: nginx}` |
| `ingress.tls` | TLS configuration for the Ingress object | `nil` |
| `global.mongoUrl` | External MongoDB connection URL | `nil` |
| `global.mongoUrlSecret` | External MongoDB connection URL secret | `nil` |
6 changes: 6 additions & 0 deletions chart/monocular/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ Point your Ingress hosts to the address from the output of the above command:
{{ end -}}

Visit https://github.com/helm/monocular for more information.

{{- if .Values.global.mongoUrlSecret }}
If you have not already created the external MongoDB connection URL secret:

kubectl create secret generic {{ .Values.global.mongoUrlSecret }} --namespace {{ .Release.Namespace }} --from-file=./mongo-url-secret
{{- end }}
27 changes: 22 additions & 5 deletions chart/monocular/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ Render image reference
{{ .registry }}/{{ .repository }}:{{ .tag }}
{{- end -}}

{{/*
MongoDB URL argument.
*/}}
{{- define "mongodb.url" -}}
{{- if $global.Values.mongodb.enabled }}
{{ template "mongodb.fullname" $global }}
{{- else if $global.Values.global.mongoUrlSecret }}
{{ "$MONGO_URL" }}
{{- else if $global.Values.global.mongoUrl }}
{{ $global.Values.global.mongoUrl }}
{{- end -}}

{{/*
Sync job pod template
*/}}
Expand All @@ -49,28 +61,33 @@ spec:
args:
- sync
- --user-agent-comment=monocular/{{ $global.Chart.AppVersion }}
{{- if and $global.Values.global.mongoUrl (not $global.Values.mongodb.enabled) }}
- --mongo-url={{ $global.Values.global.mongoUrl }}
{{- else }}
- --mongo-url={{ template "mongodb.fullname" $global }}
- --mongo-url={{ template "mongodb.url" $global }}
{{- if $global.Values.mongodb.enabled }}
- --mongo-user=root
{{- end }}
- {{ $repo.name }}
- {{ $repo.url }}
command:
- /chart-repo
{{- if $global.Values.mongodb.enabled }}
env:
- name: HTTP_PROXY
value: {{ $global.Values.sync.httpProxy }}
- name: HTTPS_PROXY
value: {{ $global.Values.sync.httpsProxy }}
{{- if $global.Values.mongodb.enabled }}
- name: MONGO_PASSWORD
valueFrom:
secretKeyRef:
key: mongodb-root-password
name: {{ template "mongodb.fullname" $global }}
{{- end }}
{{- if $global.Values.global.mongoUrlSecret }}
- name: MONGO_URL
valueFrom:
secretKeyRef:
name: {{ $global.Values.global.mongoUrlSecret }}
key: mongo-url-secret
{{- end }}
resources:
{{ toYaml $global.Values.sync.resources | indent 6 }}
{{- with $global.Values.sync.nodeSelector }}
Expand Down
14 changes: 10 additions & 4 deletions chart/monocular/templates/chartsvc-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,24 @@ spec:
command:
- /chartsvc
args:
{{- if and .Values.global.mongoUrl (not .Values.mongodb.enabled) }}
- --mongo-url={{ .Values.global.mongoUrl }}
{{- else }}
- --mongo-url={{ template "mongodb.url" . }}
{{- if .Values.mongodb.enabled }}
- --mongo-user=root
- --mongo-url={{ template "mongodb.fullname" . }}
env:
- name: MONGO_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "mongodb.fullname" . }}
key: mongodb-root-password
{{- end }}
{{- if .Values.global.mongoUrlSecret }}
env:
- name: MONGO_URL
valueFrom:
secretKeyRef:
name: {{ .Values.global.mongoUrlSecret }}
key: mongo-url-secret
{{- end }}
ports:
- name: http
containerPort: {{ .Values.chartsvc.service.port }}
Expand Down
5 changes: 5 additions & 0 deletions chart/monocular/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,10 @@ mongodb:
# This must be set if mongodb.enabled is set to false, following the pattern:
# `mongodb://${MONGODB_USER}:${MONGODB_ROOT_PASSWORD}@${MONGODB_DNS}:${MONGODB_PORT}/${MONGODB_DATABASE}`
# ref: https://docs.mongodb.com/manual/reference/connection-string/
# You may set the connection URL in one of two ways:
# - mongoUrl: store the connection string directly in Helm values
# - mongoUrlSecret: name of the secret where the connection string is stored,
# where the key is "mongo-url-secret". See NOTES.txt.
global:
mongoUrl:
mongoUrlSecret:

0 comments on commit 70db399

Please sign in to comment.