|
| 1 | +{{/* |
| 2 | +Copyright Broadcom, Inc. All Rights Reserved. |
| 3 | +SPDX-License-Identifier: APACHE-2.0 |
| 4 | +*/}} |
| 5 | + |
| 6 | +{{/* vim: set filetype=mustache: */}} |
| 7 | + |
| 8 | +{{/* |
| 9 | +Return the proper etcd image name |
| 10 | +*/}} |
| 11 | +{{- define "etcd.image" -}} |
| 12 | +{{ include "common.images.image" (dict "imageRoot" .Values.image "global" .Values.global) }} |
| 13 | +{{- end -}} |
| 14 | + |
| 15 | +{{/* |
| 16 | +Return the proper image name (for the init container volume-permissions image) |
| 17 | +*/}} |
| 18 | +{{- define "etcd.volumePermissions.image" -}} |
| 19 | +{{ include "common.images.image" (dict "imageRoot" .Values.volumePermissions.image "global" .Values.global) }} |
| 20 | +{{- end -}} |
| 21 | + |
| 22 | +{{/* |
| 23 | +Return the proper Docker Image Registry Secret Names |
| 24 | +*/}} |
| 25 | +{{- define "etcd.imagePullSecrets" -}} |
| 26 | +{{ include "common.images.pullSecrets" (dict "images" (list .Values.image .Values.volumePermissions.image) "global" .Values.global) }} |
| 27 | +{{- end -}} |
| 28 | + |
| 29 | +{{/* |
| 30 | +Return the proper etcd peer protocol |
| 31 | +*/}} |
| 32 | +{{- define "etcd.peerProtocol" -}} |
| 33 | +{{- if .Values.auth.peer.secureTransport -}} |
| 34 | +{{- print "https" -}} |
| 35 | +{{- else -}} |
| 36 | +{{- print "http" -}} |
| 37 | +{{- end -}} |
| 38 | +{{- end -}} |
| 39 | + |
| 40 | +{{/* |
| 41 | +Return the proper etcd client protocol |
| 42 | +*/}} |
| 43 | +{{- define "etcd.clientProtocol" -}} |
| 44 | +{{- if .Values.auth.client.secureTransport -}} |
| 45 | +{{- print "https" -}} |
| 46 | +{{- else -}} |
| 47 | +{{- print "http" -}} |
| 48 | +{{- end -}} |
| 49 | +{{- end -}} |
| 50 | + |
| 51 | +{{/* |
| 52 | +Return the proper etcdctl authentication options |
| 53 | +*/}} |
| 54 | +{{- define "etcd.authOptions" -}} |
| 55 | +{{- $rbacOption := "--user root:$ROOT_PASSWORD" -}} |
| 56 | +{{- $certsOption := " --cert $ETCD_CERT_FILE --key $ETCD_KEY_FILE" -}} |
| 57 | +{{- $autoCertsOption := " --cert /drycc/etcd/data/fixtures/client/cert.pem --key /drycc/etcd/data/fixtures/client/key.pem --insecure-skip-tls-verify" -}} |
| 58 | +{{- $caOption := " --cacert $ETCD_TRUSTED_CA_FILE" -}} |
| 59 | +{{- $insecureTlsOption := " --insecure-skip-tls-verify" -}} |
| 60 | +{{- if or .Values.auth.rbac.create .Values.auth.rbac.enabled -}} |
| 61 | + {{- printf "%s" $rbacOption -}} |
| 62 | +{{- end -}} |
| 63 | +{{- if and .Values.auth.client.secureTransport .Values.auth.client.useAutoTLS -}} |
| 64 | + {{- printf "%s" $autoCertsOption -}} |
| 65 | +{{- else if and .Values.auth.client.secureTransport (not .Values.auth.client.useAutoTLS) -}} |
| 66 | + {{- printf "%s" $certsOption -}} |
| 67 | + {{- if or .Values.auth.client.enableAuthentication .Values.auth.client.caFilename -}} |
| 68 | + {{- printf "%s" $caOption -}} |
| 69 | + {{- else -}} |
| 70 | + {{- printf "%s" $insecureTlsOption -}} |
| 71 | + {{- end -}} |
| 72 | +{{- end -}} |
| 73 | +{{- end -}} |
| 74 | + |
| 75 | +{{/* |
| 76 | +Return the etcd configuration configmap |
| 77 | +*/}} |
| 78 | +{{- define "etcd.configmapName" -}} |
| 79 | +{{- if .Values.existingConfigmap -}} |
| 80 | + {{- printf "%s" (tpl .Values.existingConfigmap $) | trunc 63 | trimSuffix "-" -}} |
| 81 | +{{- else -}} |
| 82 | + {{- printf "%s-configuration" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" -}} |
| 83 | +{{- end -}} |
| 84 | +{{- end -}} |
| 85 | + |
| 86 | +{{/* |
| 87 | +Return true if a configmap object should be created |
| 88 | +*/}} |
| 89 | +{{- define "etcd.createConfigmap" -}} |
| 90 | +{{- if and .Values.configuration (not .Values.existingConfigmap) }} |
| 91 | + {{- true -}} |
| 92 | +{{- end -}} |
| 93 | +{{- end -}} |
| 94 | + |
| 95 | +{{/* |
| 96 | +Return the secret with etcd credentials |
| 97 | +*/}} |
| 98 | +{{- define "etcd.secretName" -}} |
| 99 | + {{- if .Values.auth.rbac.existingSecret -}} |
| 100 | + {{- printf "%s" .Values.auth.rbac.existingSecret | trunc 63 | trimSuffix "-" -}} |
| 101 | + {{- else -}} |
| 102 | + {{- printf "%s" (include "common.names.fullname" .) -}} |
| 103 | + {{- end -}} |
| 104 | +{{- end -}} |
| 105 | + |
| 106 | +{{/* |
| 107 | +Get the secret password key to be retrieved from etcd secret. |
| 108 | +*/}} |
| 109 | +{{- define "etcd.secretPasswordKey" -}} |
| 110 | +{{- if and .Values.auth.rbac.existingSecret .Values.auth.rbac.existingSecretPasswordKey -}} |
| 111 | +{{- printf "%s" .Values.auth.rbac.existingSecretPasswordKey -}} |
| 112 | +{{- else -}} |
| 113 | +{{- printf "etcd-root-password" -}} |
| 114 | +{{- end -}} |
| 115 | +{{- end -}} |
| 116 | + |
| 117 | +{{/* |
| 118 | +Return true if a secret object should be created for the etcd token private key |
| 119 | +*/}} |
| 120 | +{{- define "etcd.token.createSecret" -}} |
| 121 | +{{- if and (eq .Values.auth.token.enabled true) (eq .Values.auth.token.type "jwt") (empty .Values.auth.token.privateKey.existingSecret) }} |
| 122 | + {{- true -}} |
| 123 | +{{- end -}} |
| 124 | +{{- end -}} |
| 125 | + |
| 126 | +{{/* |
| 127 | +Return the secret with etcd token private key |
| 128 | +*/}} |
| 129 | +{{- define "etcd.token.secretName" -}} |
| 130 | + {{- if .Values.auth.token.privateKey.existingSecret -}} |
| 131 | + {{- printf "%s" .Values.auth.token.privateKey.existingSecret | trunc 63 | trimSuffix "-" -}} |
| 132 | + {{- else -}} |
| 133 | + {{- printf "%s-jwt-token" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" -}} |
| 134 | + {{- end -}} |
| 135 | +{{- end -}} |
| 136 | + |
| 137 | +{{/* |
| 138 | +Return the proper Disaster Recovery PVC name |
| 139 | +*/}} |
| 140 | +{{- define "etcd.disasterRecovery.pvc.name" -}} |
| 141 | +{{- if .Values.disasterRecovery.pvc.existingClaim -}} |
| 142 | + {{- printf "%s" (tpl .Values.disasterRecovery.pvc.existingClaim $) | trunc 63 | trimSuffix "-" -}} |
| 143 | +{{- else if .Values.startFromSnapshot.existingClaim -}} |
| 144 | + {{- printf "%s" (tpl .Values.startFromSnapshot.existingClaim $) | trunc 63 | trimSuffix "-" -}} |
| 145 | +{{- else -}} |
| 146 | + {{- printf "%s-snapshotter" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" }} |
| 147 | +{{- end -}} |
| 148 | +{{- end -}} |
| 149 | + |
| 150 | +{{/* |
| 151 | + Create the name of the service account to use |
| 152 | + */}} |
| 153 | +{{- define "etcd.serviceAccountName" -}} |
| 154 | +{{- if .Values.serviceAccount.create -}} |
| 155 | +{{ default (include "common.names.fullname" .) .Values.serviceAccount.name | trunc 63 | trimSuffix "-" }} |
| 156 | +{{- else -}} |
| 157 | +{{ default "default" .Values.serviceAccount.name | trunc 63 | trimSuffix "-" }} |
| 158 | +{{- end -}} |
| 159 | +{{- end -}} |
| 160 | + |
| 161 | +{{/* |
| 162 | +Compile all warnings into a single message, and call fail. |
| 163 | +*/}} |
| 164 | +{{- define "etcd.validateValues" -}} |
| 165 | +{{- $messages := list -}} |
| 166 | +{{- $messages := append $messages (include "etcd.validateValues.startFromSnapshot.existingClaim" .) -}} |
| 167 | +{{- $messages := append $messages (include "etcd.validateValues.startFromSnapshot.snapshotFilename" .) -}} |
| 168 | +{{- $messages := append $messages (include "etcd.validateValues.disasterRecovery" .) -}} |
| 169 | +{{- $messages := without $messages "" -}} |
| 170 | +{{- $message := join "\n" $messages -}} |
| 171 | + |
| 172 | +{{- if $message -}} |
| 173 | +{{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}} |
| 174 | +{{- end -}} |
| 175 | +{{- end -}} |
| 176 | + |
| 177 | +{{/* Validate values of etcd - an existing claim must be provided when startFromSnapshot is enabled */}} |
| 178 | +{{- define "etcd.validateValues.startFromSnapshot.existingClaim" -}} |
| 179 | +{{- if and .Values.startFromSnapshot.enabled (not .Values.startFromSnapshot.existingClaim) (not .Values.disasterRecovery.enabled) -}} |
| 180 | +etcd: startFromSnapshot.existingClaim |
| 181 | + An existing claim must be provided when startFromSnapshot is enabled and disasterRecovery is disabled!! |
| 182 | + Please provide it (--set startFromSnapshot.existingClaim="xxxx") |
| 183 | +{{- end -}} |
| 184 | +{{- end -}} |
| 185 | + |
| 186 | +{{/* Validate values of etcd - the snapshot filename must be provided when startFromSnapshot is enabled */}} |
| 187 | +{{- define "etcd.validateValues.startFromSnapshot.snapshotFilename" -}} |
| 188 | +{{- if and .Values.startFromSnapshot.enabled (not .Values.startFromSnapshot.snapshotFilename) (not .Values.disasterRecovery.enabled) -}} |
| 189 | +etcd: startFromSnapshot.snapshotFilename |
| 190 | + The snapshot filename must be provided when startFromSnapshot is enabled and disasterRecovery is disabled!! |
| 191 | + Please provide it (--set startFromSnapshot.snapshotFilename="xxxx") |
| 192 | +{{- end -}} |
| 193 | +{{- end -}} |
| 194 | + |
| 195 | +{{/* Validate values of etcd - persistence must be enabled when disasterRecovery is enabled */}} |
| 196 | +{{- define "etcd.validateValues.disasterRecovery" -}} |
| 197 | +{{- if and .Values.disasterRecovery.enabled (not .Values.persistence.enabled) -}} |
| 198 | +etcd: disasterRecovery |
| 199 | + Persistence must be enabled when disasterRecovery is enabled!! |
| 200 | + Please enable persistence (--set persistence.enabled=true) |
| 201 | +{{- end -}} |
| 202 | +{{- end -}} |
| 203 | + |
| 204 | +{{- define "etcd.token.jwtToken" -}} |
| 205 | +{{- if (include "etcd.token.createSecret" .) -}} |
| 206 | +{{- $jwtToken := lookup "v1" "Secret" (include "common.names.namespace" .) (printf "%s-jwt-token" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" ) -}} |
| 207 | +{{- if $jwtToken -}} |
| 208 | +{{ index $jwtToken "data" "jwt-token.pem" | b64dec }} |
| 209 | +{{- else -}} |
| 210 | +{{ genPrivateKey "rsa" }} |
| 211 | +{{- end -}} |
| 212 | +{{- end -}} |
| 213 | +{{- end -}} |
0 commit comments