Skip to content

Commit

Permalink
chore: redis sentinel remove duplicate known replica in nodeport mode (
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Rookie authored Nov 28, 2024
1 parent 3f4e468 commit a3fcd6b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions addons/redis/scripts/redis-sentinel-start-v2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ reset_redis_sentinel_conf() {
set_xtrace_when_ut_mode_false
sed "/port $sentinel_port/d" $redis_sentinel_real_conf > $redis_sentinel_real_conf_bak && mv $redis_sentinel_real_conf_bak $redis_sentinel_real_conf
fi

# hack for redis sentinel when nodeport is enabled, remove known-replica line which has the same nodeport port with master
if [ -n "$REDIS_SENTINEL_ADVERTISED_PORT" ] && [ -n "$REDIS_SENTINEL_ADVERTISED_SVC_NAME" ]; then
temp_file=$(mktemp)
grep "^sentinel monitor" /data/sentinel/redis-sentinel.conf > "$temp_file"
while read -r line; do
if [[ $line =~ ^sentinel[[:space:]]+monitor[[:space:]]+([^[:space:]]+)[[:space:]]+[^[:space:]]+[[:space:]]+([^[:space:]]+) ]]; then
master_name="${BASH_REMATCH[1]}"
master_port="${BASH_REMATCH[2]}"
sed -i "/^sentinel known-replica ${master_name} .* ${master_port}$/d" /data/sentinel/redis-sentinel.conf
fi
done < "$temp_file"
rm -f "$temp_file"
fi
}

build_redis_sentinel_conf() {
Expand Down
18 changes: 18 additions & 0 deletions addons/redis/templates/cmpd-redis-sentinel-7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ spec:
compDef: {{ include "redisSentinel7.cmpdName" . }}
optional: false
podFQDNs: Required
## the redis sentinel advertised service port list for each pod, the value format is "pod1Svc:nodeport1,pod2Svc:nodeport2,..."
- name: REDIS_SENTINEL_ADVERTISED_PORT
valueFrom:
serviceVarRef:
compDef: {{ include "redisSentinel7.cmpdName" . }}
name: sentinel-advertised
optional: true
port:
name: sentinel-advertised
option: Required
## the redis sentinel advertised service name list for each pod, the value format is "pod1Svc,pod2Svc,..."
- name: REDIS_SENTINEL_ADVERTISED_SVC_NAME
valueFrom:
serviceVarRef:
compDef: {{ include "redisSentinel7.cmpdName" . }}
name: sentinel-advertised
optional: true
host: Required
## the username of redis for redis sentinel connection which is only used to recover redis servers when scale-out redis sentinel.
- name: REDIS_SENTINEL_USER
value: "kbreplicator-sentinel"
Expand Down

0 comments on commit a3fcd6b

Please sign in to comment.