forked from rancher/distros-test-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automation to assign a Elastic IP to a Cluster and perform a reboot test
Signed-off-by: est-suse <[email protected]>
- Loading branch information
est-suse
committed
Sep 19, 2023
1 parent
0b15ac1
commit 11c1261
Showing
10 changed files
with
323 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
# This script installs the first master, ensuring first master is installed | ||
# and ready before proceeding to install other nodes | ||
set -x | ||
echo "$@" | ||
|
||
create_lb=$1 | ||
public_ip=$2 | ||
server_flags=$3 | ||
|
||
hostname=$(hostname -f) | ||
mkdir -p /etc/rancher/rke2 | ||
cat << EOF >/etc/rancher/rke2/config.yaml | ||
write-kubeconfig-mode: "0644" | ||
tls-san: | ||
- ${create_lb} | ||
node-name: ${hostname} | ||
EOF | ||
|
||
if [ -n "$server_flags" ] && [[ "$server_flags" == *":"* ]] | ||
then | ||
echo "$server_flags" | ||
echo -e "$server_flags" >> /etc/rancher/rke2/config.yaml | ||
if [[ "$server_flags" != *"cloud-provider-name"* ]] | ||
then | ||
echo -e "node-external-ip: $public_ip" >> /etc/rancher/rke2/config.yaml | ||
fi | ||
cat /etc/rancher/rke2/config.yaml | ||
else | ||
echo -e "node-external-ip: $public_ip" >> /etc/rancher/rke2/config.yaml | ||
fi | ||
|
||
sudo systemctl restart rke2-server | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
# This script is used to join one or more nodes as agents | ||
set -x | ||
echo "$@" | ||
|
||
server_ip=$1 | ||
token=$2 | ||
public_ip=$3 | ||
worker_flags=$4 | ||
|
||
hostname=$(hostname -f) | ||
mkdir -p /etc/rancher/rke2 | ||
cat <<EOF >/etc/rancher/rke2/config.yaml | ||
server: https://${server_ip}:9345 | ||
token: "${token}" | ||
node-name: "${hostname}" | ||
EOF | ||
|
||
if [ -n "$worker_flags" ] && [[ "$worker_flags" == *":"* ]] | ||
then | ||
echo "$worker_flags" | ||
echo -e "$worker_flags" >> /etc/rancher/rke2/config.yaml | ||
if [[ "$worker_flags" != *"cloud-provider-name"* ]] | ||
then | ||
echo -e "node-external-ip: $public_ip" >> /etc/rancher/rke2/config.yaml | ||
fi | ||
cat /etc/rancher/rke2/config.yaml | ||
else | ||
echo -e "node-external-ip: $public_ip" >> /etc/rancher/rke2/config.yaml | ||
fi | ||
|
||
sudo systemctl restart rke2-agent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
# This script is used to join one or more nodes as masters to the first master | ||
set -x | ||
echo "$@" | ||
|
||
initial_node_ip=$1 | ||
token=$2 | ||
public_ip=$3 | ||
server_flags=$4 | ||
|
||
hostname=$(hostname -f) | ||
mkdir -p /etc/rancher/rke2 | ||
cat <<EOF >/etc/rancher/rke2/config.yaml | ||
write-kubeconfig-mode: "0644" | ||
tls-san: | ||
- ${initial_node_ip} | ||
server: https://${initial_node_ip}:9345 | ||
token: "${token}" | ||
node-name: "${hostname}" | ||
EOF | ||
|
||
if [ -n "$server_flags" ] && [[ "$server_flags" == *":"* ]] | ||
then | ||
echo "$server_flags" | ||
echo -e "$server_flags" >> /etc/rancher/rke2/config.yaml | ||
if [[ "$server_flags" != *"cloud-provider-name"* ]] | ||
then | ||
echo -e "node-external-ip: $public_ip" >> /etc/rancher/rke2/config.yaml | ||
fi | ||
cat /etc/rancher/rke2/config.yaml | ||
else | ||
echo -e "node-external-ip: $public_ip" >> /etc/rancher/rke2/config.yaml | ||
fi | ||
|
||
sudo systemctl restart --no-block rke2-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
#set -x | ||
echo "$@" | ||
type=$1 | ||
resource_name=$2 | ||
|
||
cd /tmp | ||
if [ "$type" == "stop" ]; then | ||
#output instances IDs | ||
|
||
aws ec2 describe-instances --filters "Name=tag:Name,Values=${resource_name}-server1,${resource_name}-server2" \ | ||
"Name=instance-state-name,Values=running" \ | ||
--output text --query 'Reservations[*].Instances[*].InstanceId' > /tmp/ids_server_1_2.txt | ||
|
||
aws ec2 describe-instances --filters "Name=tag:Name,Values=${resource_name}-server,${resource_name}-worker" \ | ||
"Name=instance-state-name,Values=running" \ | ||
--output text --query 'Reservations[*].Instances[*].InstanceId' > /tmp/ids_master_worker.txt | ||
|
||
cat /tmp/ids_server_1_2.txt /tmp/ids_master_worker.txt > /tmp/ids_all.txt | ||
fi | ||
|
||
if [ "$type" == "stop" ]; then | ||
file="ids_all.txt" | ||
elif [ "$type" == "start_s1_s2" ]; then | ||
file="ids_server_1_2.txt" | ||
elif [ "$type" == "start_master_worker" ]; then | ||
file="ids_master_worker.txt" | ||
fi | ||
|
||
i=1 | ||
while read line; do | ||
if [ "$type" == "stop" ]; then | ||
aws ec2 stop-instances --instance-ids $line | ||
elif [[ "$type" == "start_s1_s2" || "$type" == "start_master_worker" ]]; then | ||
aws ec2 start-instances --instance-ids $line | ||
sleep 60 | ||
fi | ||
i=$((i+1)) | ||
done < $file | ||
sleep 120 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters