Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ type: library
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
version: 0.2.0
107 changes: 107 additions & 0 deletions templates/_affinities.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{{/*
Pod and node affinity helpers.
Follows the Bitnami preset pattern (soft/hard) with full override support.

Values pattern (per component):
podAffinityPreset: "" # "", "soft", or "hard"
podAntiAffinityPreset: "" # "", "soft", or "hard"
nodeAffinityPreset:
type: "" # "", "soft", or "hard"
key: "" # node label key
values: [] # node label values
affinity: {} # full override (ignores all presets when set)
*/}}

{{/*
Return the topology key (defaults to kubernetes.io/hostname).
Usage: {{ include "comet-common.affinities.topologyKey" (dict "topologyKey" "BAR") }}
*/}}
{{- define "comet-common.affinities.topologyKey" -}}
{{ .topologyKey | default "kubernetes.io/hostname" -}}
{{- end -}}

{{/*
Return a soft nodeAffinity definition.
Usage: {{ include "comet-common.affinities.nodes.soft" (dict "key" "FOO" "values" (list "BAR" "BAZ")) }}
*/}}
{{- define "comet-common.affinities.nodes.soft" -}}
preferredDuringSchedulingIgnoredDuringExecution:
- preference:
matchExpressions:
- key: {{ .key }}
operator: In
values:
{{- range .values }}
- {{ . | quote }}
{{- end }}
weight: 1
{{- end -}}

{{/*
Return a hard nodeAffinity definition.
Usage: {{ include "comet-common.affinities.nodes.hard" (dict "key" "FOO" "values" (list "BAR" "BAZ")) }}
*/}}
{{- define "comet-common.affinities.nodes.hard" -}}
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: {{ .key }}
operator: In
values:
{{- range .values }}
- {{ . | quote }}
{{- end }}
{{- end -}}

{{/*
Return a nodeAffinity definition (dispatches to soft or hard).
Usage: {{ include "comet-common.affinities.nodes" (dict "type" "soft" "key" "FOO" "values" (list "BAR" "BAZ")) }}
*/}}
{{- define "comet-common.affinities.nodes" -}}
{{- if eq .type "soft" }}
{{- include "comet-common.affinities.nodes.soft" . -}}
{{- else if eq .type "hard" }}
{{- include "comet-common.affinities.nodes.hard" . -}}
{{- end -}}
{{- end -}}

{{/*
Return a soft podAffinity/podAntiAffinity definition.
Uses comet-common.selectorLabels for matchLabels, passing componentName for app.kubernetes.io/component.
Usage: {{ include "comet-common.affinities.pods.soft" (dict "component" "FOO" "topologyKey" "BAR" "context" $) }}
*/}}
{{- define "comet-common.affinities.pods.soft" -}}
{{- $component := default "" .component -}}
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchLabels: {{- (include "comet-common.selectorLabels" (dict "componentName" $component "customLabels" (dict) "context" .context)) | nindent 10 }}
topologyKey: {{ include "comet-common.affinities.topologyKey" (dict "topologyKey" .topologyKey) }}
weight: 1
{{- end -}}

{{/*
Return a hard podAffinity/podAntiAffinity definition.
Uses comet-common.selectorLabels for matchLabels, passing componentName for app.kubernetes.io/component.
Usage: {{ include "comet-common.affinities.pods.hard" (dict "component" "FOO" "topologyKey" "BAR" "context" $) }}
*/}}
{{- define "comet-common.affinities.pods.hard" -}}
{{- $component := default "" .component -}}
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels: {{- (include "comet-common.selectorLabels" (dict "componentName" $component "customLabels" (dict) "context" .context)) | nindent 8 }}
topologyKey: {{ include "comet-common.affinities.topologyKey" (dict "topologyKey" .topologyKey) }}
{{- end -}}

