@@ -29,6 +29,16 @@ redis_acl_file_bak="/data/users.acl.bak"
2929retry_times=3
3030retry_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+
3242load_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
101111build_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
387397load_common_library
398+ init_redis_service_port
388399parse_redis_announce_addr " $CURRENT_POD_NAME "
389400build_redis_conf
390401start_redis_server
0 commit comments