Skip to content

Commit

Permalink
Update rke2-init.sh
Browse files Browse the repository at this point in the history
fix tls-san handling in rke2 config
  • Loading branch information
ghsbhatia authored Nov 22, 2023
1 parent 1fe22df commit aa6e197
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions modules/userdata/files/rke2-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ append_config() {
echo "$1" >> "/etc/rancher/rke2/config.yaml"
}

append_config_san() {
grep "^tls-san:$" /etc/rancher/rke2/config.yaml > /dev/null
if [ $? -eq 0 ]; then
sed -i "/^tls-san:$/a \ \ - ${server_url}" /etc/rancher/rke2/config.yaml
return
fi
echo "tls-san:" >> /etc/rancher/rke2/config.yaml
echo " - ${server_url}" >> /etc/rancher/rke2/config.yaml
}

# The most simple "leader election" you've ever seen in your life
elect_leader() {
# Fetch other running instances in ASG
Expand Down Expand Up @@ -168,10 +178,7 @@ upload() {
# Initialize server
identify

cat <<EOF >> "/etc/rancher/rke2/config.yaml"
tls-san:
- ${server_url}
EOF
append_config_san

if [ $SERVER_TYPE = "server" ]; then # additional server joining an existing cluster
append_config 'server: https://${server_url}:9345'
Expand Down

0 comments on commit aa6e197

Please sign in to comment.