|
| 1 | +{{/* vim: set filetype=mustache: */}} |
| 2 | + |
| 3 | +{{/* |
| 4 | +Create a default fully qualified mongodb name. |
| 5 | +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). |
| 6 | +*/}} |
| 7 | +{{- define "gorse.mongodb.fullname" -}} |
| 8 | +{{- include "common.names.dependency.fullname" (dict "chartName" "mongodb" "chartValues" .Values.mongodb "context" $) -}} |
| 9 | +{{- end -}} |
| 10 | + |
| 11 | +{{- define "gorse.master.fullname" -}} |
| 12 | +{{ printf "%s-master" (include "common.names.fullname" .) }} |
| 13 | +{{- end -}} |
| 14 | + |
| 15 | +{{- define "gorse.server.fullname" -}} |
| 16 | +{{ printf "%s-server" (include "common.names.fullname" .) }} |
| 17 | +{{- end -}} |
| 18 | + |
| 19 | +{{- define "gorse.worker.fullname" -}} |
| 20 | +{{ printf "%s-worker" (include "common.names.fullname" .) }} |
| 21 | +{{- end -}} |
| 22 | + |
| 23 | +{{/* |
| 24 | +Returns the available value for certain key in an existing secret (if it exists), |
| 25 | +otherwise it generates a random value. |
| 26 | +*/}} |
| 27 | +{{- define "getValueFromSecret" }} |
| 28 | + {{- $len := (default 16 .Length) | int -}} |
| 29 | + {{- $obj := (lookup "v1" "Secret" .Namespace .Name).data -}} |
| 30 | + {{- if $obj }} |
| 31 | + {{- index $obj .Key | b64dec -}} |
| 32 | + {{- else -}} |
| 33 | + {{- randAlphaNum $len -}} |
| 34 | + {{- end -}} |
| 35 | +{{- end }} |
| 36 | + |
| 37 | +{{- define "gorse.toTOMLArray" -}} |
| 38 | + {{- $list := list }} |
| 39 | + {{- range .List }} |
| 40 | + {{- $list = append $list (printf "\"%s\"" .) }} |
| 41 | + {{- end }} |
| 42 | + {{- printf "[%s]" (join ", " $list) }} |
| 43 | +{{- end }} |
| 44 | + |
| 45 | +{{/* |
| 46 | +Return Gorse username |
| 47 | +*/}} |
| 48 | +{{- define "gorse.dashboardUsername" -}} |
| 49 | +{{- if not (empty .Values.gorse.dashboard.username) }} |
| 50 | + {{- .Values.gorse.dashboard.username -}} |
| 51 | +{{- else -}} |
| 52 | + {{- "gorse" -}} |
| 53 | +{{- end -}} |
| 54 | +{{- end -}} |
| 55 | + |
| 56 | +{{/* |
| 57 | +Return Gorse password |
| 58 | +*/}} |
| 59 | +{{- define "gorse.dashboardPassword" -}} |
| 60 | +{{- if not (empty .Values.gorse.dashboard.password) }} |
| 61 | + {{- .Values.gorse.dashboard.password -}} |
| 62 | +{{- else -}} |
| 63 | + {{- include "getValueFromSecret" (dict "Namespace" .Release.Namespace "Name" (include "common.names.fullname" .) "Length" 10 "Key" "dashboard-password") -}} |
| 64 | +{{- end -}} |
| 65 | +{{- end -}} |
| 66 | + |
| 67 | +{{/* |
| 68 | +Return Gorse API Secret |
| 69 | +*/}} |
| 70 | +{{- define "gorse.apiKey" -}} |
| 71 | +{{- if not (empty .Values.gorse.api.key) }} |
| 72 | + {{- .Values.gorse.api.key -}} |
| 73 | +{{- else -}} |
| 74 | + {{- include "getValueFromSecret" (dict "Namespace" .Release.Namespace "Name" (include "common.names.fullname" .) "Length" 32 "Key" "api-key") -}} |
| 75 | +{{- end -}} |
| 76 | +{{- end -}} |
| 77 | + |
| 78 | +{{/* |
| 79 | +Return the MongoDB Hostname |
| 80 | +*/}} |
| 81 | +{{- define "gorse.databaseHost" -}} |
| 82 | +{{- if .Values.mongodb.enabled }} |
| 83 | + {{- if eq .Values.mongodb.architecture "replication" }} |
| 84 | + {{- printf "%s-primary" (include "gorse.mongodb.fullname" .) | trunc 63 | trimSuffix "-" -}} |
| 85 | + {{- else -}} |
| 86 | + {{- printf "%s" (include "gorse.mongodb.fullname" .) -}} |
| 87 | + {{- end -}} |
| 88 | +{{- else -}} |
| 89 | + {{- printf "%s" .Values.externalDatabase.host -}} |
| 90 | +{{- end -}} |
| 91 | +{{- end -}} |
| 92 | + |
| 93 | +{{/* |
| 94 | +Return the MongoDB Port |
| 95 | +*/}} |
| 96 | +{{- define "gorse.databasePort" -}} |
| 97 | +{{- if .Values.mongodb.enabled }} |
| 98 | + {{- printf "27017" -}} |
| 99 | +{{- else -}} |
| 100 | + {{- printf "%d" (.Values.externalDatabase.port | int ) -}} |
| 101 | +{{- end -}} |
| 102 | +{{- end -}} |
| 103 | + |
| 104 | +{{/* |
| 105 | +Return the MongoDB Database Name |
| 106 | +*/}} |
| 107 | +{{- define "gorse.databaseName" -}} |
| 108 | +{{- if .Values.mongodb.enabled }} |
| 109 | + {{- printf "%s" .Values.mongodb.auth.database -}} |
| 110 | +{{- else -}} |
| 111 | + {{- printf "%s" .Values.externalDatabase.database -}} |
| 112 | +{{- end -}} |
| 113 | +{{- end -}} |
| 114 | + |
| 115 | +{{/* |
| 116 | +Return the MongoDB User |
| 117 | +*/}} |
| 118 | +{{- define "gorse.databaseUser" -}} |
| 119 | +{{- if .Values.mongodb.enabled }} |
| 120 | + {{- .Values.mongodb.auth.username -}} |
| 121 | +{{- else -}} |
| 122 | + {{- .Values.externalDatabase.username -}} |
| 123 | +{{- end -}} |
| 124 | +{{- end -}} |
| 125 | + |
| 126 | +{{/* |
| 127 | +Return the MongoDB Secret Name |
| 128 | +*/}} |
| 129 | +{{- define "gorse.databaseSecretName" -}} |
| 130 | +{{- if .Values.mongodb.enabled }} |
| 131 | + {{- if .Values.mongodb.auth.existingSecret -}} |
| 132 | + {{- printf "%s" .Values.mongodb.auth.existingSecret -}} |
| 133 | + {{- else -}} |
| 134 | + {{- printf "%s" (include "gorse.mongodb.fullname" .) -}} |
| 135 | + {{- end -}} |
| 136 | +{{- else if .Values.externalDatabase.existingSecret -}} |
| 137 | + {{- include "common.tplvalues.render" (dict "value" .Values.externalDatabase.existingSecret "context" $) -}} |
| 138 | +{{- else -}} |
| 139 | + {{- printf "%s-externaldb" (include "common.names.fullname" .) -}} |
| 140 | +{{- end -}} |
| 141 | +{{- end -}} |
| 142 | + |
| 143 | +{{/* |
| 144 | +Return the MongoDB secret key |
| 145 | +*/}} |
| 146 | +{{- define "gorse.databaseSecretPasswordKey" -}} |
| 147 | +{{- if .Values.mongodb.enabled }} |
| 148 | + {{- printf "mongodb-passwords" -}} |
| 149 | +{{- else -}} |
| 150 | + {{- .Values.externalDatabase.existingSecretPasswordKey -}} |
| 151 | +{{- end -}} |
| 152 | +{{- end -}} |
0 commit comments