Skip to content

Commit c8333e3

Browse files
committed
improve
1 parent 3979ea9 commit c8333e3

18 files changed

+41
-119
lines changed

addons/redis/scripts/redis-account.sh

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
set -e
4-
service_port=$SERVICE_PORT
4+
service_port=${INNER_SERVICE_PORT:-6379}
55

66
function do_acl_command() {
77
local hosts=$1
@@ -47,11 +47,6 @@ function env_pre_check() {
4747
exit 1
4848
fi
4949

50-
if [ -z "$SERVICE_PORT" ]; then
51-
echo "SERVICE_PORT is empty, skip ACL operation"
52-
exit 1
53-
fi
54-
5550
if [ -z "$REDIS_DEFAULT_USER" ]; then
5651
echo "REDIS_DEFAULT_USER is empty, skip ACL operation"
5752
exit 1
@@ -82,10 +77,6 @@ function env_pre_check() {
8277
echo "CLUSTER_DOMAIN is empty, skip ACL operation"
8378
exit 0
8479
fi
85-
86-
if [ "$TLS_ENABLED" == "true" ]; then
87-
service_port=$NON_TLS_SERVICE_PORT
88-
fi
8980

9081
}
9182

addons/redis/scripts/redis-ping.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ load_common_library() {
2828

2929
check_redis_ok() {
3030
unset_xtrace_when_ut_mode_false
31-
service_port=$SERVICE_PORT
32-
if [ "$TLS_ENABLED" == "true" ]; then
33-
service_port=$NON_TLS_SERVICE_PORT
34-
fi
31+
service_port=${INNER_SERVICE_PORT:-6379}
3532
if ! is_empty "$REDIS_DEFAULT_PASSWORD"; then
3633
cmd="redis-cli -h localhost -p $service_port -a $REDIS_DEFAULT_PASSWORD ping"
3734
else

addons/redis/scripts/redis-pre-stop.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ load_common_library() {
2727
}
2828

2929
acl_save_before_stop() {
30-
service_port=$SERVICE_PORT
31-
if [ "$TLS_ENABLED" == "true" ]; then
32-
service_port=$NON_TLS_SERVICE_PORT
33-
fi
30+
service_port=${INNER_SERVICE_PORT:-6379}
3431
if ! is_empty "$REDIS_DEFAULT_PASSWORD"; then
3532
acl_save_command="redis-cli -h localhost -p $service_port -a $REDIS_DEFAULT_PASSWORD acl save"
3633
logging_mask_acl_save_command="${acl_save_command/$REDIS_DEFAULT_PASSWORD/********}"

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test || __() {
2626

2727
redis_announce_host_value=""
2828
redis_announce_port_value=""
29-
redis_default_service_port=6379
29+
redis_default_service_port=${INNER_SERVICE_PORT:-6379}
3030
if [ -f /data/.fixed_pod_ip_enabled ]; then
3131
# if the file /data/.fixed_pod_ip_enabled exists, it means that the redis pod is running in fixed pod ip mode.
3232
FIXED_POD_IP_ENABLED=true
@@ -41,15 +41,6 @@ load_common_library() {
4141
source "${common_library_file}"
4242
}
4343

44-
init_redis_service_port() {
45-
if env_exist SERVICE_PORT; then
46-
redis_default_service_port=$SERVICE_PORT
47-
fi
48-
if [ "$TLS_ENABLED" == "true" ]; then
49-
redis_default_service_port=$NON_TLS_SERVICE_PORT
50-
fi
51-
}
52-
5344
extract_lb_host_by_svc_name() {
5445
local svc_name="$1"
5546
for lb_composed_name in $(echo "$REDIS_LB_ADVERTISED_HOST" | tr ',' '\n' ); do
@@ -223,12 +214,9 @@ get_master_addr_by_name(){
223214
register_to_sentinel() {
224215
local sentinel_host=$1
225216
local master_name=$2
226-
local sentinel_port=${SENTINEL_SERVICE_PORT:-26379}
217+
local sentinel_port=${SENTINEL_INNER_SERVICE_PORT:-26379}
227218
local redis_primary_host=$3
228219
local redis_primary_port=$4
229-
if [ -n "$SENTINEL_NON_TLS_SERVICE_PORT" ]; then
230-
sentinel_port=$SENTINEL_NON_TLS_SERVICE_PORT
231-
fi
232220

233221
unset_xtrace_when_ut_mode_false
234222
# Check connectivity to sentinel host and redis primary host
@@ -316,7 +304,6 @@ register_to_sentinel_wrapper() {
316304
# get minimum lexicographical order pod name as default primary node (the same logic as redis initialize primary node selection)
317305
redis_default_primary_pod_name=$(min_lexicographical_order_pod "$REDIS_POD_NAME_LIST")
318306
redis_default_primary_pod_fqdn=$(get_target_pod_fqdn_from_pod_fqdn_vars "$REDIS_POD_FQDN_LIST" "$redis_default_primary_pod_name")
319-
init_redis_service_port
320307
parse_redis_primary_announce_addr "$redis_default_primary_pod_name"
321308
if is_empty "$CUSTOM_SENTINEL_MASTER_NAME"; then
322309
master_name=$REDIS_COMPONENT_NAME

addons/redis/scripts/redis-sentinel-member-join.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ recover_registered_redis_servers() {
7777
echo "Error: Required environment variable SENTINEL_POD_FQDN_LIST is not set."
7878
return 1
7979
fi
80-
sentinel_service_port=$SENTINEL_SERVICE_PORT
81-
if [ "$TLS_ENABLED" = "true" ]; then
82-
sentinel_service_port=$SENTINEL_NON_TLS_SERVICE_PORT
83-
fi
80+
sentinel_service_port=${SENTINEL_INNER_SERVICE_PORT:-26379}
8481

8582
output=""
8683
local max_retries=5

addons/redis/scripts/redis-sentinel-member-leave.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ load_common_library() {
2626
source "${common_library_file}"
2727
}
2828

29-
declare -g redis_default_service_port=${SENTINEL_SERVICE_PORT:-26379}
30-
if [ "$TLS_ENABLED" = "true" ]; then
31-
redis_default_service_port=$SENTINEL_NON_TLS_SERVICE_PORT
32-
fi
29+
declare -g redis_default_service_port=${SENTINEL_INNER_SERVICE_PORT:-26379}
3330
declare -A master_slave_counts
3431
declare -g sentinel_leave_member_name
3532
declare -g sentinel_leave_member_fqdn

addons/redis/scripts/redis-sentinel-ping.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ load_common_library() {
2828

2929
check_redis_sentinel_ok() {
3030
unset_xtrace_when_ut_mode_false
31-
sentinel_service_port=$SENTINEL_SERVICE_PORT
32-
if [ "$TLS_ENABLED" = "true" ]; then
33-
sentinel_service_port=$SENTINEL_NON_TLS_SERVICE_PORT
34-
fi
35-
31+
sentinel_service_port=${SENTINEL_INNER_SERVICE_PORT:-26379}
3632
if ! is_empty "$SENTINEL_PASSWORD"; then
3733
cmd="redis-cli -h localhost -p $sentinel_service_port -a $SENTINEL_PASSWORD ping"
3834
else

addons/redis/scripts/redis-sentinel-post-start.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ load_common_library() {
2929
acl_set_user_for_redis_sentinel() {
3030
# set default user password and replication user password
3131
if [ -n "$SENTINEL_PASSWORD" ]; then
32-
sentinel_service_port=$SENTINEL_SERVICE_PORT
33-
if [ "$TLS_ENABLED" = "true" ]; then
34-
sentinel_service_port=$SENTINEL_NON_TLS_SERVICE_PORT
35-
fi
32+
sentinel_service_port=${SENTINEL_INNER_SERVICE_PORT:-26379}
3633
until redis-cli -h localhost -p $sentinel_service_port -a $SENTINEL_PASSWORD ping; do sleep 1; done
3734
redis-cli -h localhost -p $sentinel_service_port -a $SENTINEL_PASSWORD ACL SETUSER $SENTINEL_USER ON \>$SENTINEL_PASSWORD allchannels +@all
3835
redis-cli -h localhost -p $sentinel_service_port -a $SENTINEL_PASSWORD ACL SAVE

addons/redis/scripts/redis-sentinel-start-v2.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,7 @@ build_redis_sentinel_conf() {
149149
exit 1
150150
fi
151151

152-
sentinel_port=26379
153-
if env_exist SENTINEL_SERVICE_PORT; then
154-
sentinel_port=$SENTINEL_SERVICE_PORT
155-
fi
152+
sentinel_port=${SENTINEL_SERVICE_PORT:-26379}
156153
# build announce ip and port according to whether the announce addr is enabled
157154
if ! is_empty "$redis_sentinel_announce_host_value" && ! is_empty "$redis_sentinel_announce_port_value"; then
158155
echo "redis sentinel use nodeport $redis_sentinel_announce_host_value:$redis_sentinel_announce_port_value to announce"

addons/redis/scripts/redis-start.sh

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,7 @@ redis_acl_file="/data/users.acl"
2828
redis_acl_file_bak="/data/users.acl.bak"
2929
retry_times=3
3030
retry_delay_second=2
31-
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-
}
31+
service_port=${INNER_SERVICE_PORT:-6379}
4132

4233
load_common_library() {
4334
# the common.sh scripts is mounted to the same path which is defined in the cmpd.spec.scripts
@@ -207,10 +198,7 @@ build_sentinel_get_master_addr_by_name_command() {
207198
local sentinel_pod_fqdn="$1"
208199
local timeout_value=5
209200
# 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
201+
sentinel_service_port=${SENTINEL_INNER_SERVICE_PORT:-26379}
214202
if is_empty "$SENTINEL_PASSWORD"; then
215203
echo "timeout $timeout_value redis-cli -h $sentinel_pod_fqdn -p $sentinel_service_port sentinel get-master-addr-by-name $REDIS_COMPONENT_NAME"
216204
else
@@ -395,7 +383,6 @@ ${__SOURCED__:+false} : || return 0
395383

396384
# main
397385
load_common_library
398-
init_redis_service_port
399386
parse_redis_announce_addr "$CURRENT_POD_NAME"
400387
build_redis_conf
401388
start_redis_server

0 commit comments

Comments
 (0)