Skip to content

Commit 394680e

Browse files
committed
fix tls bug
1 parent efe9cee commit 394680e

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

addons/redis/scripts/redis-register-to-sentinel.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ register_to_sentinel() {
226226
local sentinel_port=${SENTINEL_SERVICE_PORT:-26379}
227227
local redis_primary_host=$3
228228
local redis_primary_port=$4
229+
if [ -n "$SENTINEL_NON_TLS_SERVICE_PORT" ]; then
230+
sentinel_port=$SENTINEL_NON_TLS_SERVICE_PORT
231+
fi
229232

230233
unset_xtrace_when_ut_mode_false
231234
# Check connectivity to sentinel host and redis primary host

addons/redis/scripts/redis-start.sh

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ redis_acl_file_bak="/data/users.acl.bak"
2929
retry_times=3
3030
retry_delay_second=2
3131

32+
function init_redis_service_port() {
33+
service_port=6379
34+
if env_exist SERVICE_PORT; then
35+
service_port=$SERVICE_PORT
36+
fi
37+
if [ "$TLS_ENABLED" == "true" ]; then
38+
service_port=$NON_TLS_SERVICE_PORT
39+
fi
40+
}
41+
3242
load_common_library() {
3343
# the common.sh scripts is mounted to the same path which is defined in the cmpd.spec.scripts
3444
common_library_file="/scripts/common.sh"
@@ -99,14 +109,10 @@ build_announce_ip_and_port() {
99109
}
100110

101111
build_redis_service_port() {
102-
service_port=6379
103-
if env_exist SERVICE_PORT; then
104-
service_port=$SERVICE_PORT
105-
fi
106112
# TODO: tls announce port for nodePort Service
107113
if [ "$TLS_ENABLED" == "true" ]; then
108114
echo "port ${NON_TLS_SERVICE_PORT}" >> $redis_real_conf
109-
echo "tls-port $service_port" >> $redis_real_conf
115+
echo "tls-port $SERVICE_PORT" >> $redis_real_conf
110116
else
111117
echo "port $service_port" >> $redis_real_conf
112118
fi
@@ -201,10 +207,14 @@ build_sentinel_get_master_addr_by_name_command() {
201207
local sentinel_pod_fqdn="$1"
202208
local timeout_value=5
203209
# TODO: replace $SENTINEL_SERVICE_PORT with each sentinel pod's port when sentinel service port is not the same, for example in HostNetwork mode
210+
sentinel_service_port=$SENTINEL_SERVICE_PORT
211+
if [ "$TLS_ENABLED" == "true" ]; then
212+
sentinel_service_port=$SENTINEL_NON_TLS_SERVICE_PORT
213+
fi
204214
if is_empty "$SENTINEL_PASSWORD"; then
205-
echo "timeout $timeout_value redis-cli -h $sentinel_pod_fqdn -p $SENTINEL_SERVICE_PORT sentinel get-master-addr-by-name $REDIS_COMPONENT_NAME"
215+
echo "timeout $timeout_value redis-cli -h $sentinel_pod_fqdn -p $sentinel_service_port sentinel get-master-addr-by-name $REDIS_COMPONENT_NAME"
206216
else
207-
echo "timeout $timeout_value redis-cli -h $sentinel_pod_fqdn -p $SENTINEL_SERVICE_PORT -a $SENTINEL_PASSWORD sentinel get-master-addr-by-name $REDIS_COMPONENT_NAME"
217+
echo "timeout $timeout_value redis-cli -h $sentinel_pod_fqdn -p $sentinel_service_port -a $SENTINEL_PASSWORD sentinel get-master-addr-by-name $REDIS_COMPONENT_NAME"
208218
fi
209219
}
210220

@@ -385,6 +395,7 @@ ${__SOURCED__:+false} : || return 0
385395

386396
# main
387397
load_common_library
398+
init_redis_service_port
388399
parse_redis_announce_addr "$CURRENT_POD_NAME"
389400
build_redis_conf
390401
start_redis_server

addons/redis/templates/cmpd-redis.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,17 @@ spec:
316316
name: redis-sentinel
317317
option: Required
318318
expression: {{ `{{if index . "SENTINEL_SERVICE_PORT"}}{{.SENTINEL_SERVICE_PORT}}{{else}}26379{{end}}` | toYaml }}
319+
- name: SENTINEL_NON_TLS_SERVICE_PORT
320+
valueFrom:
321+
hostNetworkVarRef:
322+
compDef: {{ printf "%s-%s" .sentinelComponentDef $.Chart.Version }}
323+
optional: true
324+
container:
325+
name: redis-sentinel
326+
port:
327+
name: non-tls
328+
option: Required
329+
expression: {{ `{{if index . "SENTINEL_NON_TLS_SERVICE_PORT"}}{{.SENTINEL_NON_TLS_SERVICE_PORT}}{{else}}26380{{end}}` | toYaml }}
319330
- name: PHY_MEMORY
320331
valueFrom:
321332
resourceVarRef:
@@ -350,8 +361,6 @@ spec:
350361
container: redis
351362
command:
352363
- /tools/dbctl
353-
- --config-path
354-
- /tools/config/dbctl/components
355364
- redis
356365
- getrole
357366
postProvision:
@@ -411,7 +420,6 @@ spec:
411420
- cp
412421
- -r
413422
- /bin/dbctl
414-
- /config
415423
- /tools/
416424
imagePullPolicy: {{ default "IfNotPresent" $.Values.dbctlImage.pullPolicy }}
417425
volumeMounts:

addons/redis/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ dbctlImage:
128128
registry:
129129
repository: apecloud/dbctl
130130
pullPolicy: IfNotPresent
131-
tag: 0.1.8
131+
tag: 0.2.1
132132

133133
redisTwemproxyImage:
134134
# if the value of redisTwemproxyImage.registry is not specified using `--set`, it will be set to the value of 'image.registry' by default

0 commit comments

Comments
 (0)