Fix ETCD_ACTIVE_ENDPOINTS environment variable not found issue (#49)

* FIx ETCD_ACTIVE_ENDPOINTS environment variable not found issue

Signed-off-by: Arlo Liu <arlo@xfers.com>

* Fix missing cluster_size variable

Signed-off-by: Arlo Liu <arlo@xfers.com>

* Test if ETCD_ACTIVE_ENDPOINTS unbound is set properly

Signed-off-by: Arlo Liu <arlo@xfers.com>

* Use is_empty_value function to align coding style

Signed-off-by: Arlo Liu <arlo@xfers.com>

* Remove un-necessary letter

Signed-off-by: Arlo Liu <arlo@xfers.com>
This commit is contained in:
Arlo Liu
2022-07-14 17:57:16 +08:00
committed by Bitnami Containers
parent 72b5fb30a2
commit 8a191f5886
3 changed files with 75 additions and 12 deletions

View File

@@ -392,16 +392,15 @@ is_new_etcd_cluster() {
}
########################
# Checks if there are enough active members, will also set ETCD_ACTIVE_ENDPOINTS
# Setup ETCD_ACTIVE_ENDPOINTS environment variable, will return the number of active endpoints
# Globals:
# ETCD_*
# Arguments:
# None
# Returns:
# Boolean
# List of Numbers (active_endpoints, cluster_size)
########################
is_healthy_etcd_cluster() {
local return_value=0
setup_etcd_active_endpoints() {
local active_endpoints=0
local -a extra_flags active_endpoints_array
local -a endpoints_array=()
@@ -425,6 +424,22 @@ is_healthy_etcd_cluster() {
ETCD_ACTIVE_ENDPOINTS=$(echo "${active_endpoints_array[*]}" | tr ' ' ',')
export ETCD_ACTIVE_ENDPOINTS
fi
echo "${active_endpoints} ${cluster_size}"
}
########################
# Checks if there are enough active members, will also set ETCD_ACTIVE_ENDPOINTS
# Globals:
# ETCD_*
# Arguments:
# None
# Returns:
# Boolean
########################
is_healthy_etcd_cluster() {
local return_value=0
local active_endpoints cluster_size
read -r active_endpoints cluster_size <<< $(setup_etcd_active_endpoints)
if is_boolean_yes "$ETCD_DISASTER_RECOVERY"; then
if [[ -f "/snapshots/.disaster_recovery" ]]; then
@@ -748,6 +763,12 @@ get_member_id() {
fi
local ret
local -a extra_flags
local etcd_active_endpoints=${ETCD_ACTIVE_ENDPOINTS:-}
if is_empty_value "${etcd_active_endpoints}"; then
setup_etcd_active_endpoints >/dev/null 2>&1
fi
read -r -a extra_flags <<<"$(etcdctl_auth_flags)"
extra_flags+=("--endpoints=${ETCD_ACTIVE_ENDPOINTS}")
ret=$(etcdctl "${extra_flags[@]}" member list | grep -w "$ETCD_INITIAL_ADVERTISE_PEER_URLS" | awk -F "," '{ print $1 }')

View File

@@ -392,16 +392,15 @@ is_new_etcd_cluster() {
}
########################
# Checks if there are enough active members, will also set ETCD_ACTIVE_ENDPOINTS
# Setup ETCD_ACTIVE_ENDPOINTS environment variable, will return the number of active endpoints
# Globals:
# ETCD_*
# Arguments:
# None
# Returns:
# Boolean
# List of Numbers (active_endpoints, cluster_size)
########################
is_healthy_etcd_cluster() {
local return_value=0
setup_etcd_active_endpoints() {
local active_endpoints=0
local -a extra_flags active_endpoints_array
local -a endpoints_array=()
@@ -425,6 +424,22 @@ is_healthy_etcd_cluster() {
ETCD_ACTIVE_ENDPOINTS=$(echo "${active_endpoints_array[*]}" | tr ' ' ',')
export ETCD_ACTIVE_ENDPOINTS
fi
echo "${active_endpoints} ${cluster_size}"
}
########################
# Checks if there are enough active members, will also set ETCD_ACTIVE_ENDPOINTS
# Globals:
# ETCD_*
# Arguments:
# None
# Returns:
# Boolean
########################
is_healthy_etcd_cluster() {
local return_value=0
local active_endpoints cluster_size
read -r active_endpoints cluster_size <<< $(setup_etcd_active_endpoints)
if is_boolean_yes "$ETCD_DISASTER_RECOVERY"; then
if [[ -f "/snapshots/.disaster_recovery" ]]; then
@@ -748,6 +763,12 @@ get_member_id() {
fi
local ret
local -a extra_flags
local etcd_active_endpoints=${ETCD_ACTIVE_ENDPOINTS:-}
if is_empty_value "${etcd_active_endpoints}"; then
setup_etcd_active_endpoints >/dev/null 2>&1
fi
read -r -a extra_flags <<<"$(etcdctl_auth_flags)"
extra_flags+=("--endpoints=${ETCD_ACTIVE_ENDPOINTS}")
ret=$(etcdctl "${extra_flags[@]}" member list | grep -w "$ETCD_INITIAL_ADVERTISE_PEER_URLS" | awk -F "," '{ print $1 }')

View File

@@ -392,16 +392,15 @@ is_new_etcd_cluster() {
}
########################
# Checks if there are enough active members, will also set ETCD_ACTIVE_ENDPOINTS
# Setup ETCD_ACTIVE_ENDPOINTS environment variable, will return the number of active endpoints
# Globals:
# ETCD_*
# Arguments:
# None
# Returns:
# Boolean
# List of Numbers (active_endpoints, cluster_size)
########################
is_healthy_etcd_cluster() {
local return_value=0
setup_etcd_active_endpoints() {
local active_endpoints=0
local -a extra_flags active_endpoints_array
local -a endpoints_array=()
@@ -425,6 +424,22 @@ is_healthy_etcd_cluster() {
ETCD_ACTIVE_ENDPOINTS=$(echo "${active_endpoints_array[*]}" | tr ' ' ',')
export ETCD_ACTIVE_ENDPOINTS
fi
echo "${active_endpoints} ${cluster_size}"
}
########################
# Checks if there are enough active members, will also set ETCD_ACTIVE_ENDPOINTS
# Globals:
# ETCD_*
# Arguments:
# None
# Returns:
# Boolean
########################
is_healthy_etcd_cluster() {
local return_value=0
local active_endpoints cluster_size
read -r active_endpoints cluster_size <<< $(setup_etcd_active_endpoints)
if is_boolean_yes "$ETCD_DISASTER_RECOVERY"; then
if [[ -f "/snapshots/.disaster_recovery" ]]; then
@@ -786,6 +801,12 @@ get_member_id() {
fi
local ret
local -a extra_flags
local etcd_active_endpoints=${ETCD_ACTIVE_ENDPOINTS:-}
if is_empty_value "${etcd_active_endpoints}"; then
setup_etcd_active_endpoints >/dev/null 2>&1
fi
read -r -a extra_flags <<<"$(etcdctl_auth_flags)"
extra_flags+=("--endpoints=${ETCD_ACTIVE_ENDPOINTS}")
ret=$(etcdctl "${extra_flags[@]}" member list | grep -w "$ETCD_INITIAL_ADVERTISE_PEER_URLS" | awk -F "," '{ print $1 }')