From b616188b77df4e42dcc91323228a8284ac917d9b Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Tue, 6 Feb 2024 19:46:54 +0800
Subject: [PATCH 01/21] chore(redis): headless svc does not require ports

---
 charts/redis/templates/redis-svc.yaml | 2 --
 1 file changed, 2 deletions(-)

diff --git a/charts/redis/templates/redis-svc.yaml b/charts/redis/templates/redis-svc.yaml
index 3f4b709..0a47609 100644
--- a/charts/redis/templates/redis-svc.yaml
+++ b/charts/redis/templates/redis-svc.yaml
@@ -13,6 +13,4 @@ spec:
   clusterIP: None
   selector:
     app: drycc-redis
-  ports:
-  - port: 6379
 {{- end }}

From 256940639249023ca0105c7dcd89d5b6cf8389a8 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Mon, 4 Mar 2024 16:06:39 +0800
Subject: [PATCH 02/21] chore(charts): add diagnostic mode

---
 charts/redis/templates/redis-statefulset.yaml |  5 +++++
 charts/redis/values.yaml                      | 15 +++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/charts/redis/templates/redis-statefulset.yaml b/charts/redis/templates/redis-statefulset.yaml
index a51ba06..2189955 100644
--- a/charts/redis/templates/redis-statefulset.yaml
+++ b/charts/redis/templates/redis-statefulset.yaml
@@ -36,10 +36,15 @@ spec:
             memory: {{.Values.limitsMemory}}
             {{- end}}
         {{- end}}
+        {{- if .Values.diagnosticMode.enabled }}
+        command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 10 }}
+        args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 10 }}
+        {{- else }}
         args:
         - "/bin/boot"
         - "--port"
         - "6379"
+        {{- end }}
         ports:
         - containerPort: 6379
         env:
diff --git a/charts/redis/values.yaml b/charts/redis/values.yaml
index 55e9d6e..d4d54d1 100644
--- a/charts/redis/values.yaml
+++ b/charts/redis/values.yaml
@@ -5,6 +5,21 @@ imageRegistry: "registry.drycc.cc"
 # limitsCpu: "100m"
 # limitsMemory: "50Mi"
 
+## Enable diagnostic mode
+##
+diagnosticMode:
+  ## @param diagnosticMode.enabled Enable diagnostic mode (all probes will be disabled and the command will be overridden)
+  ##
+  enabled: false
+  ## @param diagnosticMode.command Command to override all containers
+  ##
+  command:
+    - sleep
+  ## @param diagnosticMode.args Args to override all containers
+  ##
+  args:
+    - infinity
+
 nodeAffinityPreset:
   key: "drycc.cc/node"
   type: "soft"

From 79f8852bd9c819aaba85515bfa38f85cadcec422 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Wed, 6 Mar 2024 11:34:51 +0800
Subject: [PATCH 03/21] feat(charts): reuses the value from an existing secret
 and config

---
 charts/redis/templates/redis-secret-creds.yaml | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/charts/redis/templates/redis-secret-creds.yaml b/charts/redis/templates/redis-secret-creds.yaml
index ca96a29..8957eb3 100644
--- a/charts/redis/templates/redis-secret-creds.yaml
+++ b/charts/redis/templates/redis-secret-creds.yaml
@@ -5,17 +5,15 @@ metadata:
   labels:
     app: drycc-redis
     heritage: drycc
-  annotations:
-    "helm.sh/hook": pre-install
 data: 
   {{ if eq .Values.global.redisLocation "on-cluster"}}
   {{- $redisAddrs := (list ) }}
-  {{ $redisNodeCount := .Values.replicas | int }}
+  {{- $redisNodeCount := .Values.replicas | int }}
   {{- range $i := until $redisNodeCount }}
   {{- $redisAddrs = (append $redisAddrs (printf "drycc-redis-%d.drycc-redis.%s.svc.%s:6379" $i $.Release.Namespace $.Values.global.clusterDomain)) }}
   {{- end -}}
   addrs: {{ join "," $redisAddrs | b64enc }}
-  password: {{ randAlphaNum 32 | b64enc }}
+  password: {{ include "common.secrets.lookup" (dict "secret" "redis-creds" "key" "password" "defaultValue" (randAlphaNum 32) "context" $) }}
   {{ else if eq .Values.global.redisLocation "off-cluster"}}
   addrs: {{ .Values.addrs | b64enc }}
   password: {{ .Values.password | b64enc }}

From fb4bb9f84c1987edc18680cba9f4d7aeaf3fee7d Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Mon, 18 Mar 2024 16:47:00 +0800
Subject: [PATCH 04/21] chore(woodpecker): migrations woodpecker-ci to 2

---
 .woodpecker/build-linux.yml | 5 ++---
 .woodpecker/chart.yaml      | 6 ++----
 .woodpecker/manifest.yml    | 5 ++---
 .woodpecker/test-linux.yml  | 5 ++---
 4 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/.woodpecker/build-linux.yml b/.woodpecker/build-linux.yml
index 8cdd984..f411033 100644
--- a/.woodpecker/build-linux.yml
+++ b/.woodpecker/build-linux.yml
@@ -3,12 +3,11 @@ matrix:
     - linux/amd64
     - linux/arm64
 
-platform: ${platform}
-
 labels:
   type: exec
+  platform: ${platform}
 
-pipeline:
+steps:
 - name: publish-linux
   image: bash
   commands:
diff --git a/.woodpecker/chart.yaml b/.woodpecker/chart.yaml
index 3204cf5..20f9ea9 100644
--- a/.woodpecker/chart.yaml
+++ b/.woodpecker/chart.yaml
@@ -1,11 +1,9 @@
-platform: linux/amd64
-
 labels:
   type: exec
+  platform: linux/amd64
 
-pipeline:
+steps:
 - name: generate-chart
-  type: local
   image: bash
   commands:
   - export VERSION=$(sed 's#v##' <<< $CI_COMMIT_TAG)
diff --git a/.woodpecker/manifest.yml b/.woodpecker/manifest.yml
index 2d5c4e5..b4735ee 100644
--- a/.woodpecker/manifest.yml
+++ b/.woodpecker/manifest.yml
@@ -1,9 +1,8 @@
-platform: linux/amd64
-
 labels:
   type: exec
+  platform: linux/amd64
 
-pipeline:
+steps:
 - name: generate-manifest
   image: bash
   commands:
diff --git a/.woodpecker/test-linux.yml b/.woodpecker/test-linux.yml
index 313179e..d47ccc5 100644
--- a/.woodpecker/test-linux.yml
+++ b/.woodpecker/test-linux.yml
@@ -3,12 +3,11 @@ matrix:
   - linux/amd64
   - linux/arm64
 
-platform: ${platform}
-
 labels:
   type: exec
+  platform: ${platform}
 
-pipeline:
+steps:
 - name: test-linux
   image: bash
   commands:

From b9ca123636056e62c752d5a0625c05aad9792c7e Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Tue, 19 Mar 2024 23:15:23 +0800
Subject: [PATCH 05/21] fix(woodpecker): CI_SYSTEM_ARCH env removed

---
 .woodpecker/build-linux.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.woodpecker/build-linux.yml b/.woodpecker/build-linux.yml
index f411033..782d2f5 100644
--- a/.woodpecker/build-linux.yml
+++ b/.woodpecker/build-linux.yml
@@ -11,7 +11,7 @@ steps:
 - name: publish-linux
   image: bash
   commands:
-  - export VERSION=$([ -z $CI_COMMIT_TAG ] && echo latest || echo $CI_COMMIT_TAG)-$(sed 's#/#-#g' <<< $CI_SYSTEM_ARCH)
+  - export VERSION=$([ -z $CI_COMMIT_TAG ] && echo latest || echo $CI_COMMIT_TAG)-$(sed 's#/#-#g' <<< $CI_SYSTEM_PLATFORM)
   - echo $CONTAINER_PASSWORD | podman login $DRYCC_REGISTRY --username $CONTAINER_USERNAME --password-stdin > /dev/null 2>&1
   - make podman-build podman-immutable-push
   secrets:

From 234cb2bf01feaf7d6284c30e96e9331b35c72498 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Wed, 20 Mar 2024 14:22:22 +0800
Subject: [PATCH 06/21] chore(charts): change canary app version

---
 .woodpecker/chart.yaml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.woodpecker/chart.yaml b/.woodpecker/chart.yaml
index 20f9ea9..5aa7eb3 100644
--- a/.woodpecker/chart.yaml
+++ b/.woodpecker/chart.yaml
@@ -8,7 +8,7 @@ steps:
   commands:
   - export VERSION=$(sed 's#v##' <<< $CI_COMMIT_TAG)
   - export IMAGE_TAG=$([ ! -z $CI_COMMIT_TAG ] && echo \"$VERSION\" || echo \"canary\")
-  - export APP_VERSION=$([ ! -z $CI_COMMIT_TAG ] && echo $VERSION || echo 1.0.0)
+  - export APP_VERSION=$([ -z $CI_COMMIT_TAG ] && echo $CI_COMMIT_SHA || echo $VERSION)
   - export CHART_VERSION=$([ -z $CI_COMMIT_TAG ] && echo 1.0.0 || echo $VERSION)
   - sed -i "s/imageTag:\ \"canary\"/imageTag:\ $IMAGE_TAG/g" charts/$${CI_REPO_NAME}/values.yaml
   - helm package -u charts/$${CI_REPO_NAME} --version $CHART_VERSION --app-version $APP_VERSION
@@ -25,4 +25,4 @@ steps:
     - tag
 
 depends_on:
-- manifest
\ No newline at end of file
+- manifest

From 23e00da6b065435765df8bd0fd21bd9223102598 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Tue, 19 Nov 2024 11:22:53 +0800
Subject: [PATCH 07/21] chore(valkey): use valkey replace redis

---
 Makefile                                      |  5 +++--
 README.md                                     |  6 ++---
 _test/test.sh                                 | 22 +++++++++++++++++++
 .../redis/templates/redis-secret-creds.yaml   | 20 -----------------
 charts/{redis => valkey}/Chart.yaml           |  6 ++---
 .../valkey/templates/valkey-secret-creds.yaml | 20 +++++++++++++++++
 .../templates/valkey-statefulset.yaml}        | 22 +++++++++----------
 .../templates/valkey-svc.yaml}                |  6 ++---
 charts/{redis => valkey}/values.yaml          | 16 +++++++-------
 rootfs/Dockerfile                             |  8 +++----
 rootfs/bin/boot                               |  8 +++----
 .../{redis/redis.conf => valkey/valkey.conf}  |  0
 12 files changed, 81 insertions(+), 58 deletions(-)
 create mode 100755 _test/test.sh
 delete mode 100644 charts/redis/templates/redis-secret-creds.yaml
 rename charts/{redis => valkey}/Chart.yaml (64%)
 create mode 100644 charts/valkey/templates/valkey-secret-creds.yaml
 rename charts/{redis/templates/redis-statefulset.yaml => valkey/templates/valkey-statefulset.yaml} (87%)
 rename charts/{redis/templates/redis-svc.yaml => valkey/templates/valkey-svc.yaml} (69%)
 rename charts/{redis => valkey}/values.yaml (77%)
 rename rootfs/etc/{redis/redis.conf => valkey/valkey.conf} (100%)

diff --git a/Makefile b/Makefile
index 0e01839..68a5fc2 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
 # Some uses for short name:
 # - Container image name
 # - Kubernetes service, rc, pod, secret, volume names
-SHORT_NAME := redis
+SHORT_NAME := valkey
 DRYCC_REGISTRY ?= ${DEV_REGISTRY}
 IMAGE_PREFIX ?= drycc
 PLATFORM ?= linux/amd64,linux/arm64
@@ -29,7 +29,8 @@ podman-build:
 	podman build --build-arg CODENAME=${CODENAME} -t ${IMAGE} rootfs
 	podman tag ${IMAGE} ${MUTABLE_IMAGE}
 
-test: test-style
+test: podman-build test-style
+	./_test/test.sh ${VERSION}
 
 test-style:
 	${DEV_ENV_CMD} shellcheck $(SHELL_SCRIPTS)
