@@ -35,9 +35,8 @@ sleep_random_second_when_ut_mode_false() {
3535 fi
3636}
3737
38- # usage: parse_host_ip_from_built_in_envs <pod_name>
39- # $KB_CLUSTER_COMPONENT_POD_NAME_LIST and $KB_CLUSTER_COMPONENT_POD_HOST_IP_LIST are built-in envs in KubeBlocks postProvision lifecycle action.
40- # TODO: the built-in envs will be removed in the future.
38+ # usage: parse_host_ip_from_built_in_envs <pod_name> <pod_name_list> <pod_host_ip_list>
39+ # Kept for scripts that pass an explicit pod-name/IP mapping.
4140parse_host_ip_from_built_in_envs () {
4241 local given_pod_name=" $1 "
4342 local all_pod_name_list=" $2 "
@@ -454,24 +453,17 @@ check_slots_covered() {
454453
455454# check if the cluster has been initialized
456455check_cluster_initialized () {
457- local cluster_pod_ip_list=" $1 "
458- local cluster_pod_name_list=" $2 "
459- if is_empty " $cluster_pod_ip_list " || is_empty " $cluster_pod_name_list " ; then
460- echo " Error: Required environment variable cluster_pod_ip_list or cluster_pod_name_list is not set." >&2
456+ local cluster_pod_fqdn_list=" $1 "
457+ if is_empty " $cluster_pod_fqdn_list " ; then
458+ echo " Error: Required environment variable cluster_pod_fqdn_list is not set." >&2
461459 return 1
462460 fi
463461
464- local pod_ip
465462 local service_port
466- for pod_name in $( echo " $cluster_pod_name_list " | tr ' ,' ' ' ) ; do
467- pod_ip=$( parse_host_ip_from_built_in_envs " $pod_name " " $cluster_pod_name_list " " $cluster_pod_ip_list " )
468- if is_empty " $pod_ip " ; then
469- echo " Failed to get the host ip of the pod $pod_name in check_cluster_initialized"
470- continue
471- fi
472-
463+ for pod_fqdn in $( echo " $cluster_pod_fqdn_list " | tr ' ,' ' ' ) ; do
464+ pod_name=${pod_fqdn%% .* }
473465 service_port=$( get_pod_service_port_by_network_mode " ${pod_name} " )
474- cluster_info=$( get_cluster_info_with_retry " $pod_ip " " $service_port " )
466+ cluster_info=$( get_cluster_info_with_retry " $pod_fqdn " " $service_port " )
475467 status=$?
476468 if [ $status -ne 0 ]; then
477469 echo " Failed to get cluster info in check_cluster_initialized" >&2
@@ -487,6 +479,36 @@ check_cluster_initialized() {
487479 return 1
488480}
489481
482+ redis_config_get () {
483+ local host=$1
484+ local port=$2
485+ local password=$3
486+ local command=$4
487+
488+ local output
489+ unset_xtrace_when_ut_mode_false
490+ if ! is_empty " $password " ; then
491+ output=$( redis-cli $REDIS_CLI_TLS_CMD -h " $host " -p " $port " -a " $password " $command )
492+ else
493+ output=$( redis-cli $REDIS_CLI_TLS_CMD -h " $host " -p " $port " $command )
494+ fi
495+ local status=$?
496+ set_xtrace_when_ut_mode_false
497+
498+ if [[ $status -ne 0 ]]; then
499+ echo " Command failed with status $status ." >&2
500+ return 1
501+ fi
502+
503+ if [[ -z " $output " ]]; then
504+ echo " Command returned no output." >&2
505+ return 1
506+ fi
507+
508+ echo " $output "
509+ return 0
510+ }
511+
490512build_redis_cluster_create_command () {
491513 local primary_nodes=" $1 "
492514 unset_xtrace_when_ut_mode_false
@@ -740,4 +762,4 @@ check_redis_role() {
740762 else
741763 echo " unknown"
742764 fi
743- }
765+ }
0 commit comments