{{- /* Copyright Broadcom, Inc. All Rights Reserved. SPDX-License-Identifier: APACHE-2.0 */}} {{- if (include "valkey-cluster.createStatefulSet" .) }} apiVersion: {{ include "common.capabilities.statefulset.apiVersion" . }} kind: StatefulSet metadata: name: {{ include "common.names.fullname" . }} namespace: {{ .Release.Namespace | quote }} labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }} {{- if .Values.commonAnnotations }} annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} {{- end }} spec: {{- if .Values.valkey.updateStrategy }} updateStrategy: {{- toYaml .Values.valkey.updateStrategy | nindent 4 }} {{- end }} {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.valkey.podLabels .Values.commonLabels ) "context" . ) }} selector: matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 6 }} replicas: {{ .Values.cluster.nodes }} serviceName: {{ include "common.names.fullname" . }}-headless podManagementPolicy: {{ .Values.valkey.podManagementPolicy }} template: metadata: labels: {{- include "common.labels.standard" ( dict "customLabels" $podLabels "context" $ ) | nindent 8 }} {{- if and .Values.metrics.enabled .Values.metrics.podLabels }} {{- toYaml .Values.metrics.podLabels | nindent 8 }} {{- end }} annotations: checksum/scripts: {{ include (print $.Template.BasePath "/scripts-configmap.yaml") . | sha256sum }} {{- if not .Values.existingSecret }} checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }} {{- end }} checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} {{- if .Values.valkey.podAnnotations }} {{- include "common.tplvalues.render" (dict "value" .Values.valkey.podAnnotations "context" $) | nindent 8 }} {{- end }} {{- if and .Values.metrics.enabled .Values.metrics.podAnnotations }} {{- include "common.tplvalues.render" (dict "value" .Values.metrics.podAnnotations "context" $) | nindent 8 }} {{- end }} spec: hostNetwork: {{ .Values.valkey.hostNetwork }} enableServiceLinks: false {{- include "valkey-cluster.imagePullSecrets" . | nindent 6 }} {{- if .Values.podSecurityContext.enabled }} securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.podSecurityContext "context" $) | nindent 8 }} {{- end }} serviceAccountName: {{ include "valkey-cluster.serviceAccountName" . }} automountServiceAccountToken: {{ .Values.valkey.automountServiceAccountToken }} {{- if .Values.valkey.hostAliases }} hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.valkey.hostAliases "context" $) | nindent 8 }} {{- end }} {{- if .Values.valkey.priorityClassName }} priorityClassName: {{ .Values.valkey.priorityClassName }} {{- end }} {{- if .Values.valkey.affinity }} affinity: {{- include "common.tplvalues.render" (dict "value" .Values.valkey.affinity "context" $) | nindent 8 }} {{- else }} affinity: podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.valkey.podAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }} podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.valkey.podAntiAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }} nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.valkey.nodeAffinityPreset.type "key" .Values.valkey.nodeAffinityPreset.key "values" .Values.valkey.nodeAffinityPreset.values) | nindent 10 }} {{- end }} {{- if .Values.valkey.nodeSelector }} nodeSelector: {{- include "common.tplvalues.render" (dict "value" .Values.valkey.nodeSelector "context" $) | nindent 8 }} {{- end }} {{- if .Values.valkey.tolerations }} tolerations: {{- include "common.tplvalues.render" (dict "value" .Values.valkey.tolerations "context" $) | nindent 8 }} {{- end }} {{- if .Values.valkey.shareProcessNamespace }} shareProcessNamespace: {{ .Values.valkey.shareProcessNamespace }} {{- end }} {{- if .Values.valkey.schedulerName }} schedulerName: {{ .Values.valkey.schedulerName | quote }} {{- end }} {{- if .Values.valkey.topologySpreadConstraints }} topologySpreadConstraints: {{- include "common.tplvalues.render" ( dict "value" .Values.valkey.topologySpreadConstraints "context" $ ) | nindent 8 }} {{- end }} containers: - name: {{ include "common.names.fullname" . }} image: {{ include "valkey-cluster.image" . }} imagePullPolicy: {{ .Values.image.pullPolicy | quote }} {{- if .Values.containerSecurityContext.enabled }} securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.containerSecurityContext "context" $) | nindent 12 }} {{- end }} {{- if .Values.diagnosticMode.enabled }} command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }} {{- else if .Values.valkey.command }} command: {{- include "common.tplvalues.render" (dict "value" .Values.valkey.command "context" $) | nindent 12 }} {{- else }} command: ['/bin/bash', '-c'] {{- end }} {{- if .Values.diagnosticMode.enabled }} args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }} {{- else if .Values.valkey.args }} args: {{- include "common.tplvalues.render" (dict "value" .Values.valkey.args "context" $) | nindent 12 }} {{- else if .Values.cluster.externalAccess.enabled }} args: - | # Backwards compatibility change if ! [[ -f /opt/bitnami/valkey/etc/valkey.conf ]]; then cp /opt/bitnami/valkey/etc/valkey-default.conf /opt/bitnami/valkey/etc/valkey.conf fi pod_index=($(echo "$POD_NAME" | tr "-" "\n")) pod_index="${pod_index[-1]}" ips=($(echo "{{ .Values.cluster.externalAccess.service.loadBalancerIP }}" | cut -d [ -f2 | cut -d ] -f 1)) {{- if .Values.cluster.externalAccess.hostMode }} export VALKEY_CLUSTER_ANNOUNCE_HOSTNAME="${ips[$pod_index]}" {{- else }} export VALKEY_CLUSTER_ANNOUNCE_IP="${ips[$pod_index]}" {{- end }} export VALKEY_NODES="${ips[@]}" {{- if .Values.cluster.init }} if [[ "$pod_index" == "0" ]]; then export VALKEY_CLUSTER_CREATOR="yes" export VALKEY_CLUSTER_REPLICAS="{{ .Values.cluster.replicas }}" fi {{- end }} /opt/bitnami/scripts/valkey-cluster/entrypoint.sh /opt/bitnami/scripts/valkey-cluster/run.sh {{- else }} args: - | # Backwards compatibility change if ! [[ -f /opt/bitnami/valkey/etc/valkey.conf ]]; then echo COPYING FILE cp /opt/bitnami/valkey/etc/valkey-default.conf /opt/bitnami/valkey/etc/valkey.conf fi {{- if .Values.cluster.init }} pod_index=($(echo "$POD_NAME" | tr "-" "\n")) pod_index="${pod_index[-1]}" if [[ "$pod_index" == "0" ]]; then export VALKEY_CLUSTER_CREATOR="yes" export VALKEY_CLUSTER_REPLICAS="{{ .Values.cluster.replicas }}" fi {{- end }} /opt/bitnami/scripts/valkey-cluster/entrypoint.sh /opt/bitnami/scripts/valkey-cluster/run.sh {{- end }} env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name {{- if and .Values.cluster.externalAccess.enabled .Values.cluster.externalAccess.hostMode }} - name: VALKEY_CLUSTER_DYNAMIC_IPS value: "yes" - name: VALKEY_CLUSTER_PREFERRED_ENDPOINT_TYPE value: "hostname" {{- else if .Values.cluster.externalAccess.enabled }} - name: VALKEY_CLUSTER_DYNAMIC_IPS value: "no" {{- else }} - name: VALKEY_NODES value: "{{ $count := .Values.cluster.nodes | int }}{{ range $i, $v := until $count }}{{ include "common.names.fullname" $ }}-{{ $i }}.{{ template "common.names.fullname" $ }}-headless {{ end }}" {{- end }} {{- if .Values.usePassword }} - name: REDISCLI_AUTH valueFrom: secretKeyRef: name: {{ template "valkey-cluster.secretName" . }} key: {{ template "valkey-cluster.secretPasswordKey" . }} {{- if .Values.usePasswordFiles }} - name: VALKEY_PASSWORD_FILE value: "/opt/bitnami/valkey/secrets/valkey-password" {{- else }} - name: VALKEY_PASSWORD valueFrom: secretKeyRef: name: {{ template "valkey-cluster.secretName" . }} key: {{ template "valkey-cluster.secretPasswordKey" . }} {{- end }} {{- else }} - name: ALLOW_EMPTY_PASSWORD value: "yes" {{- end }} - name: VALKEY_AOF_ENABLED value: {{ .Values.valkey.useAOFPersistence | quote }} - name: VALKEY_TLS_ENABLED value: {{ ternary "yes" "no" .Values.tls.enabled | quote }} {{- if .Values.tls.enabled }} - name: VALKEY_TLS_PORT_NUMBER value: {{ .Values.valkey.containerPorts.valkey | quote }} - name: VALKEY_TLS_AUTH_CLIENTS value: {{ ternary "yes" "no" .Values.tls.authClients | quote }} - name: VALKEY_TLS_CERT_FILE value: {{ template "valkey-cluster.tlsCert" . }} - name: VALKEY_TLS_KEY_FILE value: {{ template "valkey-cluster.tlsCertKey" . }} - name: VALKEY_TLS_CA_FILE value: {{ template "valkey-cluster.tlsCACert" . }} {{- if .Values.tls.dhParamsFilename }} - name: VALKEY_TLS_DH_PARAMS_FILE value: {{ template "valkey-cluster.tlsDHParams" . }} {{- end }} {{- else }} - name: VALKEY_PORT_NUMBER value: {{ .Values.valkey.containerPorts.valkey | quote }} {{- end }} {{- if .Values.valkey.extraEnvVars }} {{- include "common.tplvalues.render" ( dict "value" .Values.valkey.extraEnvVars "context" $ ) | nindent 12 }} {{- end }} {{- if or .Values.valkey.extraEnvVarsCM .Values.valkey.extraEnvVarsSecret }} envFrom: {{- if .Values.valkey.extraEnvVarsCM }} - configMapRef: name: {{ include "common.tplvalues.render" ( dict "value" .Values.valkey.extraEnvVarsCM "context" $ ) }} {{- end }} {{- if .Values.valkey.extraEnvVarsSecret }} - secretRef: name: {{ include "common.tplvalues.render" ( dict "value" .Values.valkey.extraEnvVarsSecret "context" $ ) }} {{- end }} {{- end }} ports: - name: tcp-redis containerPort: {{ .Values.valkey.containerPorts.valkey }} - name: tcp-redis-bus containerPort: {{ .Values.valkey.containerPorts.bus }} {{- if not .Values.diagnosticMode.enabled }} {{- if .Values.valkey.customLivenessProbe }} livenessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.valkey.customLivenessProbe "context" $) | nindent 12 }} {{- else if .Values.valkey.livenessProbe.enabled }} livenessProbe: initialDelaySeconds: {{ .Values.valkey.livenessProbe.initialDelaySeconds }} periodSeconds: {{ .Values.valkey.livenessProbe.periodSeconds }} # One second longer than command timeout should prevent generation of zombie processes. timeoutSeconds: {{ add1 .Values.valkey.livenessProbe.timeoutSeconds }} successThreshold: {{ .Values.valkey.livenessProbe.successThreshold }} failureThreshold: {{ .Values.valkey.livenessProbe.failureThreshold }} exec: command: - sh - -c - /scripts/ping_liveness_local.sh {{ .Values.valkey.livenessProbe.timeoutSeconds }} {{- end }} {{- if .Values.valkey.customReadinessProbe }} readinessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.valkey.customReadinessProbe "context" $) | nindent 12 }} {{- else if .Values.valkey.readinessProbe.enabled }} readinessProbe: initialDelaySeconds: {{ .Values.valkey.readinessProbe.initialDelaySeconds }} periodSeconds: {{ .Values.valkey.readinessProbe.periodSeconds }} # One second longer than command timeout should prevent generation of zombie processes. timeoutSeconds: {{ add1 .Values.valkey.readinessProbe.timeoutSeconds }} successThreshold: {{ .Values.valkey.readinessProbe.successThreshold }} failureThreshold: {{ .Values.valkey.readinessProbe.failureThreshold }} exec: command: - sh - -c - /scripts/ping_readiness_local.sh {{ .Values.valkey.readinessProbe.timeoutSeconds }} {{- end }} {{- if .Values.valkey.customStartupProbe }} startupProbe: {{- include "common.tplvalues.render" (dict "value" .Values.valkey.customStartupProbe "context" $) | nindent 12 }} {{- else if .Values.valkey.startupProbe.enabled }} startupProbe: tcpSocket: port: tcp-redis initialDelaySeconds: {{ .Values.valkey.startupProbe.initialDelaySeconds }} periodSeconds: {{ .Values.valkey.startupProbe.periodSeconds }} timeoutSeconds: {{ .Values.valkey.startupProbe.timeoutSeconds }} successThreshold: {{ .Values.valkey.startupProbe.successThreshold }} failureThreshold: {{ .Values.valkey.startupProbe.failureThreshold }} {{- end }} {{- if .Values.valkey.lifecycleHooks }} lifecycle: {{- include "common.tplvalues.render" (dict "value" .Values.valkey.lifecycleHooks "context" $) | nindent 12 }} {{- end }} {{- end }} {{- if .Values.valkey.resources }} resources: {{- toYaml .Values.valkey.resources | nindent 12 }} {{- else if ne .Values.valkey.resourcesPreset "none" }} resources: {{- include "common.resources.preset" (dict "type" .Values.valkey.resourcesPreset) | nindent 12 }} {{- end }} volumeMounts: - name: scripts mountPath: /scripts {{- if and .Values.usePassword .Values.usePasswordFiles }} - name: valkey-password mountPath: /opt/bitnami/valkey/secrets/ {{- end }} - name: valkey-data mountPath: {{ .Values.persistence.path }} subPath: {{ .Values.persistence.subPath }} - name: default-config mountPath: /opt/bitnami/valkey/etc/valkey-default.conf subPath: valkey-default.conf - name: empty-dir mountPath: /opt/bitnami/valkey/etc/ subPath: app-conf-dir - name: empty-dir mountPath: /opt/bitnami/valkey/tmp subPath: app-tmp-dir - name: empty-dir mountPath: /opt/bitnami/valkey/logs subPath: app-logs-dir - name: empty-dir mountPath: /tmp subPath: tmp-dir {{- if .Values.tls.enabled }} - name: valkey-certificates mountPath: /opt/bitnami/valkey/certs readOnly: true {{- end }} {{- if .Values.valkey.extraVolumeMounts }} {{- include "common.tplvalues.render" ( dict "value" .Values.valkey.extraVolumeMounts "context" $ ) | nindent 12 }} {{- end }} {{- if .Values.metrics.enabled }} - name: metrics image: {{ template "valkey-cluster.metrics.image" . }} imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }} {{- if .Values.metrics.containerSecurityContext.enabled }} securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.metrics.containerSecurityContext "context" $) | nindent 12 }} {{- end }} {{- if .Values.diagnosticMode.enabled }} command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }} args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }} {{- else }} command: - /bin/bash - -c - | {{- if and .Values.usePassword .Values.usePasswordFiles }} export REDIS_PASSWORD="$(< "${REDIS_PASSWORD_FILE}")" {{- end }} redis_exporter{{- range $key, $value := .Values.metrics.extraArgs }} --{{ $key }}={{ $value }}{{- end }} {{- end }} env: - name: BITNAMI_DEBUG value: {{ ternary "true" "false" (or .Values.image.debug .Values.diagnosticMode.enabled) | quote }} - name: REDIS_ALIAS value: {{ template "common.names.fullname" . }} - name: REDIS_ADDR value: {{ printf "%s://127.0.0.1:%g" (ternary "rediss" "redis" .Values.tls.enabled) .Values.valkey.containerPorts.valkey | quote }} {{- if .Values.usePassword }} {{- if .Values.usePasswordFiles }} - name: REDIS_PASSWORD_FILE value: "/opt/bitnami/valkey/secrets/valkey-password" {{- else }} - name: REDIS_PASSWORD valueFrom: secretKeyRef: name: {{ template "valkey-cluster.secretName" . }} key: {{ template "valkey-cluster.secretPasswordKey" . }} {{- end }} {{- end }} {{- if .Values.tls.enabled }} - name: REDIS_EXPORTER_TLS_CLIENT_KEY_FILE value: {{ template "valkey-cluster.tlsCertKey" . }} - name: REDIS_EXPORTER_TLS_CLIENT_CERT_FILE value: {{ template "valkey-cluster.tlsCert" . }} - name: REDIS_EXPORTER_TLS_CA_CERT_FILE value: {{ template "valkey-cluster.tlsCACert" . }} {{- end }} - name: REDIS_EXPORTER_WEB_LISTEN_ADDRESS value: {{ printf ":%v" .Values.metrics.containerPorts.http }} {{- if .Values.metrics.extraEnvVars }} {{- include "common.tplvalues.render" (dict "value" .Values.metrics.extraEnvVars "context" $) | nindent 12 }} {{- end }} {{- if or (and .Values.usePassword .Values.usePasswordFiles) .Values.tls.enabled }} volumeMounts: - name: empty-dir mountPath: /tmp subPath: tmp-dir {{- if and .Values.usePassword .Values.usePasswordFiles }} - name: valkey-password mountPath: /opt/bitnami/valkey/secrets/ {{- end }} {{- if .Values.tls.enabled }} - name: valkey-certificates mountPath: /opt/bitnami/valkey/certs readOnly: true {{- end }} {{- end }} ports: - name: http-metrics containerPort: {{ .Values.metrics.containerPorts.http }} {{- if .Values.metrics.resources }} resources: {{- toYaml .Values.metrics.resources | nindent 12 }} {{- else if ne .Values.metrics.resourcesPreset "none" }} resources: {{- include "common.resources.preset" (dict "type" .Values.metrics.resourcesPreset) | nindent 12 }} {{- end }} {{- end }} {{- if .Values.valkey.sidecars }} {{- include "common.tplvalues.render" ( dict "value" .Values.valkey.sidecars "context" $ ) | nindent 8 }} {{- end }} {{- $needsVolumePermissions := and .Values.volumePermissions.enabled .Values.containerSecurityContext.enabled }} {{- if or $needsVolumePermissions .Values.sysctlImage.enabled .Values.valkey.initContainers }} initContainers: {{- if $needsVolumePermissions }} - name: volume-permissions image: {{ include "valkey-cluster.volumePermissions.image" . }} imagePullPolicy: {{ .Values.volumePermissions.image.pullPolicy | quote }} command: ["/bin/chown", "-R", "{{ .Values.containerSecurityContext.runAsUser }}:{{ .Values.podSecurityContext.fsGroup }}", "{{ .Values.persistence.path }}"] securityContext: runAsUser: 0 {{- if .Values.volumePermissions.resources }} resources: {{- toYaml .Values.volumePermissions.resources | nindent 12 }} {{- else if ne .Values.volumePermissions.resourcesPreset "none" }} resources: {{- include "common.resources.preset" (dict "type" .Values.volumePermissions.resourcesPreset) | nindent 12 }} {{- end }} volumeMounts: - name: empty-dir mountPath: /tmp subPath: tmp-dir - name: valkey-data mountPath: {{ .Values.persistence.path }} subPath: {{ .Values.persistence.subPath }} {{- end }} {{- if .Values.sysctlImage.enabled }} - name: init-sysctl image: {{ template "valkey-cluster.sysctl.image" . }} imagePullPolicy: {{ default "" .Values.sysctlImage.pullPolicy | quote }} {{- if .Values.sysctlImage.resources }} resources: {{- toYaml .Values.sysctlImage.resources | nindent 12 }} {{- else if ne .Values.sysctlImage.resourcesPreset "none" }} resources: {{- include "common.resources.preset" (dict "type" .Values.sysctlImage.resourcesPreset) | nindent 12 }} {{- end }} {{- if .Values.sysctlImage.mountHostSys }} volumeMounts: - name: empty-dir mountPath: /tmp subPath: tmp-dir - name: host-sys mountPath: /host-sys {{- end }} command: {{- toYaml .Values.sysctlImage.command | nindent 12 }} {{- if .Values.sysctlImage.containerSecurityContext.enabled }} securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.sysctlImage.containerSecurityContext "context" $) | nindent 12 }} {{- end }} {{- end }} {{- if .Values.valkey.initContainers }} {{- toYaml .Values.valkey.initContainers | nindent 8 }} {{- end }} {{- end }} volumes: - name: scripts configMap: name: {{ include "common.names.fullname" . }}-scripts defaultMode: 0755 {{- if and .Values.usePassword .Values.usePasswordFiles }} - name: valkey-password secret: secretName: {{ include "valkey-cluster.secretName" . }} items: - key: {{ include "valkey-cluster.secretPasswordKey" . }} path: valkey-password {{- end }} - name: default-config configMap: name: {{ include "common.names.fullname" . }}-default {{- if .Values.sysctlImage.mountHostSys }} - name: host-sys hostPath: path: /sys {{- end }} - name: empty-dir emptyDir: {} {{- if .Values.valkey.extraVolumes }} {{- include "common.tplvalues.render" ( dict "value" .Values.valkey.extraVolumes "context" $ ) | nindent 8 }} {{- end }} {{- if .Values.tls.enabled }} - name: valkey-certificates secret: secretName: {{ include "valkey-cluster.tlsSecretName" . }} defaultMode: 256 {{- end }} {{- if not .Values.persistence.enabled }} - name: valkey-data emptyDir: {} {{- end }} {{- if .Values.persistentVolumeClaimRetentionPolicy.enabled }} persistentVolumeClaimRetentionPolicy: whenDeleted: {{ .Values.persistentVolumeClaimRetentionPolicy.whenDeleted }} whenScaled: {{ .Values.persistentVolumeClaimRetentionPolicy.whenScaled }} {{- end }} {{- if .Values.persistence.enabled }} volumeClaimTemplates: - metadata: name: valkey-data labels: {{- include "common.labels.matchLabels" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 10 }} {{- if .Values.persistence.labels }} {{- include "common.tplvalues.render" (dict "value" .Values.persistence.labels "context" $) | nindent 10 }} {{- end }} {{- if .Values.persistence.annotations }} annotations: {{- include "common.tplvalues.render" (dict "value" .Values.persistence.annotations "context" $) | nindent 10 }} {{- end }} spec: accessModes: {{- range .Values.persistence.accessModes }} - {{ . | quote }} {{- end }} resources: requests: storage: {{ .Values.persistence.size | quote }} {{- include "common.storage.class" (dict "persistence" .Values.persistence "global" .Values.global) | nindent 8 }} {{- if or .Values.persistence.matchLabels .Values.persistence.matchExpressions }} selector: {{- if .Values.persistence.matchLabels }} matchLabels: {{- toYaml .Values.persistence.matchLabels | nindent 12 }} {{- end -}} {{- if .Values.persistence.matchExpressions }} matchExpressions: {{- toYaml .Values.persistence.matchExpressions | nindent 12 }} {{- end -}} {{- end }} {{- end }} {{- end }}