-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bitnami/etcd] Stop relying on files for state #75906
base: main
Are you sure you want to change the base?
Conversation
- Remove prestop logic (no longer removing member when container stops) - Remove members not included in ETCD_INITIAL_CLUSTERS during startup - Stop storing member id on a separate file, member id is checked from etcd data dir instead - Stop reading member removal state off of disk, probe the cluster instead - Remove old member (with the same name) if exist before adding new member - If data dir is not empty, check if the member still belongs to the cluster. If not, remove data dir, remove member with the same name, and add new member - Remove env var ETCD_DISABLE_STORE_MEMBER_ID - Remove env var ETCD_DISABLE_PRESTOP Signed-off-by: Khoi Pham <[email protected]>
Signed-off-by: Khoi Pham <[email protected]>
Signed-off-by: Khoi Pham <[email protected]>
Signed-off-by: Khoi Pham <[email protected]>
Signed-off-by: Khoi Pham <[email protected]>
…s new Signed-off-by: Khoi Pham <[email protected]>
I'm planning to open a complementary PR in the charts repo. I will try to add more tests there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @pckhoi
Thanks so much for this amazing contribution! It'd definitely help on making the Bitnami etcd chart more stable.
I think the main concern/challenge with your changes would be providing a solution for users who may scale down the cluster via kubectl scale sts/etcd --replicas X
(or via some HorizontalPodAutoscaler that may also scale down the cluster without Helm's control via hooks). Correct me if I'm wrong but this use case won't be covered, right?
bitnami/etcd/3.5/debian-12/rootfs/opt/bitnami/scripts/etcd/preupgrade.sh
Outdated
Show resolved
Hide resolved
bitnami/etcd/3.5/debian-12/rootfs/opt/bitnami/scripts/etcd/preupgrade.sh
Outdated
Show resolved
Hide resolved
bitnami/etcd/3.5/debian-12/rootfs/opt/bitnami/scripts/libetcd.sh
Outdated
Show resolved
Hide resolved
@juan131 you're correct that the autoscaling use case isn't covered. People use Etcd for its consistency rather than for handling large, fluctuating traffic so I think autoscaling to handle large traffic is a niche use case. As for manual scaling, running |
Thanks for confirming so @pckhoi ! In that case, I'd add a warning at the "Upgrading" section alerting about what these changes imply (I mean, warning users to use exclusively Helm to scale the cluster): We could even add it in the chart NOTES: |
Sure, I will do that. |
Signed-off-by: Khoi Pham <[email protected]>
Signed-off-by: Khoi Pham <[email protected]>
Signed-off-by: Khoi Pham <[email protected]>
@juan131 I have updated https://github.com/bitnami/charts/tree/main/bitnami/etcd#upgrading. As for https://github.com/bitnami/charts/blob/main/bitnami/etcd/templates/NOTES.txt, I don't see anything that needs to be updated. |
bitnami/etcd/3.5/debian-12/rootfs/opt/bitnami/scripts/etcd/preupgrade.sh
Outdated
Show resolved
Hide resolved
bitnami/etcd/3.5/debian-12/rootfs/opt/bitnami/scripts/etcd/preupgrade.sh
Outdated
Show resolved
Hide resolved
bitnami/etcd/3.5/debian-12/rootfs/opt/bitnami/scripts/libetcd.sh
Outdated
Show resolved
Hide resolved
Signed-off-by: Khoi Pham <[email protected]>
Thanks! I have addressed all the suggestsions. |
@pckhoi I think this PR looks great now! Could you please check my comments in the associated chart PR? Thanks in advance. |
Signed-off-by: Khoi Pham <[email protected]>
bitnami/etcd/3.5/debian-12/rootfs/opt/bitnami/scripts/etcd/preupgrade.sh
Show resolved
Hide resolved
bitnami/etcd/3.5/debian-12/rootfs/opt/bitnami/scripts/etcd/preupgrade.sh
Outdated
Show resolved
Hide resolved
Signed-off-by: Khoi Pham <[email protected]>
am_i_root && start_command=("run_as_user" "$ETCD_DAEMON_USER" "${start_command[@]}") | ||
[[ -f "$ETCD_CONF_FILE" ]] && start_command+=("--config-file" "$ETCD_CONF_FILE") | ||
$start_command > >(tee -a "$tmp_file") 2>&1 & | ||
pid=$! | ||
debug "Started etcd in background with PID $pid" | ||
|
||
while read -r line; do | ||
echo "$line" # Stream the output | ||
if [[ "$line" =~ (established TCP streaming connection with remote peer|the member has been permanently removed from the cluster|ignored streaming request; ID mismatch|\"error\":\"cluster ID mismatch\") ]]; then | ||
kill "$pid" | ||
wait "$pid" 2>/dev/null | ||
debug "Stopped etcd" | ||
break | ||
fi | ||
done < <(tail -f "$tmp_file") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been doing more tests today and we'll have to change this block. This always throws etcd start logs to stdout regardless BITNAMI_DEBUG
is set or not. Alternative:
am_i_root && start_command=("run_as_user" "$ETCD_DAEMON_USER" "${start_command[@]}") | |
[[ -f "$ETCD_CONF_FILE" ]] && start_command+=("--config-file" "$ETCD_CONF_FILE") | |
$start_command > >(tee -a "$tmp_file") 2>&1 & | |
pid=$! | |
debug "Started etcd in background with PID $pid" | |
while read -r line; do | |
echo "$line" # Stream the output | |
if [[ "$line" =~ (established TCP streaming connection with remote peer|the member has been permanently removed from the cluster|ignored streaming request; ID mismatch|\"error\":\"cluster ID mismatch\") ]]; then | |
kill "$pid" | |
wait "$pid" 2>/dev/null | |
debug "Stopped etcd" | |
break | |
fi | |
done < <(tail -f "$tmp_file") | |
am_i_root && start_command=("run_as_user" "$ETCD_DAEMON_USER" "${start_command[@]}") | |
[[ -f "$ETCD_CONF_FILE" ]] && start_command+=("--config-file" "$ETCD_CONF_FILE") | |
"${start_command[@]}" > "$tmp_file" 2>&1 & | |
while read -r line; do | |
debug_execute echo "$line" | |
if [[ "$line" =~ (established TCP streaming connection with remote peer|the member has been permanently removed from the cluster|ignored streaming request; ID mismatch|\"error\":\"cluster ID mismatch\") ]]; then | |
etcd_stop | |
debug "Stopped etcd" | |
break | |
fi | |
done < <(tail -f "$tmp_file") |
By the way, it's not necessary to save the PID, you can use etcd_stop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
|
||
expected="$(echo $ETCD_INITIAL_CLUSTER | tr -s ',' '\n' | awk -F= '{print $1}')" | ||
info "Expected cluster members are: $(echo "$expected" | tr -s '\n' ',' | sed 's/,$//g')" | ||
read -r -a obsolete_members <<<"$(comm -23 <(echo "$current" | awk -F: '{print $1}' | sort) <(echo "$expected" | sort))" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small fix:
read -r -a obsolete_members <<<"$(comm -23 <(echo "$current" | awk -F: '{print $1}' | sort) <(echo "$expected" | sort))" | |
read -r -a obsolete_members <<<"$(comm -23 <(echo "$current" | awk -F: '{print $1}' | sort) <(echo "$expected" | sort) | tr -s '\n' ' ')" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems to break the script for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, something else is breaking. Let me investigate more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What problems are you experiencing? It works for me
Without this change only one member is removed given the obsolete_members
wasn't an array but a string with the 1st obsolete member to remove, so when I did a test scaling down from 5 to 3 replicas it only removed one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, your suggestion works. I just had to fix the loop as well. Everything should work now.
Signed-off-by: Khoi Pham <[email protected]>
Description of the change
The current etcd container and chart have a few major problems:
replicas
update then the next time the pod starts, it will not be able to start from the existing data dir which means it must throw away the data dir and start from scratch.etcdctl member update
for unclear reasons when the data dir is not empty and there is a member IDETCD_INITIAL_CLUSTER_STATE
to know whether the cluster is new which could be inaccurateThis PR add the following changes:
preupgrade.sh
which should be run in a Helm pre-upgrade hook. When the cluster is scaled down, it detects and removes obsolete members withetcdctl member remove
.prestop.sh
member_id
file. Instead, the remote member ID is read from the cluster withetcdctl member list
, and the local member ID is checked for conflict during startup.member_removal.log
. Check withetcdctl member list
instead.ETCD_DISABLE_STORE_MEMBER_ID
ETCD_DISABLE_PRESTOP
ETCD_INITIAL_CLUSTER_STATE
becomes read-onlyBenefits
etcdctl member remove
command tends to be executed against a healthy clusterPossible drawbacks
Applicable issues
Additional information
Related changes in the Helm chart: bitnami/charts#31161 and bitnami/charts#31164