7 Commits

Author SHA1 Message Date
12c34af01a feat(misc): adding test kustomization 2025-07-24 09:57:45 +02:00
38650b32c5 feat(node): adding node component
Cleaning up the repo
2025-07-24 09:57:45 +02:00
fef4f1d899 fix(node): disable replacements
Some checks failed
Build and Push Image / Build and push image (push) Failing after 12s
2025-05-28 15:47:17 +02:00
27ffba8dc1 fix(node): changing statefulset name here is a bad idea
Some checks failed
Build and Push Image / Build and push image (push) Failing after 12s
2025-05-28 15:31:05 +02:00
5d739cbb0c fix(node): change default service name to valkey-node
Some checks failed
Build and Push Image / Build and push image (push) Failing after 13s
2025-05-28 15:22:19 +02:00
09c6791509 fix(node): use headless service in all the scripts
Some checks failed
Build and Push Image / Build and push image (push) Failing after 13s
2025-05-28 11:11:12 +02:00
3c550b3015 feat(node): support for name replacement
Some checks failed
Build and Push Image / Build and push image (push) Failing after 13s
now when you include this project you can change then service and statefulset name from
the valkey-env configMap
2025-05-28 10:57:50 +02:00
30 changed files with 318 additions and 241 deletions

View File

@ -1,5 +1,5 @@
{{- $hostname := env "HOSTNAME" }}
{{- $service := env "VALKEY_SERVICE" }}
{{- $service := env "VALKEY_HEADLESS_SERVICE" }}
{{- $namespace := env "NAMESPACE" }}
{{- $port := env "VALKEY_PORT" }}
{{- $sentinel_port := env "VALKEY_SENTINEL_PORT" }}

View File

@ -1,5 +1,5 @@
{{- $hostname := env "HOSTNAME" }}
{{- $service := env "VALKEY_SERVICE" }}
{{- $service := env "VALKEY_HEADLESS_SERVICE" }}
{{- $namespace := env "NAMESPACE" }}
{{- $port := env "VALKEY_PORT" }}
{{- $sentinel_port := env "VALKEY_SENTINEL_PORT" }}

View File

@ -1,19 +1,21 @@
{{- $hostname := env "HOSTNAME" }}
{{- $service := env "VALKEY_SERVICE" }}
{{- $service := env "VALKEY_HEADLESS_SERVICE" }}
{{- $namespace := env "NAMESPACE" }}
{{- $port := env "VALKEY_PORT" }}
{{- $name := env "VALKEY_NAME" }}
{{- $sentinel_port := env "VALKEY_SENTINEL_PORT" }}
{{- $replicas := env "VALKEY_REPLICAS" }}
{{- $domain := printf "%s.%s.svc.cluster.local" $service $namespace }}
{{- $fqdn := printf "%s.%s" $hostname $domain }}
{{- $hostid := sha1sum $hostname }}
{{- $quorum := env "VALKEY_QUORUM" }}
{{- $master_name := env "VALKEY_MASTER_NAME" }}
#-REPLICAS:{{ $replicas }}
dir "/tmp"
port {{ $sentinel_port }}
sentinel monitor mymaster SENTINEL_MASTER {{ $port }} {{ $quorum }}
sentinel down-after-milliseconds mymaster 60000
sentinel monitor {{ $master_name }} SENTINEL_MASTER {{ $port }} {{ $quorum }}
sentinel down-after-milliseconds {{ $master_name }} 60000
# User-supplied sentinel configuration:
# End of sentinel configuration
@ -31,16 +33,17 @@ protected-mode no
# gotemplate-pause!
user default on nopass sanitize-payload ~* &* +@all
# gotemplate-resume!
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel config-epoch {{ $master_name }} 0
sentinel leader-epoch {{ $master_name }} 0
sentinel current-epoch 0
{{- range $i, $e := until ( int $replicas ) }}
{{- $ndeHostname := printf "valkey-node-%d" $i }}
{{- $masterName := printf "%s" $master_name}}
{{- $ndeHostname := printf "%s-%d" $name $i }}
{{- $ndeFQDN := printf "%s.%s" $ndeHostname $domain }}
{{- $nodeID := sha1sum $ndeHostname }}
{{- if (ne $fqdn $ndeFQDN) }}
sentinel {{ printf "known-sentinel mymaster %s %s %s" $ndeFQDN $sentinel_port $nodeID }}
sentinel {{ printf "known-replica mymaster %s %s" $ndeFQDN $port }}
sentinel {{ printf "known-sentinel %s %s %s %s" $masterName $ndeFQDN $sentinel_port $nodeID }}
sentinel {{ printf "known-replica %s %s %s" $masterName $ndeFQDN $port }}
{{- end}}
{{- end}}