{{/*
Return a podAffinity/podAntiAffinity definition (dispatches to soft or hard).
Returns empty string when type is "" (disabled).
Usage: {{ include "comet-common.affinities.pods" (dict "type" "soft" "component" "FOO" "context" $) }}
*/}}
{{- define "comet-common.affinities.pods" -}}
{{- if eq .type "soft" }}
{{- include "comet-common.affinities.pods.soft" . -}}
{{- else if eq .type "hard" }}
{{- include "comet-common.affinities.pods.hard" . -}}
{{- end -}}
{{- end -}}
9 changes: 9 additions & 0 deletions templates/_images.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,12 @@ Return the proper image version (ingores image revision/prerelease info & fallba
{{- print .chart.AppVersion -}}
{{- end -}}
{{- end -}}

{{/*
Return the proper image pull policy.
Resolves: imageRoot.pullPolicy -> default "IfNotPresent"
{{ include "comet-common.images.pullPolicy" (dict "imageRoot" .Values.path.to.the.image) }}
*/}}
{{- define "comet-common.images.pullPolicy" -}}
{{- .imageRoot.pullPolicy | default "IfNotPresent" -}}
{{- end -}}
147 changes: 147 additions & 0 deletions templates/_mysql.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{{/*
MySQL configuration helpers.
All helpers read from .Values.global.mysql.* which are propagated by Helm's
global value mechanism from the umbrella chart.

Usage:
{{ include "comet-common.mysql.host" . }}
{{ include "comet-common.mysql.url" . }}
{{ include "comet-common.mysql.readOnlyUrl" . }}
*/}}

{{/* ---- Basic Connection Settings ---- */}}

{{- define "comet-common.mysql.host" -}}
{{- .Values.global.mysql.mysqlHost | default "comet-ml-mysql" -}}
{{- end -}}

{{- define "comet-common.mysql.port" -}}
{{- .Values.global.mysql.mysqlPort | default 3306 -}}
{{- end -}}

{{- define "comet-common.mysql.database" -}}
{{- .Values.global.mysql.mysqlDatabase | default "comet" -}}
{{- end -}}

{{- define "comet-common.mysql.username" -}}
{{- .Values.global.mysql.mysqlUser | default "" -}}
{{- end -}}

{{- define "comet-common.mysql.password" -}}
{{- .Values.global.mysql.mysqlPassword | default "" -}}
{{- end -}}

{{/* ---- Admin Credentials (fallback to regular creds) ---- */}}

{{- define "comet-common.mysql.adminUsername" -}}
{{- default (include "comet-common.mysql.username" .) .Values.global.mysql.mysqlAdminUser -}}
{{- end -}}

{{- define "comet-common.mysql.adminPassword" -}}
{{- default (include "comet-common.mysql.password" .) .Values.global.mysql.mysqlAdminPassword -}}
{{- end -}}

{{/* ---- TLS / Security ---- */}}

{{- define "comet-common.mysql.useTLS" -}}
{{- .Values.global.mysql.useTLS | default false -}}
{{- end -}}

{{- define "comet-common.mysql.requireTLS" -}}
{{- .Values.global.mysql.requireTLS | default false -}}
{{- end -}}

{{- define "comet-common.mysql.verifyServerCert" -}}
{{- .Values.global.mysql.verifyServerCert | default false -}}
{{- end -}}

{{- define "comet-common.mysql.allowPublicKeyRetrieval" -}}
{{- .Values.global.mysql.allowPublicKeyRetrieval | default false -}}
{{- end -}}

{{/* ---- AWS / IAM ---- */}}

{{- define "comet-common.mysql.awsRegion" -}}
{{- .Values.global.mysql.awsRegion | default "us-east-1" -}}
{{- end -}}

{{- define "comet-common.mysql.iamEnabled" -}}
{{- .Values.global.mysql.mysqlIamEnabled | default false -}}
{{- end -}}

{{- define "comet-common.mysql.iamServiceAccountEnabled" -}}
{{- .Values.global.mysql.mysqlIamServiceAccountEnabled | default false -}}
{{- end -}}

{{/* ---- Connection Pool ---- */}}

{{- define "comet-common.mysql.maxPoolSize" -}}
{{- .Values.global.mysql.maxPoolSize | default 50 -}}
{{- end -}}

{{/* ---- Replicated MySQL (read-write / read-only) ---- */}}

{{- define "comet-common.mysql.rw.host" -}}
{{- default (include "comet-common.mysql.host" .) .Values.global.mysql.replicated.rw.host -}}
{{- end -}}

{{- define "comet-common.mysql.rw.username" -}}
{{- default (include "comet-common.mysql.username" .) .Values.global.mysql.replicated.rw.user -}}
{{- end -}}

{{- define "comet-common.mysql.rw.password" -}}
{{- default (include "comet-common.mysql.password" .) .Values.global.mysql.replicated.rw.password -}}
{{- end -}}

{{- define "comet-common.mysql.ro.host" -}}
{{- default (include "comet-common.mysql.host" .) .Values.global.mysql.replicated.ro.host -}}
{{- end -}}

{{- define "comet-common.mysql.ro.username" -}}
{{- default (include "comet-common.mysql.username" .) .Values.global.mysql.replicated.ro.user -}}
{{- end -}}

{{- define "comet-common.mysql.ro.password" -}}
{{- default (include "comet-common.mysql.password" .) .Values.global.mysql.replicated.ro.password -}}
{{- end -}}

{{/* ---- Connection URL Builders ---- */}}

{{/*
MySQL connection URL builder (replicated-aware).
When replicated.enabled is true, uses read-write credentials; otherwise uses primary.
Usage: {{ include "comet-common.mysql.url" . }}
*/}}
{{- define "comet-common.mysql.url" }}
{{- $port := include "comet-common.mysql.port" . -}}
{{- $database := include "comet-common.mysql.database" . -}}
{{- if .Values.global.mysql.replicated.enabled -}}
{{- $host := include "comet-common.mysql.rw.host" . -}}
{{- $user := include "comet-common.mysql.rw.username" . -}}
{{- $password := include "comet-common.mysql.rw.password" . -}}
{{- printf "mysql://%s:%s@%s:%s/%s" $user $password $host $port $database -}}
{{- else -}}
{{- $host := include "comet-common.mysql.host" . -}}
{{- $user := include "comet-common.mysql.username" . -}}
{{- $password := include "comet-common.mysql.password" . -}}
{{- printf "mysql://%s:%s@%s:%s/%s" $user $password $host $port $database -}}
{{- end -}}
{{- end }}

{{/*
MySQL read-only connection URL builder.
Returns read-only URL when replicated.enabled, otherwise falls back to primary URL.
Usage: {{ include "comet-common.mysql.readOnlyUrl" . }}
*/}}
{{- define "comet-common.mysql.readOnlyUrl" }}
{{- if .Values.global.mysql.replicated.enabled -}}
{{- $port := include "comet-common.mysql.port" . -}}
{{- $database := include "comet-common.mysql.database" . -}}
{{- $host := include "comet-common.mysql.ro.host" . -}}
{{- $user := include "comet-common.mysql.ro.username" . -}}
{{- $password := include "comet-common.mysql.ro.password" . -}}
{{- printf "mysql://%s:%s@%s:%s/%s" $user $password $host $port $database -}}
{{- else -}}
{{- include "comet-common.mysql.url" . -}}
{{- end -}}
{{- end }}
88 changes: 88 additions & 0 deletions templates/_redis.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{{/*
Redis configuration helpers.
All helpers read from .Values.global.redis.* which are propagated by Helm's
global value mechanism from the umbrella chart.

Usage:
{{ include "comet-common.redis.value" (dict "root" . "key" "redisHost" "default" "comet-ml-redis-master") }}
{{ include "comet-common.redis.url" . }}
{{ include "comet-common.redis.url" (dict "root" . "db" "2" "tlsParams" true) }}
*/}}

{{/*
Get Redis configuration value from .Values.global.redis.*
Usage: {{ include "comet-common.redis.value" (dict "root" . "key" "redisHost" "default" "comet-ml-redis-master") }}
*/}}
{{- define "comet-common.redis.value" -}}
{{- $root := .root -}}
{{- $key := .key -}}
{{- $default := .default | default "" -}}
{{- if hasKey $root.Values.global.redis $key -}}
{{- index $root.Values.global.redis $key -}}
{{- else -}}
{{- $default -}}
{{- end -}}
{{- end -}}

{{/*
Build a Redis URL from an explicit config dict.
This is the shared implementation used by both comet-common.redis.url and chart-specific Redis helpers.
Usage: {{ include "comet-common.redis.buildUrl" (dict "host" "localhost" "port" "6379" "token" "NA" "user" "" "tls" "false" "db" "0" "tlsParams" false) }}
*/}}
{{- define "comet-common.redis.buildUrl" -}}
{{- $host := .host -}}
{{- $port := .port | toString -}}
{{- $token := .token | default "NA" | toString -}}
{{- $user := .user | default "" | toString -}}
{{- $tls := .tls | default "false" | toString -}}
{{- $db := .db | default "0" | toString -}}
{{- $tlsParams := .tlsParams | default false -}}
{{- $protocol := ternary "rediss" "redis" (eq $tls "true") -}}
{{- if or (eq $token "NA") (eq $token "") -}}
{{- if $user -}}
{{- printf "%s://%s@%s:%s/%s" $protocol $user $host $port $db -}}
{{- else -}}
{{- printf "%s://%s:%s/%s" $protocol $host $port $db -}}
{{- end -}}
{{- else -}}
{{- $url := "" -}}
{{- if $user -}}
{{- $url = printf "%s://%s:%s@%s:%s/%s" $protocol $user $token $host $port $db -}}
{{- else -}}
{{- $url = printf "%s://:%s@%s:%s/%s" $protocol $token $host $port $db -}}
{{- end -}}
{{- if and (eq $tls "true") $tlsParams -}}
{{- printf "%s?ssl_cert_reqs=none" $url -}}
{{- else -}}
{{- $url -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Generate Redis URL from global.redis.* values.
Supports both simple invocation (passing context directly) and dict-based parameters.
Usage:
{{ include "comet-common.redis.url" . }} # db=0, no TLS params
{{ include "comet-common.redis.url" (dict "root" . "db" "2") }} # db=2
{{ include "comet-common.redis.url" (dict "root" . "db" "5" "tlsParams" true) }} # db=5 with TLS params
*/}}
{{- define "comet-common.redis.url" }}
{{- $root := . -}}
{{- $db := "0" -}}
{{- $tlsParams := false -}}
{{- if kindIs "map" . -}}
{{- $root = .root -}}
{{- $db = .db | default "0" -}}
{{- $tlsParams = .tlsParams | default false -}}
{{- end -}}
{{- include "comet-common.redis.buildUrl" (dict
"host" (include "comet-common.redis.value" (dict "root" $root "key" "redisHost" "default" "comet-redis-master"))
"port" (include "comet-common.redis.value" (dict "root" $root "key" "redisPort" "default" "6379"))
"token" (include "comet-common.redis.value" (dict "root" $root "key" "redisToken" "default" "NA"))
"user" (include "comet-common.redis.value" (dict "root" $root "key" "redisUser"))
"tls" (include "comet-common.redis.value" (dict "root" $root "key" "redisTLS" "default" "false"))
"db" $db
"tlsParams" $tlsParams
) -}}
{{- end }}
Loading