diff --git a/README.md b/README.md
index a195ec9..9105718 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,9 @@
-# Drycc Redis
-[![Build Status](https://woodpecker.drycc.cc/api/badges/drycc/redis/status.svg)](https://woodpecker.drycc.cc/drycc/redis)
+# Drycc Valkey
+[![Build Status](https://woodpecker.drycc.cc/api/badges/drycc/valkey/status.svg)](https://woodpecker.drycc.cc/drycc/valkey)
 
 Drycc (pronounced DAY-iss) Workflow is an open source Platform as a Service (PaaS) that adds a developer-friendly layer to any [Kubernetes](http://kubernetes.io) cluster, making it easy to deploy and manage applications on your own servers.
 
 ## Description
-A Container image for running standalone (not clustered) Redis on a Kubernetes cluster.
+A Container image for running standalone (not clustered) Valkey on a Kubernetes cluster.
 
 [v2.18]: https://github.com/drycc/workflow/releases/tag/v2.18.0
diff --git a/_test/test.sh b/_test/test.sh
new file mode 100755
index 0000000..13b77ac
--- /dev/null
+++ b/_test/test.sh
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+VERSION="$1"
+CONTAINER_NAME="valkey-benchmark"
+
+function clean_before_exit {
+    # delay before exiting, so stdout/stderr flushes through the logging system
+    clean-valkey
+}
+trap clean_before_exit EXIT
+
+start-valkey() {
+    podman run -d --name "$CONTAINER_NAME" --rm registry.drycc.cc/drycc/valkey:$VERSION
+}
+
+clean-valkey() {
+    podman rm -f "$CONTAINER_NAME"
+}
+
+clean-valkey
+start-valkey
+podman exec "$CONTAINER_NAME" /opt/drycc/valkey/bin/valkey-benchmark
diff --git a/charts/redis/templates/redis-secret-creds.yaml b/charts/redis/templates/redis-secret-creds.yaml
deleted file mode 100644
index 8957eb3..0000000
--- a/charts/redis/templates/redis-secret-creds.yaml
+++ /dev/null
@@ -1,20 +0,0 @@
-apiVersion: v1
-kind: Secret
-metadata:
-  name: redis-creds
-  labels:
-    app: drycc-redis
-    heritage: drycc
-data: 
-  {{ if eq .Values.global.redisLocation "on-cluster"}}
-  {{- $redisAddrs := (list ) }}
-  {{- $redisNodeCount := .Values.replicas | int }}
-  {{- range $i := until $redisNodeCount }}
-  {{- $redisAddrs = (append $redisAddrs (printf "drycc-redis-%d.drycc-redis.%s.svc.%s:6379" $i $.Release.Namespace $.Values.global.clusterDomain)) }}
-  {{- end -}}
-  addrs: {{ join "," $redisAddrs | b64enc }}
-  password: {{ include "common.secrets.lookup" (dict "secret" "redis-creds" "key" "password" "defaultValue" (randAlphaNum 32) "context" $) }}
-  {{ else if eq .Values.global.redisLocation "off-cluster"}}
-  addrs: {{ .Values.addrs | b64enc }}
-  password: {{ .Values.password | b64enc }}
-  {{ end }}
diff --git a/charts/redis/Chart.yaml b/charts/valkey/Chart.yaml
similarity index 64%
rename from charts/redis/Chart.yaml
rename to charts/valkey/Chart.yaml
index 9272cb1..5e7e12d 100644
--- a/charts/redis/Chart.yaml
+++ b/charts/valkey/Chart.yaml
@@ -1,12 +1,12 @@
-name: redis
-home: https://github.com/drycc/redis
+name: valkey
+home: https://github.com/drycc/valkey
 apiVersion: v2
 appVersion: 1.0.0
 dependencies:
   - name: common
     repository: oci://registry.drycc.cc/charts
     version: ~1.1.2
-description: A Redis database for use inside a Kubernetes cluster.
+description: A Valkey database for use inside a Kubernetes cluster.
 maintainers:
   - name: Drycc Team
     email: engineering@drycc.com
diff --git a/charts/valkey/templates/valkey-secret-creds.yaml b/charts/valkey/templates/valkey-secret-creds.yaml
new file mode 100644
index 0000000..4d292e4
--- /dev/null
+++ b/charts/valkey/templates/valkey-secret-creds.yaml
@@ -0,0 +1,20 @@
+apiVersion: v1
+kind: Secret
+metadata:
+  name: valkey-creds
+  labels:
+    app: drycc-valkey
+    heritage: drycc
+data: 
+  {{ if eq .Values.global.valkeyLocation "on-cluster"}}
+  {{- $valkeyAddrs := (list ) }}
+  {{- $valkeyNodeCount := .Values.replicas | int }}
+  {{- range $i := until $valkeyNodeCount }}
+  {{- $valkeyAddrs = (append $valkeyAddrs (printf "drycc-valkey-%d.drycc-valkey.%s.svc.%s:6379" $i $.Release.Namespace $.Values.global.clusterDomain)) }}
+  {{- end -}}
+  addrs: {{ join "," $valkeyAddrs | b64enc }}
+  password: {{ include "common.secrets.lookup" (dict "secret" "valkey-creds" "key" "password" "defaultValue" (randAlphaNum 32) "context" $) }}
+  {{ else if eq .Values.global.valkeyLocation "off-cluster"}}
+  addrs: {{ .Values.addrs | b64enc }}
+  password: {{ .Values.password | b64enc }}
+  {{ end }}
diff --git a/charts/redis/templates/redis-statefulset.yaml b/charts/valkey/templates/valkey-statefulset.yaml
similarity index 87%
rename from charts/redis/templates/redis-statefulset.yaml
rename to charts/valkey/templates/valkey-statefulset.yaml
index 2189955..5c76dfe 100644
--- a/charts/redis/templates/redis-statefulset.yaml
+++ b/charts/valkey/templates/valkey-statefulset.yaml
@@ -1,30 +1,30 @@
-{{- if eq .Values.global.redisLocation "on-cluster" }}
+{{- if eq .Values.global.valkeyLocation "on-cluster" }}
 apiVersion: apps/v1
 kind: StatefulSet
 metadata:
-  name: drycc-redis
+  name: drycc-valkey
   labels:
     heritage: drycc
   annotations:
     component.drycc.cc/version: {{ .Values.imageTag }}
 spec:
-  serviceName: drycc-redis
+  serviceName: drycc-valkey
   replicas: {{ .Values.replicas }}
   selector:
     matchLabels:
-      app: drycc-redis
+      app: drycc-valkey
   template:
     metadata:
       labels: {{- include "common.labels.standard" . | nindent 8 }}
-        app: drycc-redis
+        app: drycc-valkey
     spec:
       affinity:
         podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAffinityPreset.type "component" "" "extraMatchLabels" .Values.podAffinityPreset.extraMatchLabels "topologyKey" "" "context" $) | nindent 10 }}
         podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAntiAffinityPreset.type "component" "" "extraMatchLabels" .Values.podAntiAffinityPreset.extraMatchLabels "topologyKey" "" "context" $) | nindent 10 }}
         nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.nodeAffinityPreset.type "key" .Values.nodeAffinityPreset.key "values" .Values.nodeAffinityPreset.values ) | nindent 10 }}
       containers:
-      - name: drycc-redis
-        image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/redis:{{ .Values.imageTag }}
+      - name: drycc-valkey
+        image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/valkey:{{ .Values.imageTag }}
         imagePullPolicy: {{ .Values.imagePullPolicy }}
         {{- if or (.Values.limitsCpu) (.Values.limitsMemory)}}
         resources:
@@ -48,14 +48,14 @@ spec:
         ports:
         - containerPort: 6379
         env:
-        - name: DRYCC_REDIS_PASSWORD
+        - name: DRYCC_VALKEY_PASSWORD
           valueFrom:
             secretKeyRef:
-              name: redis-creds
+              name: valkey-creds
               key: password
         {{- if .Values.persistence.enabled }}
         volumeMounts:
-        - name: redis-data
+        - name: valkey-data
           mountPath: /data
         {{- end }}
       securityContext:
@@ -65,7 +65,7 @@ spec:
   {{- if .Values.persistence.enabled }}
   volumeClaimTemplates:
   - metadata:
-      name: redis-data
+      name: valkey-data
     spec:
       accessModes: [ "ReadWriteOnce" ]
       {{- if .Values.persistence.storageClass }}
diff --git a/charts/redis/templates/redis-svc.yaml b/charts/valkey/templates/valkey-svc.yaml
similarity index 69%
rename from charts/redis/templates/redis-svc.yaml
rename to charts/valkey/templates/valkey-svc.yaml
index 0a47609..2eabd57 100644
--- a/charts/redis/templates/redis-svc.yaml
+++ b/charts/valkey/templates/valkey-svc.yaml
@@ -1,8 +1,8 @@
-{{- if eq .Values.global.redisLocation "on-cluster" }}
+{{- if eq .Values.global.valkeyLocation "on-cluster" }}
 apiVersion: v1
 kind: Service
 metadata:
-  name: drycc-redis
+  name: drycc-valkey
   annotations:
     {{- with .Values.service.annotations }}
     {{- toYaml . | nindent 4 }}
@@ -12,5 +12,5 @@ metadata:
 spec:
   clusterIP: None
   selector:
-    app: drycc-redis
+    app: drycc-valkey
 {{- end }}
diff --git a/charts/redis/values.yaml b/charts/valkey/values.yaml
similarity index 77%
rename from charts/redis/values.yaml
rename to charts/valkey/values.yaml
index d4d54d1..2873936 100644
--- a/charts/redis/values.yaml
+++ b/charts/valkey/values.yaml
@@ -34,14 +34,14 @@ podAffinityPreset:
 podAntiAffinityPreset:
   type: "soft"
   extraMatchLabels:
-    app: "drycc-redis"
+    app: "drycc-valkey"
 
-# The following parameters are configured only when using an on-cluster Redis instance
+# The following parameters are configured only when using an on-cluster Valkey instance
 replicas: 1
 
-# The following parameters are configured only when using an off-cluster Redis instance
+# The following parameters are configured only when using an off-cluster Valkey instance
 addrs: "" # A list of clusters: "127.0.0.1:7001/1,127.0.0.2:7002/1"
-password: "redis password" # "" == no password
+password: "valkey password" # "" == no password
 
 # Service
 service:
@@ -55,9 +55,9 @@ persistence:
   storageClass: ""
 
 global:
-  # Set the location of Workflow's redis instance
+  # Set the location of Workflow's valkey instance
   #
   # Valid values are:
-  # - on-cluster: Run Redis within the Kubernetes cluster
-  # - off-cluster: Run Redis outside the Kubernetes cluster (configure in redis section)
-  redisLocation: "on-cluster"
\ No newline at end of file
+  # - on-cluster: Run Valkey within the Kubernetes cluster
+  # - off-cluster: Run Valkey outside the Kubernetes cluster (configure in valkey section)
+  valkeyLocation: "on-cluster"
\ No newline at end of file
diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile
index 41de670..4357748 100644
--- a/rootfs/Dockerfile
+++ b/rootfs/Dockerfile
@@ -4,15 +4,15 @@ FROM registry.drycc.cc/drycc/base:${CODENAME}
 ENV DRYCC_UID=1001 \
   DRYCC_GID=1001 \
   DRYCC_HOME_DIR=/data \
-  REDIS_VERSION="7.0.11"
+  VALKEY_VERSION="8.0.1"
 
 RUN groupadd drycc --gid ${DRYCC_GID} \
   && useradd drycc -u ${DRYCC_UID} -g ${DRYCC_GID} -s /bin/bash -m -d ${DRYCC_HOME_DIR}
 
 COPY bin/boot /bin/boot
-COPY etc/redis/redis.conf /etc/redis/redis.conf
+COPY etc/valkey/valkey.conf /etc/valkey/valkey.conf
 
-RUN install-stack redis ${REDIS_VERSION} \
+RUN install-stack valkey ${VALKEY_VERSION} \
   && rm -rf \
       /usr/share/doc \
       /usr/share/man \
@@ -27,7 +27,7 @@ RUN install-stack redis ${REDIS_VERSION} \
       /usr/lib/`echo $(uname -m)`-linux-gnu/gconv/IBM* \
       /usr/lib/`echo $(uname -m)`-linux-gnu/gconv/EBC* \
   && mkdir -p /usr/share/man/man{1..8} \
-  && chown -R ${DRYCC_UID}:${DRYCC_GID} /etc/redis ${DRYCC_HOME_DIR}
+  && chown -R ${DRYCC_UID}:${DRYCC_GID} /etc/valkey ${DRYCC_HOME_DIR}
 
 USER ${DRYCC_UID}
 WORKDIR ${DRYCC_HOME_DIR}
diff --git a/rootfs/bin/boot b/rootfs/bin/boot
index d45af80..a78fd97 100755
--- a/rootfs/bin/boot
+++ b/rootfs/bin/boot
@@ -2,11 +2,11 @@
 
 set -eof pipefail
 
-REDIS_CONFIG_FILE=/etc/redis/redis.conf
+VALKEY_CONFIG_FILE=/etc/valkey/valkey.conf
 
 # Set password
-if [ -n "$DRYCC_REDIS_PASSWORD" ]; then
-    printf "\nrequirepass %s" "$DRYCC_REDIS_PASSWORD" >> $REDIS_CONFIG_FILE
+if [ -n "$DRYCC_VALKEY_PASSWORD" ]; then
+    printf "\nrequirepass %s" "$DRYCC_VALKEY_PASSWORD" >> $VALKEY_CONFIG_FILE
 fi
 
-exec redis-server $REDIS_CONFIG_FILE "$@"
+exec valkey-server $VALKEY_CONFIG_FILE "$@"
diff --git a/rootfs/etc/redis/redis.conf b/rootfs/etc/valkey/valkey.conf
similarity index 100%
rename from rootfs/etc/redis/redis.conf
rename to rootfs/etc/valkey/valkey.conf

From bd4a1b8b19e7c6c53d2d92e024da03ac4fe6f4b9 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Wed, 20 Nov 2024 18:16:45 +0800
Subject: [PATCH 08/21] feat(valkey): add sentinel

---
 Makefile                                      |   2 +-
 _test/test.sh                                 | 126 +++++++++++++++-
 charts/valkey/Chart.lock                      |   6 +
 charts/valkey/charts/common-1.1.3.tgz         | Bin 0 -> 10632 bytes
 .../valkey/templates/valkey-secret-creds.yaml |  15 +-
 .../valkey/templates/valkey-statefulset.yaml  | 135 +++++++++++++++++-
 charts/valkey/templates/valkey-svc.yaml       |  10 ++
 charts/valkey/values.yaml                     |  10 +-
 rootfs/Dockerfile                             |   8 +-
 rootfs/bin/boot                               |  12 --
 rootfs/bin/valkey-start                       | 100 +++++++++++++
 .../{valkey.conf => valkey-default.conf}      |   1 +
 .../etc/valkey/valkey-sentinel-default.conf   |  10 ++
 rootfs/scripts/init.sh                        |  61 ++++++++
 rootfs/scripts/ping_liveness_local.sh         |  21 +++
 rootfs/scripts/ping_readiness_local.sh        |  20 +++
 rootfs/scripts/ping_sentinel.sh               |  20 +++
 rootfs/scripts/prestop-sentinel.sh            |  30 ++++
 rootfs/scripts/prestop-valkey.sh              |  20 +++
 19 files changed, 566 insertions(+), 41 deletions(-)
 create mode 100644 charts/valkey/Chart.lock
 create mode 100644 charts/valkey/charts/common-1.1.3.tgz
 delete mode 100755 rootfs/bin/boot
 create mode 100755 rootfs/bin/valkey-start
 rename rootfs/etc/valkey/{valkey.conf => valkey-default.conf} (90%)
 create mode 100644 rootfs/etc/valkey/valkey-sentinel-default.conf
 create mode 100755 rootfs/scripts/init.sh
 create mode 100755 rootfs/scripts/ping_liveness_local.sh
 create mode 100755 rootfs/scripts/ping_readiness_local.sh
 create mode 100755 rootfs/scripts/ping_sentinel.sh
 create mode 100755 rootfs/scripts/prestop-sentinel.sh
 create mode 100755 rootfs/scripts/prestop-valkey.sh

diff --git a/Makefile b/Makefile
index 68a5fc2..6c8d6c9 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ PLATFORM ?= linux/amd64,linux/arm64
 
 include versioning.mk
 
