Skip to content

Commit

Permalink
Merge pull request #96 from ghsbhatia/fix-tls-san
Browse files Browse the repository at this point in the history
Fix tls-san handling in rke2 config
  • Loading branch information
adamacosta authored Nov 28, 2023
2 parents 1fe22df + aa6e197 commit 4206e41
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 4206e41

Please sign in to comment.