View File

@ -2,7 +2,7 @@
pingSentinel() {
svc=${VALKEY_SERVICE:-"localhost"}
svc=${VALKEY_HEADLESS_SERVICE:-"localhost"}
resp=$(timeout -s 15 $1 \
valkey-cli \
@ -15,8 +15,30 @@ pingSentinel() {
}
getPrimaryInfo() {
valkey-cli --csv -h ${VALKEY_SERVICE} -p ${VALKEY_SENTINEL_PORT} sentinel get-primary-addr-by-name "mymaster"| \
awk -F ',' '{ gsub(/"/,"",$0); print $1 " " $2 }'
masterName=${VALKEY_MASTER_NAME:-"mymaster"}
it="${1:-0}"
info=$(valkey-cli --csv -h ${VALKEY_HEADLESS_SERVICE} -p ${VALKEY_SENTINEL_PORT} sentinel get-primary-addr-by-name "${masterName}"| \
awk -F ',' '{ gsub(/"/,"",$0); print $1 " " $2 }')
if [ -z "${info}" ]; then
echo "Failed to get primary info for master '${masterName}'"
it=$((it + 1))
getPrimaryInfo ${it}
if [ ${it} -ge 10 ]; then
echo "Failed to get primary info after 5 attempts"
return 1
fi
fi
if [[ "${info}" =~ /^NULL/ ]]; then
it=$((it + 1))
getPrimaryInfo ${it}
if [ ${it} -ge 10 ]; then
echo "Failed to get primary info after 5 attempts"
return 1
fi
fi
echo "${info}"
return ${?}
}
@ -76,6 +98,6 @@ sentinelIsMaster() {
sentinelReset() {
# Reset the sentinel
valkey-cli -h ${VALKEY_SERVICE} -p ${VALKEY_SENTINEL_PORT} sentinel reset "${1}"
valkey-cli -h ${VALKEY_HEADLESS_SERVICE} -p ${VALKEY_SENTINEL_PORT} sentinel reset "${1}"
return $?
}

View File

@ -8,14 +8,15 @@ vcli() {
# Run Sentinel command
vcli-sentinel() {
valkey-cli -h "$VALKEY_SERVICE" -p "$VALKEY_SENTINEL_PORT" sentinel "$@"
valkey-cli -h "${VALKEY_HEADLESS_SERVICE}" -p "${VALKEY_SENTINEL_PORT}" sentinel "$@"
return $?
}
getFailOverStatus() {
# Check if the failover is finished
local failoverStatus
primaryInfo=$(vcli-sentinel get-primary-addr-by-name "mymaster")
sentinelMasterName="${VALKEY_MASTER_NAME:-"mymaster"}"
primaryInfo=$(vcli-sentinel get-primary-addr-by-name "${sentinelMasterName}")
primaryHost=$(echo ${primaryInfo} | awk -F ' ' '{print $1}')
currentHost=$(hostname -f)
if [[ "${primaryHost}" != "${currentHost}" ]]; then
@ -44,12 +45,13 @@ isPrimary() {
}
if isPrimary && ! getFailOverStatus; then
sentinelMasterName="${VALKEY_MASTER_NAME}"
echo "I'm the primary and you are stopping me, pausing client connections"
#Pausing write connections to avoid data loss"
vcli CLIENT PAUSE "22000" WRITE
echo "Starting failover"
vcli-sentinel failover "mymaster"
vcli-sentinel failover "${sentinelMasterName}"
echo "Waiting for sentinel to complete failover for up to 120s"
tmout=120
while true ; do

View File

@ -3,7 +3,7 @@
pingSentinel() {
resp=$(timeout -s 15 $1 \
valkey-cli \
-h ${VALKEY_SERVICE} \
-h ${VALKEY_HEADLESS_SERVICE} \
-p ${VALKEY_SENTINEL_PORT} \
ping)
ret=${?}
@ -12,7 +12,8 @@ pingSentinel() {
}
getPrimaryInfo() {
valkey-cli -t 15 --csv -h ${VALKEY_SERVICE} -p ${VALKEY_SENTINEL_PORT} sentinel get-primary-addr-by-name "mymaster"| \
sentinelMasterName="${VALKEY_MASTER_NAME:-"mymaster"}"
valkey-cli -t 15 --csv -h ${VALKEY_HEADLESS_SERVICE} -p ${VALKEY_SENTINEL_PORT} sentinel get-primary-addr-by-name "${sentinelMasterName}"| \
awk -F ',' '{ gsub(/"/,"",$0); print $1 " " $2 }'
return ${?}
}
@ -80,6 +81,10 @@ else
echo "Primary host is : ${primaryHost}, port: ${primaryPort}"
currentHost=$(hostname -f)
echo "Current host is : ${currentHost}"
if [ "${primaryHost}" = "NULL" ]; then
echo "Not primary yet, starting as primary"
startPrimary=1
else
if [ "${primaryHost}" != "${currentHost}" ]; then
echo "Not the primary, setting up as replica"
startPrimary=0
@ -87,6 +92,7 @@ else
echo "This is the primary"
startPrimary=1
fi
fi
fi
if [ "${startPrimary}" -eq 1 ]; then

View File

@ -0,0 +1,44 @@
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
resources:
- resources/sa.yaml
- resources/statefulset.yaml
- resources/svc.yaml
configMapGenerator:
#- name: valkey-env
# literals:
# - NAMESPACE="default"
# - VALKEY_ENV="base"
# - VALKEY_NAME="valkey-node"
# - VALKEY_SERVICE="valkey-node"
# - VALKEY_HEADLESS_SERVICE="valkey-node-headless"
# - VALKEY_MASTER_NAME="mymaster"
# - VALKEY_REPLICAS="4"
# - VALKEY_PORT="6379"
# - VALKEY_SENTINEL_PORT="26379"
# - ALLOW_EMPTY_PASSWORD="yes"
# - VALKEY_TLS_ENABLED="no"
# - VALKEY_SENTINEL_TLS_ENABLED="no"
# - VALKEY_DATA_DIR="/data"
# - VALKEY_LOG_LEVEL="warning"
# - VALKEY_QUORUM="2"
- name: valkey-config
files:
- files/conf/replication.conf.tpl
- files/conf/sentinel.conf.tpl
- name: valkey-scripts
files:
- files/scripts/common.sh
- files/scripts/startSentinel.sh
- files/scripts/pre-stop.sh
- files/scripts/pre-stop-sentinel.sh
- files/scripts/start-node.sh
- files/scripts/ping-sentinel.sh
- files/scripts/liveness-local.sh
- files/scripts/readiness-local.sh
replacements:
- path: replacements/service.yaml
- path: replacements/statefulset.yaml

View File

@ -0,0 +1,15 @@
- source:
kind: ConfigMap
name: valkey-env
fieldPath: data.VALKEY_SERVICE
targets:
- select:
kind: Service
name: valkey-headless
fieldPaths:
- spec.selector.app
- select:
kind: Service
name: valkey
fieldPaths:
- spec.selector.app

View File

@ -0,0 +1,22 @@
- source:
kind: ConfigMap
name: valkey-env
fieldPath: data.VALKEY_REPLICAS
targets:
- select:
kind: StatefulSet
name: valkey-node
fieldPaths:
- spec.replicas
- source:
kind: ConfigMap
name: valkey-env
fieldPath: data.VALKEY_SERVICE
targets:
- select:
kind: StatefulSet
name: valkey-node
fieldPaths:
- metadata.labels.app
- spec.selector.matchLabels.app
- spec.template.metadata.labels.app

View File

@ -2,12 +2,13 @@ apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app: CHANGE_ME
app.kubernetes.io/component: node
app.kubernetes.io/instance: valkey
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: valkey
app.kubernetes.io/part-of: valkey
app.kubernetes.io/version: 8.1.1
app.kubernetes.io/version: 8.1.3
name: valkey-node
spec:
persistentVolumeClaimRetentionPolicy:
@ -23,17 +24,19 @@ spec:
app.kubernetes.io/component: node
app.kubernetes.io/instance: valkey
app.kubernetes.io/name: valkey
app: CHANGE_ME
serviceName: valkey-headless
updateStrategy:
type: RollingUpdate
template:
metadata:
labels:
app: CHANGE_ME
app.kubernetes.io/component: node
app.kubernetes.io/instance: valkey
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: valkey
app.kubernetes.io/version: 8.1.1
app.kubernetes.io/version: 8.1.3
helm.sh/chart: valkey-3.0.7
spec:
shareProcessNamespace: true
@ -107,7 +110,7 @@ spec:
name: valkey-data
containers:
- name: valkey
image: reg.cadoles.com/dh/valkey/valkey:8.1.1-alpine3.21
image: reg.cadoles.com/dh/valkey/valkey:8.1.3-alpine3.22
command:
- /opt/scripts/start-node.sh
args:
@ -194,7 +197,7 @@ spec:
- mountPath: /data
name: valkey-data
- name: sentinel
image: reg.cadoles.com/dh/valkey/valkey:8.1.1-alpine3.21
image: reg.cadoles.com/dh/valkey/valkey:8.1.3-alpine3.22
imagePullPolicy: IfNotPresent
command:
- /opt/scripts/startSentinel.sh
@ -288,8 +291,8 @@ spec:
runAsGroup: 1001
fsGroup: 1001
fsGroupChangePolicy: Always
serviceAccount: valkey
serviceAccountName: valkey
#serviceAccount: valkey
#serviceAccountName: valkey
terminationGracePeriodSeconds: 30
volumes:
- name: valkey-scripts
@ -320,9 +323,6 @@ spec:
resources:
requests:
storage: 8Gi
volumeMode: Filesystem
status:
phase: Pending
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
@ -338,6 +338,3 @@ spec:
resources:
requests:
storage: 32Mi
volumeMode: Filesystem
status:
phase: Pending

View File

@ -2,6 +2,7 @@ apiVersion: v1
kind: Service
metadata:
labels:
app: CHANGE_ME
app.kubernetes.io/component: node
app.kubernetes.io/instance: valkey
app.kubernetes.io/managed-by: kustomize
@ -20,6 +21,7 @@ spec:
protocol: TCP
targetPort: 26379
selector:
app: CHANGE_ME
app.kubernetes.io/component: node
app.kubernetes.io/instance: valkey
app.kubernetes.io/name: valkey
@ -28,10 +30,11 @@ apiVersion: v1
kind: Service
metadata:
labels:
app: CHANGE_ME
app.kubernetes.io/component: node
app.kubernetes.io/instance: valkey
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: valkey
app.kubernetes.io/name: valkey-headless
app.kubernetes.io/part-of: valkey
app.kubernetes.io/version: 8.1.1
name: valkey-headless
@ -48,5 +51,6 @@ spec:
targetPort: valkey-sentinel
publishNotReadyAddresses: true
selector:
app: CHANGE_ME
app.kubernetes.io/instance: valkey
app.kubernetes.io/name: valkey

View File

@ -1,5 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
components:
- resources/node

View File

@ -1,5 +1,5 @@
# Base image
FROM golang:tip-alpine3.21 AS builder
FROM golang:tip-alpine3.22 AS builder
# Set directory to known value
WORKDIR /app
@ -14,7 +14,7 @@ RUN git clone https://github.com/coveooss/gotemplate.git . && \
CGO_ENABLED=0 go build
FROM alpine:3.21
FROM alpine:3.22
#
COPY --from=builder /app/gotemplate /gotemplate
COPY --from=builder /usr/bin/valkey-cli /valkey-cli

View File

@ -0,0 +1,7 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- resources/namespace.yaml
- resources/vlone
- resources/vltwo

View File

@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: vltest

View File

@ -0,0 +1,25 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: vlone-
components:
- https://forge.cadoles.com/CadolesKube/valkey-kustom//components/node
configMapGenerator:
- name: valkey-env
literals:
- NAMESPACE="vltest"
- VALKEY_ENV="vltest"
- VALKEY_NAME="vlone-valkey-node"
- VALKEY_SERVICE="vlone-valkey"
- VALKEY_HEADLESS_SERVICE="vlone-valkey-headless"
- VALKEY_MASTER_NAME="mymaster"
- VALKEY_REPLICAS="6"
- VALKEY_PORT="6379"
- VALKEY_SENTINEL_PORT="26379"
- ALLOW_EMPTY_PASSWORD="yes"
- VALKEY_TLS_ENABLED="no"
- VALKEY_SENTINEL_TLS_ENABLED="no"
- VALKEY_DATA_DIR="/data"
- VALKEY_LOG_LEVEL="warning"
- VALKEY_QUORUM="2"

View File

@ -0,0 +1,20 @@
- source:
kind: ConfigMap
name: vlone
fieldPath: data.VALKEY_HEADLESS_SERVICE
targets:
- select:
kind: Service
name: valkey-headless
fieldPaths:
- metadata.name
- source:
kind: ConfigMap
name: vlone
fieldPath: data.VALKEY_SERVICE
targets:
- select:
kind: Service
name: valkey
fieldPaths:
- metadata.name

View File

@ -0,0 +1,31 @@
- source:
kind: ConfigMap
name: vlone
fieldPath: data.VALKEY_NAME
targets:
- select:
kind: StatefulSet
name: valkey-node
fieldPaths:
- metadata.name
- source:
kind: ConfigMap
name: vlone
fieldPath: data.VALKEY_ENV_NAME
targets:
- select:
kind: StatefulSet
name: valkey-node
fieldPaths:
- spec.template.spec.containers[*].envFrom[0].configMapRef.name
- spec.template.spec.initContainers[*].envFrom[0].configMapRef.name
- source:
kind: ConfigMap
name: vlone
fieldPath: data.VALKEY_CONF_NAME
targets:
- select:
kind: StatefulSet
name: valkey-node
fieldPaths:
- spec.template.spec.initContainers[*].volumeMounts[valkey-config].name

View File

@ -0,0 +1,25 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: vltwo-
components:
- https://forge.cadoles.com/CadolesKube/valkey-kustom//components/node
configMapGenerator:
- name: valkey-env
literals:
- NAMESPACE="vltest"
- VALKEY_ENV="vltest"
- VALKEY_NAME="vltwo-valkey-node"
- VALKEY_SERVICE="vltwo-valkey"
- VALKEY_HEADLESS_SERVICE="vltwo-valkey-headless"
- VALKEY_MASTER_NAME="vltwomaster"
- VALKEY_REPLICAS="4"
- VALKEY_PORT="6379"
- VALKEY_SENTINEL_PORT="26379"
- ALLOW_EMPTY_PASSWORD="yes"
- VALKEY_TLS_ENABLED="no"
- VALKEY_SENTINEL_TLS_ENABLED="no"
- VALKEY_DATA_DIR="/data"
- VALKEY_LOG_LEVEL="warning"
- VALKEY_QUORUM="2"

View File

@ -0,0 +1,20 @@
- source:
kind: ConfigMap
name: vltwo
fieldPath: data.VALKEY_HEADLESS_SERVICE
targets:
- select:
kind: Service
name: valkey-headless
fieldPaths:
- metadata.name
- source:
kind: ConfigMap
name: vltwo
fieldPath: data.VALKEY_SERVICE
targets:
- select:
kind: Service
name: valkey
fieldPaths:
- metadata.name

View File

@ -0,0 +1,31 @@
- source:
kind: ConfigMap
name: vltwo
fieldPath: data.VALKEY_NAME
targets:
- select:
kind: StatefulSet
name: valkey-node
fieldPaths:
- metadata.name
- source:
kind: ConfigMap
name: vltwo
fieldPath: data.VALKEY_ENV_NAME
targets:
- select:
kind: StatefulSet
name: valkey-node
fieldPaths:
- spec.template.spec.containers[*].envFrom[0].configMapRef.name
- spec.template.spec.initContainers[*].envFrom[0].configMapRef.name
- source:
kind: ConfigMap
name: vltwo
fieldPath: data.VALKEY_CONF_NAME
targets:
- select:
kind: StatefulSet
name: valkey-node
fieldPaths:
- spec.template.spec.initContainers[*].volumeMounts[valkey-config].name

View File

@ -1,151 +0,0 @@
#!/bin/bash
. /opt/bitnami/scripts/libos.sh
. /opt/bitnami/scripts/liblog.sh
. /opt/bitnami/scripts/libvalidations.sh
get_port() {
hostname="$1"
type="$2"
port_var=$(echo "${hostname^^}_SERVICE_PORT_$type" | sed "s/-/_/g")
port=${!port_var}
if [ -z "$port" ]; then
case $type in
"SENTINEL")
echo 26379
;;
"VALKEY")
echo 6379
;;
esac
else
echo $port
fi
}
get_full_hostname() {
hostname="$1"
full_hostname="${hostname}.${HEADLESS_SERVICE}"
echo "${full_hostname}"
}
VALKEYPORT=$(get_port "$HOSTNAME" "VALKEY")
HEADLESS_SERVICE="valkey-headless.mse-dev.svc.cluster.local"
if [ -n "$VALKEY_EXTERNAL_PRIMARY_HOST" ]; then
VALKEY_SERVICE="$VALKEY_EXTERNAL_PRIMARY_HOST"
else
VALKEY_SERVICE="valkey.mse-dev.svc.cluster.local"
fi
SENTINEL_SERVICE_PORT=$(get_port "valkey" "SENTINEL")
validate_quorum() {
if is_boolean_yes "$VALKEY_TLS_ENABLED"; then
quorum_info_command="valkey-cli -h $VALKEY_SERVICE -p $SENTINEL_SERVICE_PORT --tls --cert ${VALKEY_TLS_CERT_FILE} --key ${VALKEY
_TLS_KEY_FILE} --cacert ${VALKEY_TLS_CA_FILE} sentinel primary mymaster"
else
quorum_info_command="valkey-cli -h $VALKEY_SERVICE -p $SENTINEL_SERVICE_PORT sentinel primary mymaster"
fi
info "about to run the command: $quorum_info_command"
eval $quorum_info_command | grep -Fq "s_down"
}
trigger_manual_failover() {
if is_boolean_yes "$VALKEY_TLS_ENABLED"; then
failover_command="valkey-cli -h $VALKEY_SERVICE -p $SENTINEL_SERVICE_PORT --tls --cert ${VALKEY_TLS_CERT_FILE} --key ${VALKEY_TL
S_KEY_FILE} --cacert ${VALKEY_TLS_CA_FILE} sentinel failover mymaster"
else
failover_command="valkey-cli -h $VALKEY_SERVICE -p $SENTINEL_SERVICE_PORT sentinel failover mymaster"
fi
info "about to run the command: $failover_command"
eval $failover_command
}
get_sentinel_primary_info() {
if is_boolean_yes "$VALKEY_TLS_ENABLED"; then
sentinel_info_command="timeout 90 valkey-cli -h $VALKEY_SERVICE -p $SENTINEL_SERVICE_PORT --tls --cert ${VALKEY_TLS_CERT_FILE} -
-key ${VALKEY_TLS_KEY_FILE} --cacert ${VALKEY_TLS_CA_FILE} sentinel get-primary-addr-by-name mymaster"
else
sentinel_info_command="timeout 90 valkey-cli -h $VALKEY_SERVICE -p $SENTINEL_SERVICE_PORT sentinel get-primary-addr-by-name myma
ster"
fi
info "about to run the command: $sentinel_info_command"
retry_while "eval $sentinel_info_command" 2 5
}
[[ -f $VALKEY_PASSWORD_FILE ]] && export VALKEY_PASSWORD="$(< "${VALKEY_PASSWORD_FILE}")"
[[ -f $VALKEY_PRIMARY_PASSWORD_FILE ]] && export VALKEY_PRIMARY_PASSWORD="$(< "${VALKEY_PRIMARY_PASSWORD_FILE}")"
# check if there is a primary
primary_in_persisted_conf="$(get_full_hostname "$HOSTNAME")"
primary_port_in_persisted_conf="$VALKEY_PRIMARY_PORT_NUMBER"
primary_in_sentinel="$(get_sentinel_primary_info)"
valkeyRetVal=$?
if [[ -f /opt/bitnami/valkey-sentinel/etc/sentinel.conf ]]; then
primary_in_persisted_conf="$(awk '/monitor/ {print $4}' /opt/bitnami/valkey-sentinel/etc/sentinel.conf)"
primary_port_in_persisted_conf="$(awk '/monitor/ {print $5}' /opt/bitnami/valkey-sentinel/etc/sentinel.conf)"
info "Found previous primary ${primary_in_persisted_conf}:${primary_port_in_persisted_conf} in /opt/bitnami/valkey-sentinel/etc/sent
inel.conf"
debug "$(cat /opt/bitnami/valkey-sentinel/etc/sentinel.conf | grep monitor)"
fi
if [[ $valkeyRetVal -ne 0 ]]; then
if [[ "$primary_in_persisted_conf" == "$(get_full_hostname "$HOSTNAME")" ]]; then
# Case 1: No active sentinel and in previous sentinel.conf we were the primary --> PRIMARY
info "Configuring the node as primary"
export VALKEY_REPLICATION_MODE="primary"
else
# Case 2: No active sentinel and in previous sentinel.conf we were not primary --> REPLICA
info "Configuring the node as replica"
export VALKEY_REPLICATION_MODE="replica"
VALKEY_PRIMARY_HOST=${primary_in_persisted_conf}
VALKEY_PRIMARY_PORT_NUMBER=${primary_port_in_persisted_conf}
fi
else
# Fetches current primary's host and port
VALKEY_SENTINEL_INFO=($(get_sentinel_primary_info))
info "Current primary: VALKEY_SENTINEL_INFO=(${VALKEY_SENTINEL_INFO[0]},${VALKEY_SENTINEL_INFO[1]})"
VALKEY_PRIMARY_HOST=${VALKEY_SENTINEL_INFO[0]}
VALKEY_PRIMARY_PORT_NUMBER=${VALKEY_SENTINEL_INFO[1]}
if [[ "$VALKEY_PRIMARY_HOST" == "$(get_full_hostname "$HOSTNAME")" ]]; then
# Case 3: Active sentinel and primary it is this node --> PRIMARY
info "Configuring the node as primary"
export VALKEY_REPLICATION_MODE="primary"
else
# Case 4: Active sentinel and primary is not this node --> REPLICA
info "Configuring the node as replica"
export VALKEY_REPLICATION_MODE="replica"
fi
fi
if [[ -n "$VALKEY_EXTERNAL_PRIMARY_HOST" ]]; then
VALKEY_PRIMARY_HOST="$VALKEY_EXTERNAL_PRIMARY_HOST"
VALKEY_PRIMARY_PORT_NUMBER="${VALKEY_EXTERNAL_PRIMARY_PORT}"
fi
if [[ -f /opt/bitnami/valkey/mounted-etc/replica.conf ]];then
cp /opt/bitnami/valkey/mounted-etc/replica.conf /opt/bitnami/valkey/etc/replica.conf
fi
if [[ -f /opt/bitnami/valkey/mounted-etc/valkey.conf ]];then
cp /opt/bitnami/valkey/mounted-etc/valkey.conf /opt/bitnami/valkey/etc/valkey.conf
fi
echo "" >> /opt/bitnami/valkey/etc/replica.conf
echo "replica-announce-port $VALKEYPORT" >> /opt/bitnami/valkey/etc/replica.conf
echo "replica-announce-ip $(get_full_hostname "$HOSTNAME")" >> /opt/bitnami/valkey/etc/replica.conf
ARGS=("--port" "${VALKEY_PORT}")
if [[ "$VALKEY_REPLICATION_MODE" = "replica" ]]; then
ARGS+=("--replicaof" "${VALKEY_PRIMARY_HOST}" "${VALKEY_PRIMARY_PORT_NUMBER}")
fi
ARGS+=("--protected-mode" "no")
ARGS+=("--include" "/opt/bitnami/valkey/etc/replica.conf")
ARGS+=("--include" "/opt/bitnami/valkey/etc/valkey.conf")
exec valkey-server "${ARGS[@]}"

View File

@ -1,40 +0,0 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- resources/sa.yaml
- resources/statefulset.yaml
- resources/svc.yaml
replacements:
- path: ./replacements/replicas.yaml
configMapGenerator:
- name: valkey-env
literals:
- NAMESPACE="default"
- VALKEY_ENV="base"
- VALKEY_SERVICE="valkey-headless"
- VALKEY_REPLICAS="4"
- VALKEY_PORT="6379"
- VALKEY_SENTINEL_PORT="26379"
- ALLOW_EMPTY_PASSWORD="yes"
- VALKEY_TLS_ENABLED="no"
- VALKEY_SENTINEL_TLS_ENABLED="no"
- VALKEY_DATA_DIR="/data"
- VALKEY_LOG_LEVEL="warning"
- VALKEY_QUORUM="2"
- name: valkey-config
files:
- files/conf/replication.conf.tpl
- files/conf/sentinel.conf.tpl
- name: valkey-scripts
files:
- files/scripts/common.sh
- files/scripts/startSentinel.sh
- files/scripts/pre-stop.sh
- files/scripts/pre-stop-sentinel.sh
- files/scripts/start-node.sh
- files/scripts/ping-sentinel.sh
- files/scripts/liveness-local.sh
- files/scripts/readiness-local.sh

View File

@ -1,10 +0,0 @@
- source:
kind: ConfigMap
name: valkey-env
fieldPath: data.VALKEY_REPLICAS
targets:
- select:
kind: StatefulSet
name: valkey-node
fieldPaths:
- spec.replicas