-SHELL_SCRIPTS = $(wildcard _scripts/*.sh) rootfs/bin/boot
+SHELL_SCRIPTS = $(wildcard _test/*.sh) rootfs/bin/valkey-start rootfs/scripts/*
 
 # The following variables describe the containerized development environment
 # and other build options
diff --git a/_test/test.sh b/_test/test.sh
index 13b77ac..5e8bc2c 100755
--- a/_test/test.sh
+++ b/_test/test.sh
@@ -1,7 +1,13 @@
 #!/usr/bin/env bash
 
 VERSION="$1"
-CONTAINER_NAME="valkey-benchmark"
+
+CONTAINER_NETWORK="valkey"
+CONTAINER_MASTER_NAME="valkey-benchmark-master"
+CONTAINER_SLAVE1_NAME="valkey-benchmark-slave1"
+CONTAINER_SLAVE2_NAME="valkey-benchmark-slave2"
+DRYCC_VALKEY_SENTINEL=$CONTAINER_MASTER_NAME
+DRYCC_VALKEY_PASSWORD=123456
 
 function clean_before_exit {
     # delay before exiting, so stdout/stderr flushes through the logging system
@@ -9,14 +15,122 @@ function clean_before_exit {
 }
 trap clean_before_exit EXIT
 
-start-valkey() {
-    podman run -d --name "$CONTAINER_NAME" --rm registry.drycc.cc/drycc/valkey:$VERSION
+start-valkey-master() {
+    podman run -d \
+      --rm \
+      --network "$CONTAINER_NETWORK" \
+      --ip 192.168.253.10 \
+      --add-host="$CONTAINER_MASTER_NAME:192.168.253.10" \
+      --add-host="$CONTAINER_SLAVE1_NAME:192.168.253.11" \
+      --add-host="$CONTAINER_SLAVE2_NAME:192.168.253.12" \
+      --env "REDISCLI_AUTH=$DRYCC_VALKEY_PASSWORD" \
+      --env "DRYCC_VALKEY_SENTINEL=$DRYCC_VALKEY_SENTINEL" \
+      --env "DRYCC_VALKEY_PASSWORD=$DRYCC_VALKEY_PASSWORD" \
+      --name "$CONTAINER_MASTER_NAME" \
+      "registry.drycc.cc/drycc/valkey:$VERSION" \
+      valkey-start server $CONTAINER_MASTER_NAME
+    podman exec "$CONTAINER_MASTER_NAME" init-stack valkey-start sentinel $CONTAINER_MASTER_NAME &
+}
+
+start-valkey-slave1() {
+    podman run -d \
+      --rm \
+      --network "$CONTAINER_NETWORK" \
+      --ip 192.168.253.11 \
+      --add-host="$CONTAINER_MASTER_NAME:192.168.253.10" \
+      --add-host="$CONTAINER_SLAVE1_NAME:192.168.253.11" \
+      --add-host="$CONTAINER_SLAVE2_NAME:192.168.253.12" \
+      --env "REDISCLI_AUTH=$DRYCC_VALKEY_PASSWORD" \
+      --env "DRYCC_VALKEY_SENTINEL=$DRYCC_VALKEY_SENTINEL" \
+      --env "DRYCC_VALKEY_PASSWORD=$DRYCC_VALKEY_PASSWORD" \
+      --name "$CONTAINER_SLAVE1_NAME" \
+      "registry.drycc.cc/drycc/valkey:$VERSION" \
+      valkey-start server $CONTAINER_SLAVE1_NAME
+    podman exec "$CONTAINER_SLAVE1_NAME" init-stack valkey-start sentinel $CONTAINER_SLAVE1_NAME &
+}
+
+start-valkey-slave2() {
+    podman run -d \
+      --rm \
+      --network "$CONTAINER_NETWORK" \
+      --ip 192.168.253.12 \
+      --add-host="$CONTAINER_MASTER_NAME:192.168.253.10" \
+      --add-host="$CONTAINER_SLAVE1_NAME:192.168.253.11" \
+      --add-host="$CONTAINER_SLAVE2_NAME:192.168.253.12" \
+      --env "REDISCLI_AUTH=$DRYCC_VALKEY_PASSWORD" \
+      --env "DRYCC_VALKEY_SENTINEL=$DRYCC_VALKEY_SENTINEL" \
+      --env "DRYCC_VALKEY_PASSWORD=$DRYCC_VALKEY_PASSWORD" \
+      --name "$CONTAINER_SLAVE2_NAME" \
+      "registry.drycc.cc/drycc/valkey:$VERSION" \
+      valkey-start server $CONTAINER_SLAVE2_NAME
+    podman exec "$CONTAINER_SLAVE2_NAME" init-stack valkey-start sentinel $CONTAINER_SLAVE2_NAME &
 }
 
 clean-valkey() {
-    podman rm -f "$CONTAINER_NAME"
+    {
+        podman stop -i "$CONTAINER_SLAVE1_NAME"
+        podman stop -i "$CONTAINER_SLAVE2_NAME"
+        podman stop -i "$CONTAINER_MASTER_NAME"
+        podman network rm -f "$CONTAINER_NETWORK"
+    } 2>>/dev/null
 }
 
 clean-valkey
-start-valkey
-podman exec "$CONTAINER_NAME" /opt/drycc/valkey/bin/valkey-benchmark
+podman network create --subnet=192.168.253.0/24 "$CONTAINER_NETWORK"
+start-valkey-master
+start-valkey-slave1
+start-valkey-slave2
+
+echo "run valkey benchmark..."
+podman exec "$CONTAINER_MASTER_NAME" init-stack valkey-benchmark -a $DRYCC_VALKEY_PASSWORD
+
+echo "check slave all keys..."
+KEYS=$(podman exec "$CONTAINER_MASTER_NAME" bash -c 'init-stack valkey-cli KEYS "*"')
+if [[ "${KEYS}" == "" ]]; then
+    echo "error: there is no data from the database"
+    exit 1
+fi
+
+echo "check sentinel $CONTAINER_MASTER_NAME get master..."
+MASTER=$(podman exec "$CONTAINER_MASTER_NAME" init-stack valkey-cli -p 26379 sentinel get-master-addr-by-name drycc)
+if [[ "${MASTER}" == "" ]]; then
+    echo "error: unable to obtain master information"
+    exit 1
+fi
+
+echo "check sentinel $CONTAINER_SLAVE1_NAME get master..."
+MASTER=$(podman exec "$CONTAINER_SLAVE1_NAME" init-stack valkey-cli -p 26379 sentinel get-master-addr-by-name drycc)
+if [[ "${MASTER}" == "" ]]; then
+    echo "error: unable to obtain master information"
+    exit 1
+fi
+
+echo "check sentinel $CONTAINER_SLAVE2_NAME get master..."
+MASTER=$(podman exec "$CONTAINER_SLAVE2_NAME" init-stack valkey-cli -p 26379 sentinel get-master-addr-by-name drycc)
+if [[ "${MASTER}" == "" ]]; then
+    echo "error: unable to obtain master information"
+    exit 1
+fi
+
+echo "check sentinel $CONTAINER_MASTER_NAME get slaves..."
+SLAVES=$(podman exec "$CONTAINER_MASTER_NAME" init-stack valkey-cli -p 26379 sentinel replicas drycc)
+if [[ "${SLAVES}" == "" ]]; then
+    echo "error: unable to obtain slaves information"
+    exit 1
+fi
+
+echo "check sentinel $CONTAINER_SLAVE1_NAME get slaves..."
+SLAVES=$(podman exec "$CONTAINER_SLAVE1_NAME" init-stack valkey-cli -p 26379 sentinel replicas drycc)
+if [[ "${SLAVES}" == "" ]]; then
+    echo "error: unable to obtain slaves information"
+    exit 1
+fi
+
+echo "check sentinel $CONTAINER_SLAVE2_NAME get slaves..."
+SLAVES=$(podman exec "$CONTAINER_SLAVE2_NAME" init-stack valkey-cli -p 26379 sentinel replicas drycc)
+if [[ "${SLAVES}" == "" ]]; then
+    echo "error: unable to obtain slaves information"
+    exit 1
+fi
+
+echo "all test ok..."
diff --git a/charts/valkey/Chart.lock b/charts/valkey/Chart.lock
new file mode 100644
index 0000000..2a25c53
--- /dev/null
+++ b/charts/valkey/Chart.lock
@@ -0,0 +1,6 @@
+dependencies:
+- name: common
+  repository: oci://registry.drycc.cc/charts
+  version: 1.1.3
+digest: sha256:4928b76b9f4927f43702c2617b139b2fe7298055b9b6d0c363a7a94530985595
+generated: "2024-11-20T16:35:58.537426209+08:00"
diff --git a/charts/valkey/charts/common-1.1.3.tgz b/charts/valkey/charts/common-1.1.3.tgz
new file mode 100644
index 0000000000000000000000000000000000000000..d1035f1a56b79241a8ae1ff4bfca514e8ceb60c4
GIT binary patch
diff --git a/charts/valkey/templates/valkey-secret-creds.yaml b/charts/valkey/templates/valkey-secret-creds.yaml
index 4d292e4..b3f0ea0 100644
--- a/charts/valkey/templates/valkey-secret-creds.yaml
+++ b/charts/valkey/templates/valkey-secret-creds.yaml
@@ -1,3 +1,4 @@
+{{- if eq .Values.global.valkeyLocation "on-cluster" }}
 apiVersion: v1
 kind: Secret
 metadata:
@@ -5,16 +6,6 @@ metadata:
   labels:
     app: drycc-valkey
     heritage: drycc
-data: 
-  {{ if eq .Values.global.valkeyLocation "on-cluster"}}
-  {{- $valkeyAddrs := (list ) }}
-  {{- $valkeyNodeCount := .Values.replicas | int }}
-  {{- range $i := until $valkeyNodeCount }}
-  {{- $valkeyAddrs = (append $valkeyAddrs (printf "drycc-valkey-%d.drycc-valkey.%s.svc.%s:6379" $i $.Release.Namespace $.Values.global.clusterDomain)) }}
-  {{- end -}}
-  addrs: {{ join "," $valkeyAddrs | b64enc }}
+data:
   password: {{ include "common.secrets.lookup" (dict "secret" "valkey-creds" "key" "password" "defaultValue" (randAlphaNum 32) "context" $) }}
-  {{ else if eq .Values.global.valkeyLocation "off-cluster"}}
-  addrs: {{ .Values.addrs | b64enc }}
-  password: {{ .Values.password | b64enc }}
-  {{ end }}
+{{- end }}
diff --git a/charts/valkey/templates/valkey-statefulset.yaml b/charts/valkey/templates/valkey-statefulset.yaml
index 5c76dfe..0828992 100644
--- a/charts/valkey/templates/valkey-statefulset.yaml
+++ b/charts/valkey/templates/valkey-statefulset.yaml
@@ -23,7 +23,7 @@ spec:
         podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAntiAffinityPreset.type "component" "" "extraMatchLabels" .Values.podAntiAffinityPreset.extraMatchLabels "topologyKey" "" "context" $) | nindent 10 }}
         nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.nodeAffinityPreset.type "key" .Values.nodeAffinityPreset.key "values" .Values.nodeAffinityPreset.values ) | nindent 10 }}
       containers:
-      - name: drycc-valkey
+      - name: server
         image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/valkey:{{ .Values.imageTag }}
         imagePullPolicy: {{ .Values.imagePullPolicy }}
         {{- if or (.Values.limitsCpu) (.Values.limitsMemory)}}
@@ -41,23 +41,150 @@ spec:
         args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 10 }}
         {{- else }}
         args:
-        - "/bin/boot"
-        - "--port"
-        - "6379"
+        - valkey-start
+        - server
+        - $(POD_NAME).{{ printf "drycc-valkey.%s.svc.%s" $.Release.Namespace $.Values.global.clusterDomain }}
         {{- end }}
         ports:
         - containerPort: 6379
         env:
+        - name: POD_NAME
+          valueFrom:
+            fieldRef:
+              fieldPath: metadata.name
+        - name: DRYCC_VALKEY_SENTINEL
+          value: {{ printf "drycc-valkey.%s.svc.%s" $.Release.Namespace $.Values.global.clusterDomain }}
+        - name: DRYCC_VALKEY_PASSWORD
+          valueFrom:
+            secretKeyRef:
+              name: valkey-creds
+              key: password
+        startupProbe:
+          initialDelaySeconds: 10
+          periodSeconds: 10
+          timeoutSeconds: 5
+          successThreshold: 1
+          failureThreshold: 22
+          tcpSocket:
+            port: 6379
+        livenessProbe:
+          initialDelaySeconds: 20
+          periodSeconds: 5
+          timeoutSeconds: 5
+          successThreshold: 1
+          failureThreshold: 5
+          exec:
+            command:
+              - init-stack
+              - sh
+              - -c
+              - /scripts/ping_liveness_local.sh 5
+        readinessProbe:
+          initialDelaySeconds: 20
+          periodSeconds: 5
+          timeoutSeconds: 1
+          successThreshold: 1
+          failureThreshold: 5
+          exec:
+            command:
+              - init-stack
+              - sh
+              - -c
+              - /scripts/ping_readiness_local.sh 1
+        {{- if .Values.persistence.enabled }}
+        volumeMounts:
+        - name: valkey-data
+          mountPath: /data
+        {{- end }}
+        lifecycle:
+          preStop:
+            exec:
+              command:
+                - init-stack
+                - /bin/bash
+                - -c
+                - /scripts/prestop-valkey.sh
+      - name: sentinel
+        image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/valkey:{{ .Values.imageTag }}
+        imagePullPolicy: {{ .Values.imagePullPolicy }}
+        {{- if or (.Values.limitsCpu) (.Values.limitsMemory)}}
+        resources:
+          limits:
+            {{- if (.Values.limitsCpu) }}
+            cpu: {{.Values.limitsCpu}}
+            {{- end}}
+            {{- if (.Values.limitsMemory) }}
+            memory: {{.Values.limitsMemory}}
+            {{- end}}
+        {{- end}}
+        {{- if .Values.diagnosticMode.enabled }}
+        command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 10 }}
+        args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 10 }}
+        {{- else }}
+        args:
+        - valkey-start
+        - sentinel
+        - $(POD_NAME).{{ printf "drycc-valkey.%s.svc.%s" $.Release.Namespace $.Values.global.clusterDomain }}
+        {{- end }}
+        ports:
+        - containerPort: 26379
+        env:
+        - name: POD_NAME
+          valueFrom:
+            fieldRef:
+              fieldPath: metadata.name
+        - name: DRYCC_VALKEY_SENTINEL
+          value: {{ printf "drycc-valkey.%s.svc.%s" $.Release.Namespace $.Values.global.clusterDomain }}
         - name: DRYCC_VALKEY_PASSWORD
           valueFrom:
             secretKeyRef:
               name: valkey-creds
               key: password
+        startupProbe:
+          initialDelaySeconds: 10
+          periodSeconds: 10
+          timeoutSeconds: 5
+          successThreshold: 1
+          failureThreshold: 22
+          tcpSocket:
+            port: 26379
+        livenessProbe:
+          initialDelaySeconds: 20
+          periodSeconds: 5
+          timeoutSeconds: 5
+          successThreshold: 1
+          failureThreshold: 5
+          exec:
+            command:
+            - init-stack
+            - sh
+            - -c
+            - /scripts/ping_sentinel.sh 5
+        readinessProbe:
+          initialDelaySeconds: 20
+          periodSeconds: 5
+          timeoutSeconds: 1
+          successThreshold: 1
+          failureThreshold: 5
+          exec:
+            command:
+            - init-stack
+            - sh
+            - -c
+            - /scripts/ping_sentinel.sh 1
         {{- if .Values.persistence.enabled }}
         volumeMounts:
         - name: valkey-data
           mountPath: /data
         {{- end }}
+        lifecycle:
+          preStop:
+            exec:
+              command:
+                - init-stack
+                - /bin/bash
+                - -c
+                - /scripts/prestop-sentinel.sh
       securityContext:
         fsGroup: 1001
         runAsGroup: 1001
diff --git a/charts/valkey/templates/valkey-svc.yaml b/charts/valkey/templates/valkey-svc.yaml
index 2eabd57..641c91f 100644
--- a/charts/valkey/templates/valkey-svc.yaml
+++ b/charts/valkey/templates/valkey-svc.yaml
@@ -11,6 +11,16 @@ metadata:
     heritage: drycc
 spec:
   clusterIP: None
+  publishNotReadyAddresses: true
+  ports:
+  - name: server
+    port: 6379
+    targetPort: 6379
+    protocol: TCP
+  - name: sentinel
+    port: 26379
+    targetPort: 26379
+    protocol: TCP
   selector:
     app: drycc-valkey
 {{- end }}
diff --git a/charts/valkey/values.yaml b/charts/valkey/values.yaml
index 2873936..1471d44 100644
--- a/charts/valkey/values.yaml
+++ b/charts/valkey/values.yaml
@@ -37,7 +37,7 @@ podAntiAffinityPreset:
     app: "drycc-valkey"
 
 # The following parameters are configured only when using an on-cluster Valkey instance
-replicas: 1
+replicas: 3
 
 # The following parameters are configured only when using an off-cluster Valkey instance
 addrs: "" # A list of clusters: "127.0.0.1:7001/1,127.0.0.2:7002/1"
@@ -55,9 +55,15 @@ persistence:
   storageClass: ""
 
 global:
+  # A domain name consists of one or more parts.
+  # Periods (.) are used to separate these parts.
+  # Each part must be 1 to 63 characters in length and can contain lowercase letters, digits, and hyphens (-).
+  # It must start and end with a lowercase letter or digit.
+  clusterDomain: "cluster.local"
   # Set the location of Workflow's valkey instance
   #
   # Valid values are:
   # - on-cluster: Run Valkey within the Kubernetes cluster
   # - off-cluster: Run Valkey outside the Kubernetes cluster (configure in valkey section)
-  valkeyLocation: "on-cluster"
\ No newline at end of file
+  valkeyLocation: "on-cluster"
+  
\ No newline at end of file
diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile
index 4357748..2fd5601 100644
--- a/rootfs/Dockerfile
+++ b/rootfs/Dockerfile
@@ -9,8 +9,9 @@ ENV DRYCC_UID=1001 \
 RUN groupadd drycc --gid ${DRYCC_GID} \
   && useradd drycc -u ${DRYCC_UID} -g ${DRYCC_GID} -s /bin/bash -m -d ${DRYCC_HOME_DIR}
 
-COPY bin/boot /bin/boot
-COPY etc/valkey/valkey.conf /etc/valkey/valkey.conf
+COPY scripts /scripts
+COPY etc/valkey /etc/valkey
+COPY bin/valkey-start /bin/valkey-start
 
 RUN install-stack valkey ${VALKEY_VERSION} \
   && rm -rf \
@@ -31,5 +32,4 @@ RUN install-stack valkey ${VALKEY_VERSION} \
 
 USER ${DRYCC_UID}
 WORKDIR ${DRYCC_HOME_DIR}
-CMD ["/bin/boot"]
-EXPOSE 6379
+EXPOSE 6379 26379
diff --git a/rootfs/bin/boot b/rootfs/bin/boot
deleted file mode 100755
index a78fd97..0000000
--- a/rootfs/bin/boot
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/env bash
-
-set -eof pipefail
-
-VALKEY_CONFIG_FILE=/etc/valkey/valkey.conf
-
-# Set password
-if [ -n "$DRYCC_VALKEY_PASSWORD" ]; then
-    printf "\nrequirepass %s" "$DRYCC_VALKEY_PASSWORD" >> $VALKEY_CONFIG_FILE
-fi
-
-exec valkey-server $VALKEY_CONFIG_FILE "$@"
diff --git a/rootfs/bin/valkey-start b/rootfs/bin/valkey-start
new file mode 100755
index 0000000..5a2090b
--- /dev/null
+++ b/rootfs/bin/valkey-start
@@ -0,0 +1,100 @@
+#!/usr/bin/env bash
+
+# shellcheck disable=SC1091
+. /scripts/init.sh
+
+print_usage() {
+    echo "Valid commands for valkey-start:"
+    echo ""
+    echo "server <announce-host>              start valkey server"
+    echo "sentinel <announce-host>            start valkey sentinel"
+    echo ""
+    echo "Such as 'weed-start server valkey.valkey.svc.cluster.local' to start valkey server."
+}
+
+remove_in_file() {
+    local filename="${1:?filename is required}"
+    local match_regex="^\s*${2:?match regex is required} .*"
+    sed -i "/$match_regex/d" "$filename"
+}
+
+get_master_info() {
+    export REDISCLI_AUTH=${DRYCC_VALKEY_PASSWORD}
+    command="valkey-cli -h ${DRYCC_VALKEY_SENTINEL} -p ${SENTINEL_PORT} sentinel get-master-addr-by-name drycc 2>>/dev/null"
+    eval "$command"
+}
+
+start_valkey_server() {
+    announce_ip="$1"
+    VALKEY_CONFIG_FILE=/data/server/valkey.conf
+    if [ ! -f ${VALKEY_CONFIG_FILE} ]; then
+        cp -rf /etc/valkey/valkey-default.conf ${VALKEY_CONFIG_FILE}
+    fi
+
+    # Clean old
+    remove_in_file ${VALKEY_CONFIG_FILE} masterauth
+    remove_in_file ${VALKEY_CONFIG_FILE} requirepass
+    remove_in_file ${VALKEY_CONFIG_FILE} replicaof
+    remove_in_file ${VALKEY_CONFIG_FILE} replica-announce-ip
+    remove_in_file ${VALKEY_CONFIG_FILE} replica-announce-port
+    {
+        printf "\nmasterauth %s" "${DRYCC_VALKEY_PASSWORD}"
+        printf "\nrequirepass %s" "${DRYCC_VALKEY_PASSWORD}"
+        printf "\nreplica-announce-ip %s" "${announce_ip}"
+        printf "\nreplica-announce-port %s" "${SERVER_PORT}"
+    } >> ${VALKEY_CONFIG_FILE}
+    # Set server slaveof
+    if get_master_info; then
+        # shellcheck disable=SC2207
+        master_info=($(get_master_info))
+        if [ "${master_info[0]}" != "${announce_ip}" ]; then
+            printf "\nreplicaof %s %s" "${master_info[0]}" "${master_info[1]}" >> "${VALKEY_CONFIG_FILE}"
+        fi
+    fi
+    exec valkey-server "${VALKEY_CONFIG_FILE}"
+}
+
+start_valkey_sentinel() {
+    announce_ip="$1"
+    VALKEY_SENTINEL_CONFIG_FILE=/data/sentinel/valkey-sentinel.conf
+    if [ ! -f ${VALKEY_SENTINEL_CONFIG_FILE} ]; then
+        cp -rf /etc/valkey/valkey-sentinel-default.conf ${VALKEY_SENTINEL_CONFIG_FILE}
+    fi
+
+    # Clean old
+    remove_in_file ${VALKEY_SENTINEL_CONFIG_FILE} masterauth
+    remove_in_file ${VALKEY_SENTINEL_CONFIG_FILE} requirepass
+    remove_in_file ${VALKEY_SENTINEL_CONFIG_FILE} primaryauth
+    remove_in_file ${VALKEY_SENTINEL_CONFIG_FILE} "sentinel auth-pass"
+    remove_in_file ${VALKEY_SENTINEL_CONFIG_FILE} "sentinel announce-ip"
+    remove_in_file ${VALKEY_SENTINEL_CONFIG_FILE} "sentinel announce-port"
+    remove_in_file ${VALKEY_SENTINEL_CONFIG_FILE} "sentinel monitor"
+
+    # Set sentinel config
+    {
+        printf "\nmasterauth %s" "${DRYCC_VALKEY_PASSWORD}"
+        printf "\nrequirepass %s" "${DRYCC_VALKEY_PASSWORD}"
+        printf "\nprimaryauth %s" "${DRYCC_VALKEY_PASSWORD}"
+        printf "\nsentinel auth-pass drycc %s" "${DRYCC_VALKEY_PASSWORD}"
+        printf "\nsentinel announce-ip %s" "${announce_ip}"
+        printf "\nsentinel announce-port %s" "${SENTINEL_PORT}"
+    } >> ${VALKEY_SENTINEL_CONFIG_FILE}
+
+    # Set monitor
+    if get_master_info; then
+        # shellcheck disable=SC2207
+        master_info=($(get_master_info))
+        printf "\nsentinel monitor drycc %s %s 2" "${master_info[0]}" "${master_info[1]}" >> ${VALKEY_SENTINEL_CONFIG_FILE}
+    else
+        printf "\nsentinel monitor drycc %s %s 2" "${announce_ip}" "${SERVER_PORT}" >> ${VALKEY_SENTINEL_CONFIG_FILE}
+    fi
+    exec valkey-sentinel $VALKEY_SENTINEL_CONFIG_FILE
+}
+
+command="$1"
+if [[ ${command} == "server" || ${command} == "sentinel" ]]; then
+    "start_valkey_$command" "$2"
+else
+    print_usage
+    exit 1
+fi
diff --git a/rootfs/etc/valkey/valkey.conf b/rootfs/etc/valkey/valkey-default.conf
similarity index 90%
rename from rootfs/etc/valkey/valkey.conf
rename to rootfs/etc/valkey/valkey-default.conf
index 58673f3..0b51917 100644
--- a/rootfs/etc/valkey/valkey.conf
+++ b/rootfs/etc/valkey/valkey-default.conf
@@ -1,6 +1,7 @@
 daemonize no
 bind 0.0.0.0
 logfile ""
+dir "/data/server"
 
 save 900 1
 save 300 10
diff --git a/rootfs/etc/valkey/valkey-sentinel-default.conf b/rootfs/etc/valkey/valkey-sentinel-default.conf
new file mode 100644
index 0000000..429f3b6
--- /dev/null
+++ b/rootfs/etc/valkey/valkey-sentinel-default.conf
@@ -0,0 +1,10 @@
+daemonize no
+bind 0.0.0.0
+logfile ""
+dir "/data/sentinel"
+
+sentinel resolve-hostnames yes
+sentinel announce-hostnames yes
+sentinel down-after-milliseconds drycc 60000
+sentinel failover-timeout drycc 180000
+sentinel parallel-syncs drycc 1
diff --git a/rootfs/scripts/init.sh b/rootfs/scripts/init.sh
new file mode 100755
index 0000000..e9ee373
--- /dev/null
+++ b/rootfs/scripts/init.sh
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+# Constants
+RESET='\033[0m'
+RED='\033[38;5;1m'
+MAGENTA='\033[38;5;5m'
+CYAN='\033[38;5;6m'
+
+log() {
+    # 'is_boolean_yes' is defined in libvalidations.sh, but depends on this file so we cannot source it
+    local bool="${DRYCC_QUIET:-false}"
+    # comparison is performed without regard to the case of alphabetic characters
+    shopt -s nocasematch
+    if ! [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]; then
+        printf "%b\\n" "${CYAN}${MODULE:-} ${MAGENTA}$(date "+%T.%2N ")${RESET}${*}" >&2
+    fi
+}
+
+error() {
+    log "${RED}ERROR${RESET} ==> ${*}"
+    exit 1
+}
+
+########################
+# Retries a command a given number of times
+# Arguments:
+#   $1 - cmd (as a string)
+#   $2 - max retries. Default: 12
+#   $3 - sleep between retries (in seconds). Default: 5
+# Returns:
+#   Boolean
+#########################
+retry_while() {
+    local cmd="${1:?cmd is missing}"
+    local retries="${2:-12}"
+    local sleep_time="${3:-5}"
+    local return_value=1
+
+    read -r -a command <<<"$cmd"
+    for ((i = 1; i <= retries; i += 1)); do
+        "${command[@]}" && return_value=0 && break
+        sleep "$sleep_time"
+    done
+    return $return_value
+}
+
+init_default_env() {
+    if [[ -z "$DRYCC_VALKEY_SENTINEL" ]]; then
+        error "DRYCC_VALKEY_SENTINEL cannot be empty"
+    fi
+    if [[ -z "$DRYCC_VALKEY_PASSWORD" ]]; then
+        error "DRYCC_VALKEY_PASSWORD cannot be empty"
+    fi
+    mkdir -p /data/{server,sentinel}
+    SERVER_PORT=${SERVER_PORT:-6379}
+    SENTINEL_PORT=${SENTINEL_PORT:-26379}
+    REDISCLI_AUTH="$DRYCC_VALKEY_PASSWORD"
+    export SERVER_PORT SENTINEL_PORT REDISCLI_AUTH
+}
+
+init_default_env
diff --git a/rootfs/scripts/ping_liveness_local.sh b/rootfs/scripts/ping_liveness_local.sh
new file mode 100755
index 0000000..baf72d2
--- /dev/null
+++ b/rootfs/scripts/ping_liveness_local.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+# shellcheck disable=SC1091
+. /scripts/init.sh
+
+response=$(
+    timeout -s 3 "$1" \
+    valkey-cli \
+    -h localhost \
+    -p "${SERVER_PORT}" \
+    ping
+)
+if [ "$?" -eq "124" ]; then
+    echo "Timed out"
+    exit 1
+fi
+responseFirstWord=$(echo "$response" | head -n1 | awk '{print $1;}')
+if [ "$response" != "PONG" ] && [ "$responseFirstWord" != "LOADING" ] && [ "$responseFirstWord" != "MASTERDOWN" ]; then
+    echo "$response"
+    exit 1
+fi
\ No newline at end of file
diff --git a/rootfs/scripts/ping_readiness_local.sh b/rootfs/scripts/ping_readiness_local.sh
new file mode 100755
index 0000000..df10bac
--- /dev/null
+++ b/rootfs/scripts/ping_readiness_local.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# shellcheck disable=SC1091
+. /scripts/init.sh
+
+response=$(
+    timeout -s 3 "$1" \
+    valkey-cli \
+    -h localhost \
+    -p "${SERVER_PORT}" \
+    ping
+)
+if [ "$?" -eq "124" ]; then
+    echo "Timed out"
+    exit 1
+fi
+if [ "$response" != "PONG" ]; then
+    echo "$response"
+    exit 1
+fi
\ No newline at end of file
diff --git a/rootfs/scripts/ping_sentinel.sh b/rootfs/scripts/ping_sentinel.sh
new file mode 100755
index 0000000..159f4c8
--- /dev/null
+++ b/rootfs/scripts/ping_sentinel.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# shellcheck disable=SC1091
+. /scripts/init.sh
+
+response=$(
+    timeout -s 3 "$1" \
+    valkey-cli \
+    -h localhost \
+    -p "${SENTINEL_PORT}" \
+    ping
+)
+if [ "$?" -eq "124" ]; then
+    echo "Timed out"
+    exit 1
+fi
+if [ "$response" != "PONG" ]; then
+    echo "$response"
+    exit 1
+fi
diff --git a/rootfs/scripts/prestop-sentinel.sh b/rootfs/scripts/prestop-sentinel.sh
new file mode 100755
index 0000000..0bb158b
--- /dev/null
+++ b/rootfs/scripts/prestop-sentinel.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+# shellcheck disable=SC1091
+. /scripts/init.sh
+
+run_sentinel_command() {
+    valkey-cli -h "$DRYCC_VALKEY_SENTINEL" -p "${SENTINEL_PORT}" sentinel "$@"
+}
+
+failover_finished() {
+    # shellcheck disable=SC2207
+    SENTINEL_INFO=($(run_sentinel_command get-master-addr-by-name drycc))
+    VALKEY_MASTER_HOST="${SENTINEL_INFO[0]}"
+    [[ "$VALKEY_MASTER_HOST" != "$(hostname -I | xargs)" ]]
+}
+
+if ! failover_finished; then
+    echo "I am the master pod and you are stopping me. Starting sentinel failover"
+    # if I am the master, issue a command to failover once and then wait for the failover to finish
+    run_sentinel_command failover drycc
+    if retry_while "failover_finished" 30 1; then
+        echo "Master has been successfuly failed over to a different pod."
+        exit 0
+    else
+        echo "Master failover failed"
+        exit 1
+    fi
+else
+    exit 0
+fi
\ No newline at end of file
diff --git a/rootfs/scripts/prestop-valkey.sh b/rootfs/scripts/prestop-valkey.sh
new file mode 100755
index 0000000..275cee6
--- /dev/null
+++ b/rootfs/scripts/prestop-valkey.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# shellcheck disable=SC1091
+. /scripts/init.sh
+
+run_valkey_command() {
+    valkey-cli -h localhost -p "${SERVER_PORT}" "$@"
+}
+
+failover_finished() {
+    VALKEY_ROLE=$(run_valkey_command role | head -1)
+    [[ "$VALKEY_ROLE" != "master" ]]
+}
+
+if ! failover_finished; then
+    echo "Waiting for sentinel to run failover for up to {{ sub .Values.sentinel.terminationGracePeriodSeconds 10 }}s"
+    retry_while "failover_finished" 30 1
+else
+    exit 0
+fi

From b2f8df9e22fdfa0d7d33bb41d3598c38fb8d908c Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Fri, 22 Nov 2024 09:22:46 +0800
Subject: [PATCH 09/21] feat(valkey): add valkey sentinel proxy

---
 README.md                                     | 12 +++++
 _test/test.sh                                 | 24 +++++++++-
 .../valkey/templates/valkey-statefulset.yaml  | 45 +++++++++++++++++++
 charts/valkey/templates/valkey-svc.yaml       |  4 ++
 rootfs/Dockerfile                             |  4 +-
 rootfs/bin/valkey-start                       | 14 +++++-
 6 files changed, 99 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index 9105718..28cb9d5 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,18 @@
 
 Drycc (pronounced DAY-iss) Workflow is an open source Platform as a Service (PaaS) that adds a developer-friendly layer to any [Kubernetes](http://kubernetes.io) cluster, making it easy to deploy and manage applications on your own servers.
 
+## Usage
+
+Different components use different db, as follows:
+
+* `controller` use db 0
+* `passport` use db 1
+* `fluentbit` and `logger` use db 2
+* `manager` use db 10
+* `helmbroker` use db 11
+
+The above are the default configurations for each component.
+
 ## Description
 A Container image for running standalone (not clustered) Valkey on a Kubernetes cluster.
 
diff --git a/_test/test.sh b/_test/test.sh
index 5e8bc2c..badc3e8 100755
--- a/_test/test.sh
+++ b/_test/test.sh
@@ -3,6 +3,7 @@
 VERSION="$1"
 
 CONTAINER_NETWORK="valkey"
+CONTAINER_PROXY_NAME="valkey-benchmark-proxy"
 CONTAINER_MASTER_NAME="valkey-benchmark-master"
 CONTAINER_SLAVE1_NAME="valkey-benchmark-slave1"
 CONTAINER_SLAVE2_NAME="valkey-benchmark-slave2"
@@ -66,8 +67,25 @@ start-valkey-slave2() {
     podman exec "$CONTAINER_SLAVE2_NAME" init-stack valkey-start sentinel $CONTAINER_SLAVE2_NAME &
 }
 
+start-valkey-proxy() {
+    podman run -d \
+      --rm \
+      --network "$CONTAINER_NETWORK" \
+      --ip 192.168.253.13 \
+      --add-host="$CONTAINER_MASTER_NAME:192.168.253.10" \
+      --add-host="$CONTAINER_SLAVE1_NAME:192.168.253.11" \
+      --add-host="$CONTAINER_SLAVE2_NAME:192.168.253.12" \
+      --env "REDISCLI_AUTH=$DRYCC_VALKEY_PASSWORD" \
+      --env "DRYCC_VALKEY_SENTINEL=$DRYCC_VALKEY_SENTINEL" \
+      --env "DRYCC_VALKEY_PASSWORD=$DRYCC_VALKEY_PASSWORD" \
+      --name "$CONTAINER_PROXY_NAME" \
+      "registry.drycc.cc/drycc/valkey:$VERSION" \
+      valkey-start proxy
+}
+
 clean-valkey() {
     {
+        podman stop -i "$CONTAINER_PROXY_NAME"
         podman stop -i "$CONTAINER_SLAVE1_NAME"
         podman stop -i "$CONTAINER_SLAVE2_NAME"
         podman stop -i "$CONTAINER_MASTER_NAME"
@@ -80,8 +98,12 @@ podman network create --subnet=192.168.253.0/24 "$CONTAINER_NETWORK"
 start-valkey-master
 start-valkey-slave1
 start-valkey-slave2
+start-valkey-proxy
+
+echo "run valkey proxy benchmark..."
+podman exec "$CONTAINER_PROXY_NAME" init-stack valkey-benchmark -p 16379 -a $DRYCC_VALKEY_PASSWORD
 
-echo "run valkey benchmark..."
+echo "run valkey master benchmark..."
 podman exec "$CONTAINER_MASTER_NAME" init-stack valkey-benchmark -a $DRYCC_VALKEY_PASSWORD
 
 echo "check slave all keys..."
diff --git a/charts/valkey/templates/valkey-statefulset.yaml b/charts/valkey/templates/valkey-statefulset.yaml
index 0828992..869ffa5 100644
--- a/charts/valkey/templates/valkey-statefulset.yaml
+++ b/charts/valkey/templates/valkey-statefulset.yaml
@@ -23,6 +23,51 @@ spec:
         podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAntiAffinityPreset.type "component" "" "extraMatchLabels" .Values.podAntiAffinityPreset.extraMatchLabels "topologyKey" "" "context" $) | nindent 10 }}
         nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.nodeAffinityPreset.type "key" .Values.nodeAffinityPreset.key "values" .Values.nodeAffinityPreset.values ) | nindent 10 }}
       containers:
+      - name: proxy
+        image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/valkey:{{ .Values.imageTag }}
+        imagePullPolicy: {{ .Values.imagePullPolicy }}
+        {{- if .Values.diagnosticMode.enabled }}
+        command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 10 }}
+        args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 10 }}
+        {{- else }}
+        args:
+        - valkey-start
+        - proxy
+        {{- end }}
+        env:
+        - name: DRYCC_VALKEY_PASSWORD
+          valueFrom:
+            secretKeyRef:
+              name: valkey-creds
+              key: password
+        - name: DRYCC_VALKEY_SENTINEL
+          value: {{ printf "drycc-valkey.%s.svc.%s" $.Release.Namespace $.Values.global.clusterDomain }}
+        ports:
+        - containerPort: 16379
+        startupProbe:
+          initialDelaySeconds: 10
+          periodSeconds: 10
+          timeoutSeconds: 5
+          successThreshold: 1
+          failureThreshold: 22
+          tcpSocket:
+            port: 16379
+        livenessProbe:
+          initialDelaySeconds: 20
+          periodSeconds: 5
+          timeoutSeconds: 5
+          successThreshold: 1
+          failureThreshold: 5
+          tcpSocket:
+            port: 16379
+        readinessProbe:
+          initialDelaySeconds: 20
+          periodSeconds: 5
+          timeoutSeconds: 1
+          successThreshold: 1
+          failureThreshold: 5
+          tcpSocket:
+            port: 16379
       - name: server
         image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/valkey:{{ .Values.imageTag }}
         imagePullPolicy: {{ .Values.imagePullPolicy }}
diff --git a/charts/valkey/templates/valkey-svc.yaml b/charts/valkey/templates/valkey-svc.yaml
index 641c91f..2300909 100644
--- a/charts/valkey/templates/valkey-svc.yaml
+++ b/charts/valkey/templates/valkey-svc.yaml
@@ -13,6 +13,10 @@ spec:
   clusterIP: None
   publishNotReadyAddresses: true
   ports:
+  - name: proxy
+    port: 16379
+    targetPort: 16379
+    protocol: TCP
   - name: server
     port: 6379
     targetPort: 6379
diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile
index 2fd5601..e3af43d 100644
--- a/rootfs/Dockerfile
+++ b/rootfs/Dockerfile
@@ -4,7 +4,8 @@ FROM registry.drycc.cc/drycc/base:${CODENAME}
 ENV DRYCC_UID=1001 \
   DRYCC_GID=1001 \
   DRYCC_HOME_DIR=/data \
-  VALKEY_VERSION="8.0.1"
+  VALKEY_VERSION="8.0.1" \
+  VALKEY_SENTINEL_PROXY_VERSION="1.0.1"
 
 RUN groupadd drycc --gid ${DRYCC_GID} \
   && useradd drycc -u ${DRYCC_UID} -g ${DRYCC_GID} -s /bin/bash -m -d ${DRYCC_HOME_DIR}
@@ -14,6 +15,7 @@ COPY etc/valkey /etc/valkey
 COPY bin/valkey-start /bin/valkey-start
 
 RUN install-stack valkey ${VALKEY_VERSION} \
+  && install-stack valkey-sentinel-proxy ${VALKEY_SENTINEL_PROXY_VERSION} \
   && rm -rf \
       /usr/share/doc \
       /usr/share/man \
diff --git a/rootfs/bin/valkey-start b/rootfs/bin/valkey-start
index 5a2090b..77618ae 100755
--- a/rootfs/bin/valkey-start
+++ b/rootfs/bin/valkey-start
@@ -6,10 +6,11 @@
 print_usage() {
     echo "Valid commands for valkey-start:"
     echo ""
+    echo "proxy <announce-host>               start valkey proxy"
     echo "server <announce-host>              start valkey server"
     echo "sentinel <announce-host>            start valkey sentinel"
     echo ""
-    echo "Such as 'weed-start server valkey.valkey.svc.cluster.local' to start valkey server."
+    echo "Such as 'valkey-start server valkey.valkey.svc.cluster.local' to start valkey server."
 }
 
 remove_in_file() {
@@ -24,6 +25,15 @@ get_master_info() {
     eval "$command"
 }
 
+start_valkey_proxy() {
+    exec valkey-sentinel-proxy \
+        --listen=:16379 \
+        --master=drycc \
+        --max-procs=4 \
+        --sentinel-addr="${DRYCC_VALKEY_SENTINEL}":26379 \
+        --sentinel-pass="${DRYCC_VALKEY_PASSWORD}"
+}
+
 start_valkey_server() {
     announce_ip="$1"
     VALKEY_CONFIG_FILE=/data/server/valkey.conf
@@ -92,7 +102,7 @@ start_valkey_sentinel() {
 }
 
 command="$1"
-if [[ ${command} == "server" || ${command} == "sentinel" ]]; then
+if [[ ${command} == "proxy" || ${command} == "server" || ${command} == "sentinel" ]]; then
     "start_valkey_$command" "$2"
 else
     print_usage

From a1277dfd5b7176a052714c1a9344613295050dd2 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Mon, 23 Dec 2024 14:12:41 +0800
Subject: [PATCH 10/21] fix(wooddpecker): secsets are deprecated

---
 .woodpecker/build-linux.yml | 17 +++++++++++------
 .woodpecker/chart.yaml      | 14 +++++++++-----
 .woodpecker/manifest.yml    | 13 ++++++++-----
 .woodpecker/test-linux.yml  |  8 +++++---
 4 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/.woodpecker/build-linux.yml b/.woodpecker/build-linux.yml
index 782d2f5..3424a97 100644
--- a/.woodpecker/build-linux.yml
+++ b/.woodpecker/build-linux.yml
@@ -14,12 +14,17 @@ steps:
   - export VERSION=$([ -z $CI_COMMIT_TAG ] && echo latest || echo $CI_COMMIT_TAG)-$(sed 's#/#-#g' <<< $CI_SYSTEM_PLATFORM)
   - echo $CONTAINER_PASSWORD | podman login $DRYCC_REGISTRY --username $CONTAINER_USERNAME --password-stdin > /dev/null 2>&1
   - make podman-build podman-immutable-push
-  secrets:
-  - codename
-  - dev_registry
-  - drycc_registry
-  - container_username
-  - container_password
+  environment:
+    CODENAME:
+      from_secret: codename
+    DEV_REGISTRY:
+      from_secret: dev_registry
+    DRYCC_REGISTRY:
+      from_secret: drycc_registry
+    CONTAINER_USERNAME:
+      from_secret: container_username
+    CONTAINER_PASSWORD:
+      from_secret: container_password
   when:
     event:
     - push
diff --git a/.woodpecker/chart.yaml b/.woodpecker/chart.yaml
index 5aa7eb3..40397e0 100644
--- a/.woodpecker/chart.yaml
+++ b/.woodpecker/chart.yaml
@@ -14,11 +14,15 @@ steps:
   - helm package -u charts/$${CI_REPO_NAME} --version $CHART_VERSION --app-version $APP_VERSION
   - echo $CONTAINER_PASSWORD | helm registry login $DRYCC_REGISTRY -u $CONTAINER_USERNAME --password-stdin
   - helm push $${CI_REPO_NAME}-$CHART_VERSION.tgz oci://$DRYCC_REGISTRY/$([ -z $CI_COMMIT_TAG ] && echo charts-testing || echo charts)
-  secrets:
-  - dev_registry
-  - drycc_registry
-  - container_username
-  - container_password
+  environment:
+    DEV_REGISTRY:
+      from_secret: dev_registry
+    DRYCC_REGISTRY:
+      from_secret: drycc_registry
+    CONTAINER_USERNAME:
+      from_secret: container_username
+    CONTAINER_PASSWORD:
+      from_secret: container_password
   when:
     event:
     - push
diff --git a/.woodpecker/manifest.yml b/.woodpecker/manifest.yml
index b4735ee..6a91aa3 100644
--- a/.woodpecker/manifest.yml
+++ b/.woodpecker/manifest.yml
@@ -8,8 +8,9 @@ steps:
   commands:
   - sed -i "s/{{project}}/$${CI_REPO_NAME}/g" .woodpecker/manifest.tmpl
   - sed -i "s/registry.drycc.cc/$${DRYCC_REGISTRY}/g" .woodpecker/manifest.tmpl
-  secrets:
-  - drycc_registry
+  environment:
+    DRYCC_REGISTRY:
+      from_secret: drycc_registry
   when:
     event:
     - tag
@@ -26,9 +27,11 @@ steps:
     -v $(pwd):$(pwd)
     -w $(pwd)
     docker.io/plugins/manifest
-  secrets:
-  - container_username
-  - container_password
+  environment:
+    CONTAINER_USERNAME:
+      from_secret: container_username
+    CONTAINER_PASSWORD:
+      from_secret: container_password
   when:
     event:
     - tag
diff --git a/.woodpecker/test-linux.yml b/.woodpecker/test-linux.yml
index d47ccc5..0d5a93f 100644
--- a/.woodpecker/test-linux.yml
+++ b/.woodpecker/test-linux.yml
@@ -12,9 +12,11 @@ steps:
   image: bash
   commands:
   - make test
-  secrets:
-  - codename
-  - dev_registry
+  environment:
+    CODENAME:
+      from_secret: codename
+    DEV_REGISTRY:
+      from_secret: dev_registry
   when:
     event:
     - push

From e6cdc786aeccd132293d3179d74cb185337837a5 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Mon, 23 Dec 2024 19:05:17 +0800
Subject: [PATCH 11/21] chore(charts): remove dependencies

---
 charts/valkey/Chart.lock              |   6 ------
 charts/valkey/charts/common-1.1.3.tgz | Bin 10632 -> 0 bytes
 2 files changed, 6 deletions(-)
 delete mode 100644 charts/valkey/Chart.lock
 delete mode 100644 charts/valkey/charts/common-1.1.3.tgz

diff --git a/charts/valkey/Chart.lock b/charts/valkey/Chart.lock
deleted file mode 100644
index 2a25c53..0000000
--- a/charts/valkey/Chart.lock
+++ /dev/null
@@ -1,6 +0,0 @@
-dependencies:
-- name: common
-  repository: oci://registry.drycc.cc/charts
-  version: 1.1.3
-digest: sha256:4928b76b9f4927f43702c2617b139b2fe7298055b9b6d0c363a7a94530985595
-generated: "2024-11-20T16:35:58.537426209+08:00"
diff --git a/charts/valkey/charts/common-1.1.3.tgz b/charts/valkey/charts/common-1.1.3.tgz
deleted file mode 100644
index d1035f1a56b79241a8ae1ff4bfca514e8ceb60c4..0000000000000000000000000000000000000000
GIT binary patch

From 49bb439de2f997a4d58160b72446784739f2f777 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Thu, 3 Apr 2025 11:31:40 +0800
Subject: [PATCH 12/21] chore(valkey): add cron event

---
 .woodpecker/build-linux.yml | 1 +
 .woodpecker/chart.yaml      | 1 +
 .woodpecker/manifest.yml    | 2 ++
 .woodpecker/test-linux.yml  | 1 +
 rootfs/Dockerfile           | 4 ++--
 5 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/.woodpecker/build-linux.yml b/.woodpecker/build-linux.yml
index 3424a97..ef4ecfd 100644
--- a/.woodpecker/build-linux.yml
+++ b/.woodpecker/build-linux.yml
@@ -29,6 +29,7 @@ steps:
     event:
     - push
     - tag
+    - cron
 
 depends_on:
 - test-linux
\ No newline at end of file
diff --git a/.woodpecker/chart.yaml b/.woodpecker/chart.yaml
index 40397e0..cfcd3ec 100644
--- a/.woodpecker/chart.yaml
+++ b/.woodpecker/chart.yaml
@@ -27,6 +27,7 @@ steps:
     event:
     - push
     - tag
+    - cron
 
 depends_on:
 - manifest
diff --git a/.woodpecker/manifest.yml b/.woodpecker/manifest.yml
index 6a91aa3..19fc70c 100644
--- a/.woodpecker/manifest.yml
+++ b/.woodpecker/manifest.yml
@@ -15,6 +15,7 @@ steps:
     event:
     - tag
     - push
+    - cron
 
 - name: publish-manifest
   image: bash
@@ -36,6 +37,7 @@ steps:
     event:
     - tag
     - push
+    - cron
 
 depends_on:
 - build-linux
diff --git a/.woodpecker/test-linux.yml b/.woodpecker/test-linux.yml
index 0d5a93f..194832f 100644
--- a/.woodpecker/test-linux.yml
+++ b/.woodpecker/test-linux.yml
@@ -21,3 +21,4 @@ steps:
     event:
     - push
     - tag
+    - cron
diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile
index e3af43d..a67a5bc 100644
--- a/rootfs/Dockerfile
+++ b/rootfs/Dockerfile
@@ -4,8 +4,8 @@ FROM registry.drycc.cc/drycc/base:${CODENAME}
 ENV DRYCC_UID=1001 \
   DRYCC_GID=1001 \
   DRYCC_HOME_DIR=/data \
-  VALKEY_VERSION="8.0.1" \
-  VALKEY_SENTINEL_PROXY_VERSION="1.0.1"
+  VALKEY_VERSION="8.1.0" \
+  VALKEY_SENTINEL_PROXY_VERSION="1.0.2"
 
 RUN groupadd drycc --gid ${DRYCC_GID} \
   && useradd drycc -u ${DRYCC_UID} -g ${DRYCC_GID} -s /bin/bash -m -d ${DRYCC_HOME_DIR}

From 1e7413432937370539213f33944630a9fac52895 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Wed, 7 May 2025 18:04:47 +0800
Subject: [PATCH 13/21] chore(charts): use condition

---
 charts/valkey/templates/valkey-secret-creds.yaml |  2 --
 charts/valkey/templates/valkey-statefulset.yaml  |  2 --
 charts/valkey/templates/valkey-svc.yaml          |  2 --
 charts/valkey/values.yaml                        | 11 -----------
 rootfs/Dockerfile                                |  2 +-
 rootfs/bin/valkey-start                          |  2 +-
 6 files changed, 2 insertions(+), 19 deletions(-)

diff --git a/charts/valkey/templates/valkey-secret-creds.yaml b/charts/valkey/templates/valkey-secret-creds.yaml
index b3f0ea0..33c81d2 100644
--- a/charts/valkey/templates/valkey-secret-creds.yaml
+++ b/charts/valkey/templates/valkey-secret-creds.yaml
@@ -1,4 +1,3 @@
-{{- if eq .Values.global.valkeyLocation "on-cluster" }}
 apiVersion: v1
 kind: Secret
 metadata:
@@ -8,4 +7,3 @@ metadata:
     heritage: drycc
 data:
   password: {{ include "common.secrets.lookup" (dict "secret" "valkey-creds" "key" "password" "defaultValue" (randAlphaNum 32) "context" $) }}
-{{- end }}
diff --git a/charts/valkey/templates/valkey-statefulset.yaml b/charts/valkey/templates/valkey-statefulset.yaml
index 869ffa5..14d7c36 100644
--- a/charts/valkey/templates/valkey-statefulset.yaml
+++ b/charts/valkey/templates/valkey-statefulset.yaml
@@ -1,4 +1,3 @@
-{{- if eq .Values.global.valkeyLocation "on-cluster" }}
 apiVersion: apps/v1
 kind: StatefulSet
 metadata:
@@ -251,4 +250,3 @@ spec:
         requests:
           storage: {{ .Values.persistence.size | quote }}
   {{- end }}
-{{- end }}
diff --git a/charts/valkey/templates/valkey-svc.yaml b/charts/valkey/templates/valkey-svc.yaml
index 2300909..1bd38dc 100644
--- a/charts/valkey/templates/valkey-svc.yaml
+++ b/charts/valkey/templates/valkey-svc.yaml
@@ -1,4 +1,3 @@
-{{- if eq .Values.global.valkeyLocation "on-cluster" }}
 apiVersion: v1
 kind: Service
 metadata:
@@ -27,4 +26,3 @@ spec:
     protocol: TCP
   selector:
     app: drycc-valkey
-{{- end }}
diff --git a/charts/valkey/values.yaml b/charts/valkey/values.yaml
index 1471d44..6ca0cb4 100644
--- a/charts/valkey/values.yaml
+++ b/charts/valkey/values.yaml
@@ -39,10 +39,6 @@ podAntiAffinityPreset:
 # The following parameters are configured only when using an on-cluster Valkey instance
 replicas: 3
 
-# The following parameters are configured only when using an off-cluster Valkey instance
-addrs: "" # A list of clusters: "127.0.0.1:7001/1,127.0.0.2:7002/1"
-password: "valkey password" # "" == no password
-
 # Service
 service:
   # Provide any additional service annotations
@@ -60,10 +56,3 @@ global:
   # Each part must be 1 to 63 characters in length and can contain lowercase letters, digits, and hyphens (-).
   # It must start and end with a lowercase letter or digit.
   clusterDomain: "cluster.local"
-  # Set the location of Workflow's valkey instance
-  #
-  # Valid values are:
-  # - on-cluster: Run Valkey within the Kubernetes cluster
-  # - off-cluster: Run Valkey outside the Kubernetes cluster (configure in valkey section)
-  valkeyLocation: "on-cluster"
-  
\ No newline at end of file
diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile
index a67a5bc..27c4bf7 100644
--- a/rootfs/Dockerfile
+++ b/rootfs/Dockerfile
@@ -4,7 +4,7 @@ FROM registry.drycc.cc/drycc/base:${CODENAME}
 ENV DRYCC_UID=1001 \
   DRYCC_GID=1001 \
   DRYCC_HOME_DIR=/data \
-  VALKEY_VERSION="8.1.0" \
+  VALKEY_VERSION="8.1.1" \
   VALKEY_SENTINEL_PROXY_VERSION="1.0.2"
 
 RUN groupadd drycc --gid ${DRYCC_GID} \
diff --git a/rootfs/bin/valkey-start b/rootfs/bin/valkey-start
index 77618ae..a49639c 100755
--- a/rootfs/bin/valkey-start
+++ b/rootfs/bin/valkey-start
@@ -98,7 +98,7 @@ start_valkey_sentinel() {
     else
         printf "\nsentinel monitor drycc %s %s 2" "${announce_ip}" "${SERVER_PORT}" >> ${VALKEY_SENTINEL_CONFIG_FILE}
     fi
-    exec valkey-sentinel $VALKEY_SENTINEL_CONFIG_FILE
+    exec valkey-server $VALKEY_SENTINEL_CONFIG_FILE --sentinel
 }
 
 command="$1"

From 657b28c3cdfb7d55eb9a582c04dfcd2d7c5596ed Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Mon, 12 May 2025 09:20:00 +0800
Subject: [PATCH 14/21] chore(charts): change resources format

---
 .../valkey/templates/valkey-statefulset.yaml  | 32 +++++++------------
 charts/valkey/values.yaml                     | 29 +++++++++++++++--
 2 files changed, 39 insertions(+), 22 deletions(-)

diff --git a/charts/valkey/templates/valkey-statefulset.yaml b/charts/valkey/templates/valkey-statefulset.yaml
index 14d7c36..1ffeb3a 100644
--- a/charts/valkey/templates/valkey-statefulset.yaml
+++ b/charts/valkey/templates/valkey-statefulset.yaml
@@ -43,6 +43,10 @@ spec:
           value: {{ printf "drycc-valkey.%s.svc.%s" $.Release.Namespace $.Values.global.clusterDomain }}
         ports:
         - containerPort: 16379
+        {{- with index .Values "proxy" "resources" }}
+        resources:
+          {{- toYaml . | nindent 10 }}
+        {{- end }}
         startupProbe:
           initialDelaySeconds: 10
           periodSeconds: 10
@@ -70,16 +74,6 @@ spec:
       - name: server
         image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/valkey:{{ .Values.imageTag }}
         imagePullPolicy: {{ .Values.imagePullPolicy }}
-        {{- if or (.Values.limitsCpu) (.Values.limitsMemory)}}
-        resources:
-          limits:
-            {{- if (.Values.limitsCpu) }}
-            cpu: {{.Values.limitsCpu}}
-            {{- end}}
-            {{- if (.Values.limitsMemory) }}
-            memory: {{.Values.limitsMemory}}
-            {{- end}}
-        {{- end}}
         {{- if .Values.diagnosticMode.enabled }}
         command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 10 }}
         args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 10 }}
@@ -91,6 +85,10 @@ spec:
         {{- end }}
         ports:
         - containerPort: 6379
+        {{- with index .Values "server" "resources" }}
+        resources:
+          {{- toYaml . | nindent 10 }}
+        {{- end }}
         env:
         - name: POD_NAME
           valueFrom:
@@ -151,16 +149,6 @@ spec:
       - name: sentinel
         image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/valkey:{{ .Values.imageTag }}
         imagePullPolicy: {{ .Values.imagePullPolicy }}
-        {{- if or (.Values.limitsCpu) (.Values.limitsMemory)}}
-        resources:
-          limits:
-            {{- if (.Values.limitsCpu) }}
-            cpu: {{.Values.limitsCpu}}
-            {{- end}}
-            {{- if (.Values.limitsMemory) }}
-            memory: {{.Values.limitsMemory}}
-            {{- end}}
-        {{- end}}
         {{- if .Values.diagnosticMode.enabled }}
         command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 10 }}
         args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 10 }}
@@ -172,6 +160,10 @@ spec:
         {{- end }}
         ports:
         - containerPort: 26379
+        {{- with index .Values "sentinel" "resources" }}
+        resources:
+          {{- toYaml . | nindent 10 }}
+        {{- end }}
         env:
         - name: POD_NAME
           valueFrom:
diff --git a/charts/valkey/values.yaml b/charts/valkey/values.yaml
index 6ca0cb4..1908f37 100644
--- a/charts/valkey/values.yaml
+++ b/charts/valkey/values.yaml
@@ -2,8 +2,6 @@ imageOrg: "drycc"
 imagePullPolicy: "Always"
 imageTag: "canary"
 imageRegistry: "registry.drycc.cc"
-# limitsCpu: "100m"
-# limitsMemory: "50Mi"
 
 ## Enable diagnostic mode
 ##
@@ -44,6 +42,33 @@ service:
   # Provide any additional service annotations
   annotations: {}
 
+proxy:
+  resources: {}
+    # limits:
+    #   cpu: 200m
+    #   memory: 50Mi
+    # requests:
+    #   cpu: 100m
+    #   memory: 30Mi
+
+server:
+  resources: {}
+    # limits:
+    #   cpu: 200m
+    #   memory: 50Mi
+    # requests:
+    #   cpu: 100m
+    #   memory: 30Mi
+
+sentinel:
+  resources: {}
+    # limits:
+    #   cpu: 200m
+    #   memory: 50Mi
+    # requests:
+    #   cpu: 100m
+    #   memory: 30Mi
+
 # GCP PDs and EBS volumes are supported only
 persistence:
   enabled: false # Set to true to enable persistence

From 0e2d55c307110337d10ac53a290e02cebd6ee077 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Tue, 20 May 2025 11:39:05 +0800
Subject: [PATCH 15/21] chore(valkey): add redis_exporter

---
 .../valkey/templates/valkey-statefulset.yaml  | 52 +++++++++++++++++--
 charts/valkey/templates/valkey-svc.yaml       |  7 +++
 rootfs/Dockerfile                             |  6 ++-
 3 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/charts/valkey/templates/valkey-statefulset.yaml b/charts/valkey/templates/valkey-statefulset.yaml
index 1ffeb3a..b14c700 100644
--- a/charts/valkey/templates/valkey-statefulset.yaml
+++ b/charts/valkey/templates/valkey-statefulset.yaml
@@ -22,7 +22,7 @@ spec:
         podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAntiAffinityPreset.type "component" "" "extraMatchLabels" .Values.podAntiAffinityPreset.extraMatchLabels "topologyKey" "" "context" $) | nindent 10 }}
         nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.nodeAffinityPreset.type "key" .Values.nodeAffinityPreset.key "values" .Values.nodeAffinityPreset.values ) | nindent 10 }}
       containers:
-      - name: proxy
+      - name: drycc-valkey-proxy
         image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/valkey:{{ .Values.imageTag }}
         imagePullPolicy: {{ .Values.imagePullPolicy }}
         {{- if .Values.diagnosticMode.enabled }}
@@ -71,7 +71,7 @@ spec:
           failureThreshold: 5
           tcpSocket:
             port: 16379
-      - name: server
+      - name: drycc-valkey-server
         image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/valkey:{{ .Values.imageTag }}
         imagePullPolicy: {{ .Values.imagePullPolicy }}
         {{- if .Values.diagnosticMode.enabled }}
@@ -146,7 +146,7 @@ spec:
                 - /bin/bash
                 - -c
                 - /scripts/prestop-valkey.sh
-      - name: sentinel
+      - name: drycc-valkey-sentinel
         image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/valkey:{{ .Values.imageTag }}
         imagePullPolicy: {{ .Values.imagePullPolicy }}
         {{- if .Values.diagnosticMode.enabled }}
@@ -221,6 +221,52 @@ spec:
                 - /bin/bash
                 - -c
                 - /scripts/prestop-sentinel.sh
+      - name: drycc-valkey-metrics
+        image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/valkey:{{ .Values.imageTag }}
+        imagePullPolicy: {{ .Values.imagePullPolicy }}
+        {{- if .Values.diagnosticMode.enabled }}
+        command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 10 }}
+        args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 10 }}
+        {{- else }}
+        command:
+        - init-stack
+        args:
+        - redis_exporter
+        {{- end }}
+        ports:
+        - containerPort: 9121
+        env:
+        - name: REDIS_PASSWORD
+          valueFrom:
+            secretKeyRef:
+              name: valkey-creds
+              key: password
+        startupProbe:
+          initialDelaySeconds: 10
+          tcpSocket:
+              port: 9121
+          periodSeconds: 10
+          timeoutSeconds: 1
+          failureThreshold: 15
+          successThreshold: 1
+        livenessProbe:
+          initialDelaySeconds: 5
+          httpGet:
+            path: /
+            port: 9121
+          periodSeconds: 10
+          timeoutSeconds: 5
+          failureThreshold: 6
+          successThreshold: 1
+        readinessProbe:
+          initialDelaySeconds: 5
+          httpGet:
+            path: /
+            port: 9121
+          periodSeconds: 10
+          timeoutSeconds: 5
+          failureThreshold: 6
+          successThreshold: 1
       securityContext:
         fsGroup: 1001
         runAsGroup: 1001
diff --git a/charts/valkey/templates/valkey-svc.yaml b/charts/valkey/templates/valkey-svc.yaml
index 1bd38dc..c38af8c 100644
--- a/charts/valkey/templates/valkey-svc.yaml
+++ b/charts/valkey/templates/valkey-svc.yaml
@@ -3,6 +3,9 @@ kind: Service
 metadata:
   name: drycc-valkey
   annotations:
+    prometheus.io/path: /metrics
+    prometheus.io/port: "9121"
+    prometheus.io/scrape: "true"
     {{- with .Values.service.annotations }}
     {{- toYaml . | nindent 4 }}
     {{- end }}
@@ -20,6 +23,10 @@ spec:
     port: 6379
     targetPort: 6379
     protocol: TCP
+  - name: metrics
+    port: 9121
+    targetPort: 9121
+    protocol: TCP
   - name: sentinel
     port: 26379
     targetPort: 26379
diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile
index 27c4bf7..f331428 100644
--- a/rootfs/Dockerfile
+++ b/rootfs/Dockerfile
@@ -5,7 +5,8 @@ ENV DRYCC_UID=1001 \
   DRYCC_GID=1001 \
   DRYCC_HOME_DIR=/data \
   VALKEY_VERSION="8.1.1" \
-  VALKEY_SENTINEL_PROXY_VERSION="1.0.2"
+  VALKEY_SENTINEL_PROXY_VERSION="1.0.2" \
+  REDIS_EXPORTER_VERSION="1.51.0"
 
 RUN groupadd drycc --gid ${DRYCC_GID} \
   && useradd drycc -u ${DRYCC_UID} -g ${DRYCC_GID} -s /bin/bash -m -d ${DRYCC_HOME_DIR}
@@ -16,6 +17,7 @@ COPY bin/valkey-start /bin/valkey-start
 
 RUN install-stack valkey ${VALKEY_VERSION} \
   && install-stack valkey-sentinel-proxy ${VALKEY_SENTINEL_PROXY_VERSION} \
+  && install-stack redis_exporter $REDIS_EXPORTER_VERSION \
   && rm -rf \
       /usr/share/doc \
       /usr/share/man \
@@ -34,4 +36,4 @@ RUN install-stack valkey ${VALKEY_VERSION} \
 
 USER ${DRYCC_UID}
 WORKDIR ${DRYCC_HOME_DIR}
-EXPOSE 6379 26379
+EXPOSE 6379 9121 26379

From 3fac5b3943fbe2c923887340248127aa9cc37b2b Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Tue, 15 Jul 2025 23:01:24 +0800
Subject: [PATCH 16/21] chore(charts): simplify the svc url

---
 charts/valkey/templates/valkey-statefulset.yaml | 10 +++++-----
 charts/valkey/values.yaml                       |  7 -------
 rootfs/bin/valkey-start                         |  2 +-
 3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/charts/valkey/templates/valkey-statefulset.yaml b/charts/valkey/templates/valkey-statefulset.yaml
index b14c700..be223df 100644
--- a/charts/valkey/templates/valkey-statefulset.yaml
+++ b/charts/valkey/templates/valkey-statefulset.yaml
@@ -40,7 +40,7 @@ spec:
               name: valkey-creds
               key: password
         - name: DRYCC_VALKEY_SENTINEL
-          value: {{ printf "drycc-valkey.%s.svc.%s" $.Release.Namespace $.Values.global.clusterDomain }}
+          value: drycc-valkey
         ports:
         - containerPort: 16379
         {{- with index .Values "proxy" "resources" }}
@@ -81,7 +81,7 @@ spec:
         args:
         - valkey-start
         - server
-        - $(POD_NAME).{{ printf "drycc-valkey.%s.svc.%s" $.Release.Namespace $.Values.global.clusterDomain }}
+        - $(POD_NAME).drycc-valkey
         {{- end }}
         ports:
         - containerPort: 6379
@@ -95,7 +95,7 @@ spec:
             fieldRef:
               fieldPath: metadata.name
         - name: DRYCC_VALKEY_SENTINEL
-          value: {{ printf "drycc-valkey.%s.svc.%s" $.Release.Namespace $.Values.global.clusterDomain }}
+          value: drycc-valkey
         - name: DRYCC_VALKEY_PASSWORD
           valueFrom:
             secretKeyRef:
@@ -156,7 +156,7 @@ spec:
         args:
         - valkey-start
         - sentinel
-        - $(POD_NAME).{{ printf "drycc-valkey.%s.svc.%s" $.Release.Namespace $.Values.global.clusterDomain }}
+        - $(POD_NAME).drycc-valkey
         {{- end }}
         ports:
         - containerPort: 26379
@@ -170,7 +170,7 @@ spec:
             fieldRef:
               fieldPath: metadata.name
         - name: DRYCC_VALKEY_SENTINEL
-          value: {{ printf "drycc-valkey.%s.svc.%s" $.Release.Namespace $.Values.global.clusterDomain }}
+          value: drycc-valkey
         - name: DRYCC_VALKEY_PASSWORD
           valueFrom:
             secretKeyRef:
diff --git a/charts/valkey/values.yaml b/charts/valkey/values.yaml
index 1908f37..bf19ca1 100644
--- a/charts/valkey/values.yaml
+++ b/charts/valkey/values.yaml
@@ -74,10 +74,3 @@ persistence:
   enabled: false # Set to true to enable persistence
   size: 5Gi
   storageClass: ""
-
-global:
-  # A domain name consists of one or more parts.
-  # Periods (.) are used to separate these parts.
-  # Each part must be 1 to 63 characters in length and can contain lowercase letters, digits, and hyphens (-).
-  # It must start and end with a lowercase letter or digit.
-  clusterDomain: "cluster.local"
diff --git a/rootfs/bin/valkey-start b/rootfs/bin/valkey-start
index a49639c..8ab7884 100755
--- a/rootfs/bin/valkey-start
+++ b/rootfs/bin/valkey-start
@@ -10,7 +10,7 @@ print_usage() {
     echo "server <announce-host>              start valkey server"
     echo "sentinel <announce-host>            start valkey sentinel"
     echo ""
-    echo "Such as 'valkey-start server valkey.valkey.svc.cluster.local' to start valkey server."
+    echo "Such as 'valkey-start server valkey.valkey.svc' to start valkey server."
 }
 
 remove_in_file() {

From 5f5f1f72502cc3540a141ecb84874a1025c4dfd6 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Sun, 14 Sep 2025 01:24:04 +0800
Subject: [PATCH 17/21] chore(valkey): bump new version

---
 rootfs/Dockerfile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile
index f331428..99efde3 100644
--- a/rootfs/Dockerfile
+++ b/rootfs/Dockerfile
@@ -4,9 +4,9 @@ FROM registry.drycc.cc/drycc/base:${CODENAME}
 ENV DRYCC_UID=1001 \
   DRYCC_GID=1001 \
   DRYCC_HOME_DIR=/data \
-  VALKEY_VERSION="8.1.1" \
+  VALKEY_VERSION="8.1.3" \
   VALKEY_SENTINEL_PROXY_VERSION="1.0.2" \
-  REDIS_EXPORTER_VERSION="1.51.0"
+  REDIS_EXPORTER_VERSION="1.76.0"
 
 RUN groupadd drycc --gid ${DRYCC_GID} \
   && useradd drycc -u ${DRYCC_UID} -g ${DRYCC_GID} -s /bin/bash -m -d ${DRYCC_HOME_DIR}

From 22610f27ea65a99c9832619eecb57f05385050c6 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Tue, 4 Nov 2025 08:48:15 +0800
Subject: [PATCH 18/21] chore(valkey): bump version to 9.0.0

---
 _test/test.sh     | 64 +++++++++++++++++------------------------------
 rootfs/Dockerfile |  8 +++---
 2 files changed, 27 insertions(+), 45 deletions(-)

diff --git a/_test/test.sh b/_test/test.sh
index badc3e8..574b989 100755
--- a/_test/test.sh
+++ b/_test/test.sh
@@ -2,12 +2,10 @@
 
 VERSION="$1"
 
-CONTAINER_NETWORK="valkey"
 CONTAINER_PROXY_NAME="valkey-benchmark-proxy"
 CONTAINER_MASTER_NAME="valkey-benchmark-master"
 CONTAINER_SLAVE1_NAME="valkey-benchmark-slave1"
 CONTAINER_SLAVE2_NAME="valkey-benchmark-slave2"
-DRYCC_VALKEY_SENTINEL=$CONTAINER_MASTER_NAME
 DRYCC_VALKEY_PASSWORD=123456
 
 function clean_before_exit {
@@ -19,87 +17,71 @@ trap clean_before_exit EXIT
 start-valkey-master() {
     podman run -d \
       --rm \
-      --network "$CONTAINER_NETWORK" \
-      --ip 192.168.253.10 \
-      --add-host="$CONTAINER_MASTER_NAME:192.168.253.10" \
-      --add-host="$CONTAINER_SLAVE1_NAME:192.168.253.11" \
-      --add-host="$CONTAINER_SLAVE2_NAME:192.168.253.12" \
       --env "REDISCLI_AUTH=$DRYCC_VALKEY_PASSWORD" \
-      --env "DRYCC_VALKEY_SENTINEL=$DRYCC_VALKEY_SENTINEL" \
       --env "DRYCC_VALKEY_PASSWORD=$DRYCC_VALKEY_PASSWORD" \
       --name "$CONTAINER_MASTER_NAME" \
       "registry.drycc.cc/drycc/valkey:$VERSION" \
-      valkey-start server $CONTAINER_MASTER_NAME
-    podman exec "$CONTAINER_MASTER_NAME" init-stack valkey-start sentinel $CONTAINER_MASTER_NAME &
+      sleep infinity
+
+    master_ip=$(podman exec "$CONTAINER_MASTER_NAME" hostname -i | tr -d '\r\n')
+    podman exec --env "DRYCC_VALKEY_SENTINEL=$master_ip" "$CONTAINER_MASTER_NAME" init-stack valkey-start server "$master_ip"  &
+    podman exec --env "DRYCC_VALKEY_SENTINEL=$master_ip" "$CONTAINER_MASTER_NAME" init-stack valkey-start sentinel "$master_ip" &
 }
 
 start-valkey-slave1() {
     podman run -d \
       --rm \
-      --network "$CONTAINER_NETWORK" \
-      --ip 192.168.253.11 \
-      --add-host="$CONTAINER_MASTER_NAME:192.168.253.10" \
-      --add-host="$CONTAINER_SLAVE1_NAME:192.168.253.11" \
-      --add-host="$CONTAINER_SLAVE2_NAME:192.168.253.12" \
       --env "REDISCLI_AUTH=$DRYCC_VALKEY_PASSWORD" \
-      --env "DRYCC_VALKEY_SENTINEL=$DRYCC_VALKEY_SENTINEL" \
       --env "DRYCC_VALKEY_PASSWORD=$DRYCC_VALKEY_PASSWORD" \
       --name "$CONTAINER_SLAVE1_NAME" \
       "registry.drycc.cc/drycc/valkey:$VERSION" \
-      valkey-start server $CONTAINER_SLAVE1_NAME
-    podman exec "$CONTAINER_SLAVE1_NAME" init-stack valkey-start sentinel $CONTAINER_SLAVE1_NAME &
+      sleep infinity
+
+    slave1_ip=$(podman exec -it "$CONTAINER_SLAVE1_NAME" hostname -i | tr -d '\r\n')
+    podman exec --env "DRYCC_VALKEY_SENTINEL=$master_ip" "$CONTAINER_SLAVE1_NAME" init-stack valkey-start server "$slave1_ip" &
+    podman exec --env "DRYCC_VALKEY_SENTINEL=$master_ip" "$CONTAINER_SLAVE1_NAME" init-stack valkey-start sentinel "$slave1_ip" &
 }
 
 start-valkey-slave2() {
     podman run -d \
       --rm \
-      --network "$CONTAINER_NETWORK" \
-      --ip 192.168.253.12 \
-      --add-host="$CONTAINER_MASTER_NAME:192.168.253.10" \
-      --add-host="$CONTAINER_SLAVE1_NAME:192.168.253.11" \
-      --add-host="$CONTAINER_SLAVE2_NAME:192.168.253.12" \
       --env "REDISCLI_AUTH=$DRYCC_VALKEY_PASSWORD" \
-      --env "DRYCC_VALKEY_SENTINEL=$DRYCC_VALKEY_SENTINEL" \
       --env "DRYCC_VALKEY_PASSWORD=$DRYCC_VALKEY_PASSWORD" \
       --name "$CONTAINER_SLAVE2_NAME" \
       "registry.drycc.cc/drycc/valkey:$VERSION" \
-      valkey-start server $CONTAINER_SLAVE2_NAME
-    podman exec "$CONTAINER_SLAVE2_NAME" init-stack valkey-start sentinel $CONTAINER_SLAVE2_NAME &
+      sleep infinity
+
+    slave2_ip=$(podman exec -it "$CONTAINER_SLAVE2_NAME" hostname -i | tr -d '\r\n')
+    podman exec --env "DRYCC_VALKEY_SENTINEL=$master_ip" "$CONTAINER_SLAVE2_NAME" init-stack valkey-start server "$slave2_ip" &
+    podman exec --env "DRYCC_VALKEY_SENTINEL=$master_ip" "$CONTAINER_SLAVE2_NAME" init-stack valkey-start sentinel "$slave2_ip" &
 }
 
 start-valkey-proxy() {
     podman run -d \
       --rm \
-      --network "$CONTAINER_NETWORK" \
-      --ip 192.168.253.13 \
-      --add-host="$CONTAINER_MASTER_NAME:192.168.253.10" \
-      --add-host="$CONTAINER_SLAVE1_NAME:192.168.253.11" \
-      --add-host="$CONTAINER_SLAVE2_NAME:192.168.253.12" \
       --env "REDISCLI_AUTH=$DRYCC_VALKEY_PASSWORD" \
-      --env "DRYCC_VALKEY_SENTINEL=$DRYCC_VALKEY_SENTINEL" \
       --env "DRYCC_VALKEY_PASSWORD=$DRYCC_VALKEY_PASSWORD" \
       --name "$CONTAINER_PROXY_NAME" \
       "registry.drycc.cc/drycc/valkey:$VERSION" \
-      valkey-start proxy
+      sleep infinity
+
+    podman exec --env "DRYCC_VALKEY_SENTINEL=$master_ip" "$CONTAINER_PROXY_NAME" init-stack valkey-start proxy &
 }
 
 clean-valkey() {
     {
-        podman stop -i "$CONTAINER_PROXY_NAME"
-        podman stop -i "$CONTAINER_SLAVE1_NAME"
-        podman stop -i "$CONTAINER_SLAVE2_NAME"
-        podman stop -i "$CONTAINER_MASTER_NAME"
-        podman network rm -f "$CONTAINER_NETWORK"
-    } 2>>/dev/null
+        podman kill "$CONTAINER_PROXY_NAME"
+        podman kill "$CONTAINER_SLAVE1_NAME"
+        podman kill "$CONTAINER_SLAVE2_NAME"
+        podman kill "$CONTAINER_MASTER_NAME"
+    } >>/dev/null 2>&1
 }
 
 clean-valkey
-podman network create --subnet=192.168.253.0/24 "$CONTAINER_NETWORK"
 start-valkey-master
 start-valkey-slave1
 start-valkey-slave2
 start-valkey-proxy
-
 echo "run valkey proxy benchmark..."
 podman exec "$CONTAINER_PROXY_NAME" init-stack valkey-benchmark -p 16379 -a $DRYCC_VALKEY_PASSWORD
 
diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile
index 99efde3..f1b0e46 100644
--- a/rootfs/Dockerfile
+++ b/rootfs/Dockerfile
@@ -1,12 +1,12 @@
 ARG CODENAME
 FROM registry.drycc.cc/drycc/base:${CODENAME}
 
-ENV DRYCC_UID=1001 \
+ARG DRYCC_UID=1001 \
   DRYCC_GID=1001 \
   DRYCC_HOME_DIR=/data \
-  VALKEY_VERSION="8.1.3" \
-  VALKEY_SENTINEL_PROXY_VERSION="1.0.2" \
-  REDIS_EXPORTER_VERSION="1.76.0"
+  VALKEY_VERSION="9.0.0" \
+  VALKEY_SENTINEL_PROXY_VERSION="2.0.0" \
+  REDIS_EXPORTER_VERSION="1.80.0"
 
 RUN groupadd drycc --gid ${DRYCC_GID} \
   && useradd drycc -u ${DRYCC_UID} -g ${DRYCC_GID} -s /bin/bash -m -d ${DRYCC_HOME_DIR}

From 149f5d8b8bfad1f45eebf3562f69ecb38fe531f2 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Tue, 9 Dec 2025 12:46:03 +0800
Subject: [PATCH 19/21] chore(Dockerfile): bump valkey-sentinel-proxy version

---
 README.md         | 2 +-
 rootfs/Dockerfile | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 28cb9d5..ea5a0de 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ Different components use different db, as follows:
 
 * `controller` use db 0
 * `passport` use db 1
-* `fluentbit` and `logger` use db 2
+* `grafana` use db 2
 * `manager` use db 10
 * `helmbroker` use db 11
 
diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile
index f1b0e46..6068bee 100644
--- a/rootfs/Dockerfile
+++ b/rootfs/Dockerfile
@@ -5,8 +5,8 @@ ARG DRYCC_UID=1001 \
   DRYCC_GID=1001 \
   DRYCC_HOME_DIR=/data \
   VALKEY_VERSION="9.0.0" \
-  VALKEY_SENTINEL_PROXY_VERSION="2.0.0" \
-  REDIS_EXPORTER_VERSION="1.80.0"
+  VALKEY_SENTINEL_PROXY_VERSION="2.0.1" \
+  REDIS_EXPORTER_VERSION="1.80.1"
 
 RUN groupadd drycc --gid ${DRYCC_GID} \
   && useradd drycc -u ${DRYCC_UID} -g ${DRYCC_GID} -s /bin/bash -m -d ${DRYCC_HOME_DIR}

From 7b4c255bce9114bcd1987fa504124510ff27bc04 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Wed, 8 Apr 2026 18:35:00 +0800
Subject: [PATCH 20/21] feat(proxy): wait for sentinel readiness before
 starting proxy

---
 rootfs/bin/valkey-start | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/rootfs/bin/valkey-start b/rootfs/bin/valkey-start
index 8ab7884..d8204d8 100755
--- a/rootfs/bin/valkey-start
+++ b/rootfs/bin/valkey-start
@@ -25,7 +25,23 @@ get_master_info() {
     eval "$command"
 }
 
+wait_for_valkey() {
+    local host="${1:?host is required}"
+    local port="${2:?port is required}"
+    local retries="${3:-30}"
+    log "Waiting for valkey (${host}:${port}) to be ready..."
+    for ((i = 1; i <= retries; i += 1)); do
+        if valkey-cli -h "$host" -p "$port" ping 2>/dev/null | grep -q PONG; then
+            log "Valkey (${host}:${port}) is ready."
+            return 0
+        fi
+        sleep 2s
+    done
+    error "Valkey (${host}:${port}) did not become ready in time"
+}
+
 start_valkey_proxy() {
+    wait_for_valkey "${DRYCC_VALKEY_SENTINEL}" "${SENTINEL_PORT}"
     exec valkey-sentinel-proxy \
         --listen=:16379 \
         --master=drycc \

From ca2ac006e7ee9156bb9ebde8d579bc15fb976e49 Mon Sep 17 00:00:00 2001
From: duanhongyi <duanhongyi@doopai.com>
Date: Tue, 12 May 2026 10:09:20 +0800
Subject: [PATCH 21/21] docs(valkey): add builder db to usage

---
 README.md         |  1 +
 _test/test.sh     | 17 +++++++++++++++++
 rootfs/Dockerfile |  2 +-
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index ea5a0de..3f4fdb5 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,7 @@ Different components use different db, as follows:
 * `controller` use db 0
 * `passport` use db 1
 * `grafana` use db 2
+* `builder` use db 3
 * `manager` use db 10
 * `helmbroker` use db 11
 
diff --git a/_test/test.sh b/_test/test.sh
index 574b989..abf1d14 100755
--- a/_test/test.sh
+++ b/_test/test.sh
@@ -6,6 +6,7 @@ CONTAINER_PROXY_NAME="valkey-benchmark-proxy"
 CONTAINER_MASTER_NAME="valkey-benchmark-master"
 CONTAINER_SLAVE1_NAME="valkey-benchmark-slave1"
 CONTAINER_SLAVE2_NAME="valkey-benchmark-slave2"
+NETWORK_NAME="valkey-benchmark-net"
 DRYCC_VALKEY_PASSWORD=123456
 
 function clean_before_exit {
@@ -14,9 +15,20 @@ function clean_before_exit {
 }
 trap clean_before_exit EXIT
 
+ensure-network() {
+    # Use a dedicated bridge network so each container gets a unique IP and
+    # can reach its neighbours. The default rootless networking (pasta) makes
+    # every container share the host IP, which breaks master/replica/sentinel
+    # discovery because containers cannot connect to each other by that IP.
+    if ! podman network exists "$NETWORK_NAME" >/dev/null 2>&1; then
+        podman network create "$NETWORK_NAME" >/dev/null
+    fi
+}
+
 start-valkey-master() {
     podman run -d \
       --rm \
+      --network "$NETWORK_NAME" \
       --env "REDISCLI_AUTH=$DRYCC_VALKEY_PASSWORD" \
       --env "DRYCC_VALKEY_PASSWORD=$DRYCC_VALKEY_PASSWORD" \
       --name "$CONTAINER_MASTER_NAME" \
@@ -31,6 +43,7 @@ start-valkey-master() {
 start-valkey-slave1() {
     podman run -d \
       --rm \
+      --network "$NETWORK_NAME" \
       --env "REDISCLI_AUTH=$DRYCC_VALKEY_PASSWORD" \
       --env "DRYCC_VALKEY_PASSWORD=$DRYCC_VALKEY_PASSWORD" \
       --name "$CONTAINER_SLAVE1_NAME" \
@@ -45,6 +58,7 @@ start-valkey-slave1() {
 start-valkey-slave2() {
     podman run -d \
       --rm \
+      --network "$NETWORK_NAME" \
       --env "REDISCLI_AUTH=$DRYCC_VALKEY_PASSWORD" \
       --env "DRYCC_VALKEY_PASSWORD=$DRYCC_VALKEY_PASSWORD" \
       --name "$CONTAINER_SLAVE2_NAME" \
@@ -59,6 +73,7 @@ start-valkey-slave2() {
 start-valkey-proxy() {
     podman run -d \
       --rm \
+      --network "$NETWORK_NAME" \
       --env "REDISCLI_AUTH=$DRYCC_VALKEY_PASSWORD" \
       --env "DRYCC_VALKEY_PASSWORD=$DRYCC_VALKEY_PASSWORD" \
       --name "$CONTAINER_PROXY_NAME" \
@@ -74,10 +89,12 @@ clean-valkey() {
         podman kill "$CONTAINER_SLAVE1_NAME"
         podman kill "$CONTAINER_SLAVE2_NAME"
         podman kill "$CONTAINER_MASTER_NAME"
+        podman network rm -f "$NETWORK_NAME"
     } >>/dev/null 2>&1
 }
 
 clean-valkey
+ensure-network
 start-valkey-master
 start-valkey-slave1
 start-valkey-slave2
diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile
index 6068bee..3de14d7 100644
--- a/rootfs/Dockerfile
+++ b/rootfs/Dockerfile
@@ -4,7 +4,7 @@ FROM registry.drycc.cc/drycc/base:${CODENAME}
 ARG DRYCC_UID=1001 \
   DRYCC_GID=1001 \
   DRYCC_HOME_DIR=/data \
-  VALKEY_VERSION="9.0.0" \
+  VALKEY_VERSION="9.0.4" \
   VALKEY_SENTINEL_PROXY_VERSION="2.0.1" \
   REDIS_EXPORTER_VERSION="1.80.1"
 
