github.com/verrazzano/verrazzano@v1.7.0/platform-operator/thirdparty/charts/thanos/templates/_helpers.tpl (about) 1 {{/* vim: set filetype=mustache: */}} 2 3 {{/* 4 Fully qualified app name for PostgreSQL 5 */}} 6 {{- define "thanos.minio.fullname" -}} 7 {{- if .Values.fullnameOverride -}} 8 {{- printf "%s-minio" .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} 9 {{- else -}} 10 {{- $name := default .Chart.Name .Values.nameOverride -}} 11 {{- if contains $name .Release.Name -}} 12 {{- printf "%s-minio" .Release.Name | trunc 63 | trimSuffix "-" -}} 13 {{- else -}} 14 {{- printf "%s-%s-minio" .Release.Name $name | trunc 63 | trimSuffix "-" -}} 15 {{- end -}} 16 {{- end -}} 17 {{- end -}} 18 19 {{/* 20 Return the proper Thanos image name 21 */}} 22 {{- define "thanos.image" -}} 23 {{- include "common.images.image" ( dict "imageRoot" .Values.image "global" .Values.global ) -}} 24 {{- end -}} 25 26 {{/* 27 Return the proper init container volume-permissions image name 28 */}} 29 {{- define "thanos.volumePermissions.image" -}} 30 {{- include "common.images.image" ( dict "imageRoot" .Values.volumePermissions.image "global" .Values.global ) -}} 31 {{- end -}} 32 33 {{/* 34 Return the proper Docker Image Registry Secret Names 35 */}} 36 {{- define "thanos.imagePullSecrets" -}} 37 {{- include "common.images.pullSecrets" (dict "images" (list .Values.image .Values.volumePermissions.image) "global" .Values.global) -}} 38 {{- end -}} 39 40 {{/* 41 Return the Thanos Objstore configuration secret. 42 */}} 43 {{- define "thanos.objstoreSecretName" -}} 44 {{- if .Values.existingObjstoreSecret -}} 45 {{- printf "%s" (tpl .Values.existingObjstoreSecret $) -}} 46 {{- else -}} 47 {{- printf "%s-objstore-secret" (include "common.names.fullname" .) -}} 48 {{- end -}} 49 {{- end -}} 50 51 {{/* 52 Return true if a secret object should be created 53 */}} 54 {{- define "thanos.createObjstoreSecret" -}} 55 {{- if and .Values.objstoreConfig (not .Values.existingObjstoreSecret) }} 56 {{- true -}} 57 {{- else -}} 58 {{- end -}} 59 {{- end -}} 60 61 {{/* 62 Return the Thanos HTTPS and basic auth configuration secret. 63 */}} 64 {{- define "thanos.httpConfigEnabled" -}} 65 {{- if or .Values.existingHttpConfigSecret .Values.https.enabled .Values.auth.basicAuthUsers .Values.httpConfig }} 66 {{- true -}} 67 {{- end -}} 68 {{- end -}} 69 70 {{/* 71 Return the Thanos HTTPS and basic auth configuration secret. 72 */}} 73 {{- define "thanos.httpCertsSecretName" -}} 74 {{- if .Values.https.existingSecret -}} 75 {{- printf "%s" (tpl .Values.https.existingSecret $) -}} 76 {{- else -}} 77 {{- printf "%s-http-certs-secret" (include "common.names.fullname" .) -}} 78 {{- end -}} 79 {{- end -}} 80 81 {{/* 82 Return the Thanos HTTPS and basic auth configuration secret. 83 */}} 84 {{- define "thanos.httpConfigSecretName" -}} 85 {{- if .Values.existingHttpConfigSecret -}} 86 {{- printf "%s" (tpl .Values.existingHttpConfigSecret $) -}} 87 {{- else -}} 88 {{- printf "%s-http-config-secret" (include "common.names.fullname" .) -}} 89 {{- end -}} 90 {{- end -}} 91 92 {{/* 93 Return true if a secret object should be created 94 */}} 95 {{- define "thanos.createHttpConfigSecret" -}} 96 {{- if and (not .Values.existingHttpConfigSecret) (or .Values.https.enabled .Values.auth.basicAuthUsers .Values.httpConfig) }} 97 {{- true -}} 98 {{- else -}} 99 {{- end -}} 100 {{- end -}} 101 102 {{/* 103 Return a YAML of either .Values.query or .Values.querier 104 If .Values.querier is used, we merge in the defaults from .Values.query, giving preference to .Values.querier 105 */}} 106 {{- define "thanos.query.values" -}} 107 {{- if .Values.querier -}} 108 {{- if .Values.query -}} 109 {{- mergeOverwrite .Values.query .Values.querier | toYaml -}} 110 {{- else -}} 111 {{- .Values.querier | toYaml -}} 112 {{- end -}} 113 {{- else -}} 114 {{- .Values.query | toYaml -}} 115 {{- end -}} 116 {{- end -}} 117 118 {{/* 119 Return the Thanos Query Service Discovery configuration configmap. 120 */}} 121 {{- define "thanos.query.SDConfigmapName" -}} 122 {{- $query := (include "thanos.query.values" . | fromYaml) -}} 123 {{- if $query.existingSDConfigmap -}} 124 {{- printf "%s" (tpl $query.existingSDConfigmap $) -}} 125 {{- else -}} 126 {{- printf "%s-query-sd-configmap" (include "common.names.fullname" .) -}} 127 {{- end -}} 128 {{- end -}} 129 130 {{/* 131 Return true if a configmap object should be created 132 */}} 133 {{- define "thanos.query.createSDConfigmap" -}} 134 {{- $query := (include "thanos.query.values" . | fromYaml) -}} 135 {{- if and $query.sdConfig (not $query.existingSDConfigmap) }} 136 {{- true -}} 137 {{- else -}} 138 {{- end -}} 139 {{- end -}} 140 141 {{/* 142 Return the Thanos Ruler configuration configmap. 143 */}} 144 {{- define "thanos.ruler.configmapName" -}} 145 {{- if .Values.ruler.existingConfigmap -}} 146 {{- printf "%s" (tpl .Values.ruler.existingConfigmap $) -}} 147 {{- else -}} 148 {{- printf "%s-ruler-configmap" (include "common.names.fullname" .) -}} 149 {{- end -}} 150 {{- end -}} 151 152 {{/* 153 Return true if a configmap object should be created 154 */}} 155 {{- define "thanos.ruler.createConfigmap" -}} 156 {{- if and .Values.ruler.config (not .Values.ruler.existingConfigmap) }} 157 {{- true -}} 158 {{- else -}} 159 {{- end -}} 160 {{- end -}} 161 162 {{/* 163 Return the Thanos storegateway configuration configmap. 164 */}} 165 {{- define "thanos.storegateway.configmapName" -}} 166 {{- if .Values.storegateway.existingConfigmap -}} 167 {{- printf "%s" (tpl .Values.storegateway.existingConfigmap $) -}} 168 {{- else -}} 169 {{- printf "%s-storegateway-configmap" (include "common.names.fullname" .) -}} 170 {{- end -}} 171 {{- end -}} 172 173 {{/* 174 Return the Thanos Query Frontend configuration configmap. 175 */}} 176 {{- define "thanos.queryFrontend.configmapName" -}} 177 {{- if .Values.queryFrontend.existingConfigmap -}} 178 {{- printf "%s" (tpl .Values.queryFrontend.existingConfigmap $) -}} 179 {{- else -}} 180 {{- printf "%s-query-frontend-configmap" (include "common.names.fullname" .) -}} 181 {{- end -}} 182 {{- end -}} 183 184 {{/* 185 Return true if a configmap object should be created 186 */}} 187 {{- define "thanos.queryFrontend.createConfigmap" -}} 188 {{- if and .Values.queryFrontend.config (not .Values.queryFrontend.existingConfigmap) }} 189 {{- true -}} 190 {{- else -}} 191 {{- end -}} 192 {{- end -}} 193 194 {{/* 195 Return true if a configmap object should be created 196 */}} 197 {{- define "thanos.storegateway.createConfigmap" -}} 198 {{- if and .Values.storegateway.config (not .Values.storegateway.existingConfigmap) }} 199 {{- true -}} 200 {{- else -}} 201 {{- end -}} 202 {{- end -}} 203 204 {{/* 205 Return the Thanos Compactor pvc name 206 */}} 207 {{- define "thanos.compactor.pvcName" -}} 208 {{- if .Values.compactor.persistence.existingClaim -}} 209 {{- printf "%s" (tpl .Values.compactor.persistence.existingClaim $) -}} 210 {{- else -}} 211 {{- printf "%s-compactor" (include "common.names.fullname" .) -}} 212 {{- end -}} 213 {{- end -}} 214 215 {{/* 216 Check if there are rolling tags in the images 217 */}} 218 {{- define "thanos.checkRollingTags" -}} 219 {{- include "common.warnings.rollingTag" .Values.image -}} 220 {{- include "common.warnings.rollingTag" .Values.volumePermissions.image -}} 221 {{- end -}} 222 223 {{/* 224 Compile all warnings into a single message, and call fail. 225 */}} 226 {{- define "thanos.validateValues" -}} 227 {{- $messages := list -}} 228 {{- $messages := append $messages (include "thanos.validateValues.objstore" .) -}} 229 {{- $messages := append $messages (include "thanos.validateValues.ruler.alertmanagers" .) -}} 230 {{- $messages := append $messages (include "thanos.validateValues.ruler.config" .) -}} 231 {{- $messages := append $messages (include "thanos.validateValues.sharded.service" .) -}} 232 {{- $messages := without $messages "" -}} 233 {{- $message := join "\n" $messages -}} 234 235 {{- if $message -}} 236 {{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}} 237 {{- end -}} 238 {{- end -}} 239 240 {{/* Validate values of Thanos - Objstore configuration */}} 241 {{- define "thanos.validateValues.objstore" -}} 242 {{- if and (or .Values.bucketweb.enabled .Values.compactor.enabled .Values.ruler.enabled .Values.storegateway.enabled) (not (include "thanos.createObjstoreSecret" .)) ( not .Values.existingObjstoreSecret) -}} 243 thanos: objstore configuration 244 When enabling Bucket Web, Compactor, Ruler or Store component, 245 you must provide a valid objstore configuration. 246 There are three alternatives to provide it: 247 1) Provide it using the 'objstoreConfig' parameter 248 2) Provide it using an existing Secret and using the 'existingObjstoreSecret' parameter 249 3) Put your objstore.yml under the 'files/conf/' directory 250 {{- end -}} 251 {{- end -}} 252 253 {{/* Validate values of Thanos - Ruler Alertmanager(s) */}} 254 {{- define "thanos.validateValues.ruler.alertmanagers" -}} 255 {{/* Check the emptiness of the values */}} 256 {{- if and .Values.ruler.enabled ( and (empty .Values.ruler.alertmanagers) (empty .Values.ruler.alertmanagersConfig)) -}} 257 thanos: ruler alertmanagers 258 When enabling Ruler component, you must provide either alermanagers URL(s) or an alertmanagers configuration. 259 See https://github.com/thanos-io/thanos/blob/ef94b7e6468d94e2c47943ebf5fc6db24c48d867/docs/components/rule.md#flags and https://github.com/thanos-io/thanos/blob/ef94b7e6468d94e2c47943ebf5fc6db24c48d867/docs/components/rule.md#Configuration for more information. 260 {{- end -}} 261 {{/* Check that the values are defined in a mutually exclusive manner */}} 262 {{- if and .Values.ruler.enabled .Values.ruler.alertmanagers .Values.ruler.alertmanagersConfig -}} 263 thanos: ruler alertmanagers 264 Only one of the following can be used at one time: 265 * .Values.ruler.alertmanagers 266 * .Values.ruler.alertmanagersConfig 267 Otherwise, the configurations will collide and Thanos will error out. Please consolidate your configuration 268 into one of the above options. 269 {{- end -}} 270 {{- end -}} 271 272 {{/* Validate values of Thanos - Ruler configuration */}} 273 {{- define "thanos.validateValues.ruler.config" -}} 274 {{- if and .Values.ruler.enabled (not (include "thanos.ruler.createConfigmap" .)) (not .Values.ruler.existingConfigmap) -}} 275 thanos: ruler configuration 276 When enabling Ruler component, you must provide a valid configuration. 277 There are three alternatives to provide it: 278 1) Provide it using the 'ruler.config' parameter 279 2) Provide it using an existing Configmap and using the 'ruler.existingConfigmap' parameter 280 3) Put your ruler.yml under the 'files/conf/' directory 281 {{- end -}} 282 {{- end -}} 283 284 {{/* Validate values of Thanos - number of sharded service properties */}} 285 {{- define "thanos.validateValues.sharded.service" -}} 286 {{- if and .Values.storegateway.sharded.enabled (not (empty .Values.storegateway.sharded.service.clusterIPs) ) -}} 287 {{- if eq "false" (include "thanos.validateValues.storegateway.sharded.length" (dict "property" $.Values.storegateway.sharded.service.clusterIPs "context" $) ) }} 288 thanos: storegateway.sharded.service.clusterIPs 289 The number of shards does not match the number of ClusterIPs $.Values.storegateway.sharded.service.clusterIPs 290 {{- end -}} 291 {{- end -}} 292 {{- if and .Values.storegateway.sharded.enabled (not (empty .Values.storegateway.sharded.service.loadBalancerIPs) ) -}} 293 {{- if eq "false" (include "thanos.validateValues.storegateway.sharded.length" (dict "property" $.Values.storegateway.sharded.service.loadBalancerIPs "context" $) ) }} 294 thanos: storegateway.sharded.service.loadBalancerIPs 295 The number of shards does not match the number of loadBalancerIPs $.Values.storegateway.sharded.service.loadBalancerIPs 296 {{- end -}} 297 {{- end -}} 298 {{- if and .Values.storegateway.sharded.enabled (not (empty .Values.storegateway.sharded.service.http.nodePorts) ) -}} 299 {{- if eq "false" (include "thanos.validateValues.storegateway.sharded.length" (dict "property" $.Values.storegateway.sharded.service.http.nodePorts "context" $) ) }} 300 thanos: storegateway.sharded.service.http.nodePorts 301 The number of shards does not match the number of http.nodePorts $.Values.storegateway.sharded.service.http.nodePorts 302 {{- end -}} 303 {{- end -}} 304 {{- if and .Values.storegateway.sharded.enabled (not (empty .Values.storegateway.sharded.service.grpc.nodePorts) ) -}} 305 {{- if eq "false" (include "thanos.validateValues.storegateway.sharded.length" (dict "property" $.Values.storegateway.sharded.service.grpc.nodePorts "context" $) ) }} 306 thanos: storegateway.sharded.service.grpc.nodePorts 307 The number of shards does not match the number of grpc.nodePorts $.Values.storegateway.sharded.service.grpc.nodePorts 308 {{- end -}} 309 {{- end -}} 310 {{- end -}} 311 312 {{- define "thanos.validateValues.storegateway.sharded.length" -}} 313 {{/* Get number of shards */}} 314 {{- $shards := int 0 }} 315 {{- if .context.Values.storegateway.sharded.hashPartitioning.shards }} 316 {{- $shards = int .context.Values.storegateway.sharded.hashPartitioning.shards }} 317 {{- else }} 318 {{- $shards = len .context.Values.storegateway.sharded.timePartitioning }} 319 {{- end }} 320 {{- $propertyLength := (len .property) -}} 321 {{/* Validate property */}} 322 {{- if ne $shards $propertyLength -}} 323 false 324 {{- end }} 325 {{- end }} 326 327 {{/* Service account name 328 Usage: 329 {{ include "thanos.serviceAccountName" (dict "component" "bucketweb" "context" $) }} 330 */}} 331 {{- define "thanos.serviceAccountName" -}} 332 {{- $component := index .context.Values .component -}} 333 {{- if eq .component "query-frontend" -}} 334 {{- $component = index .context.Values "queryFrontend" -}} 335 {{- else if eq .component "receive-distributor" -}} 336 {{- $component = index .context.Values "receiveDistributor" -}} 337 {{- end -}} 338 {{- if not (include "thanos.serviceAccount.useExisting" (dict "component" .component "context" .context)) -}} 339 {{- if $component.serviceAccount.create -}} 340 {{- if eq .context.Values.serviceAccount.name "" -}} 341 {{ default (printf "%s-%s" (include "common.names.fullname" .context) .component) $component.serviceAccount.name }} 342 {{- else -}} 343 {{ default (printf "%s-%s" (.context.Values.serviceAccount.name) .component) $component.serviceAccount.name }} 344 {{- end -}} 345 {{- else if .context.Values.serviceAccount.create -}} 346 {{ default (include "common.names.fullname" .context) .context.Values.serviceAccount.name }} 347 {{- else -}} 348 {{ default "default" (coalesce $component.serviceAccount.name .context.Values.serviceAccount.name ) }} 349 {{- end -}} 350 {{- else -}} 351 {{ default (printf "%s-%s" (include "common.names.fullname" .context) .component) (coalesce $component.serviceAccount.existingServiceAccount .context.Values.existingServiceAccount) }} 352 {{- end -}} 353 {{- end -}} 354 355 {{/* Service account use existing 356 {{- include "thanos.serviceAccount.useExisting" (dict "component" "bucketweb" "context" $) -}} 357 */}} 358 {{- define "thanos.serviceAccount.useExisting" -}} 359 {{- $component := index .context.Values .component -}} 360 {{- if eq .component "query-frontend" -}} 361 {{- $component = index .context.Values "queryFrontend" -}} 362 {{- else if eq .component "receive-distributor" -}} 363 {{- $component = index .context.Values "receiveDistributor" -}} 364 {{- end -}} 365 {{- if .context.Values.existingServiceAccount -}} 366 {{- true -}} 367 {{- else if $component.serviceAccount.existingServiceAccount -}} 368 {{- true -}} 369 {{- end -}} 370 {{- end -}} 371 372 {{/* 373 Return true if a hashring configmap object should be created 374 */}} 375 {{- define "thanos.receive.createConfigmap" -}} 376 {{- if and .Values.receive.enabled (not .Values.receive.existingConfigmap) }} 377 {{- true -}} 378 {{- else -}} 379 {{- end -}} 380 {{- end -}} 381 382 383 {{/* 384 Return the Thanos receive hashring configuration configmap. 385 */}} 386 {{- define "thanos.receive.configmapName" -}} 387 {{- if .Values.receive.existingConfigmap -}} 388 {{- printf "%s" (tpl .Values.receive.existingConfigmap $) -}} 389 {{- else -}} 390 {{- printf "%s-receive" (include "common.names.fullname" .) -}} 391 {{- end -}} 392 {{- end -}} 393 394 {{/* Return the proper pod fqdn of the replica. 395 Usage: 396 {{ include "thanos.receive.podFqdn" (dict "root" . "extra" $suffix ) }} 397 */}} 398 {{- define "thanos.receive.podFqdn" -}} 399 {{- printf "\"%s-receive-%d.%s-receive-headless.%s.svc.%s:10901\"" (include "common.names.fullname" .root ) .extra (include "common.names.fullname" .root ) .root.Release.Namespace .root.Values.clusterDomain -}} 400 {{- end -}} 401 402 {{/* Returns a proper configuration when no config is specified 403 Usage: 404 {{ include "thanos.receive.config" . }} 405 */}} 406 {{- define "thanos.receive.config" -}} 407 {{- if not .Values.receive.config -}} 408 {{- if .Values.receive.service.additionalHeadless -}} 409 {{- $count := int .Values.receive.replicaCount -}} 410 {{- $endpoints_dict := dict "endpoints" (list) -}} 411 {{- $root := . -}} 412 {{- range $i := until $count -}} 413 {{- $data := dict "root" $root "extra" $i -}} 414 {{- $noop := (include "thanos.receive.podFqdn" $data) | append $endpoints_dict.endpoints | set $endpoints_dict "endpoints" -}} 415 {{- end -}} 416 [ 417 { 418 "endpoints": [ 419 {{ join ",\n" $endpoints_dict.endpoints | indent 6 }} 420 ] 421 } 422 ] 423 {{- else -}} 424 [ 425 { 426 "endpoints": [ 427 "127.0.0.1:10901" 428 ] 429 } 430 ] 431 {{- end -}} 432 {{- else -}} 433 {{- if (typeIs "string" .Values.receive.config) }} 434 {{- .Values.receive.config -}} 435 {{- else -}} 436 {{- .Values.receive.config | toPrettyJson -}} 437 {{- end -}} 438 {{- end -}} 439 {{- end -}}