Skip to content

Commit 4206e41

Browse files
authored
Merge pull request #96 from ghsbhatia/fix-tls-san
Fix tls-san handling in rke2 config
2 parents 1fe22df + aa6e197 commit 4206e41

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

modules/userdata/files/rke2-init.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ append_config() {
3636
echo "$1" >> "/etc/rancher/rke2/config.yaml"
3737
}
3838

39+
append_config_san() {
40+
grep "^tls-san:$" /etc/rancher/rke2/config.yaml > /dev/null
41+
if [ $? -eq 0 ]; then
42+
sed -i "/^tls-san:$/a \ \ - ${server_url}" /etc/rancher/rke2/config.yaml
43+
return
44+
fi
45+
echo "tls-san:" >> /etc/rancher/rke2/config.yaml
46+
echo " - ${server_url}" >> /etc/rancher/rke2/config.yaml
47+
}
48+
3949
# The most simple "leader election" you've ever seen in your life
4050
elect_leader() {
4151
# Fetch other running instances in ASG
@@ -168,10 +178,7 @@ upload() {
168178
# Initialize server
169179
identify
170180

171-
cat <<EOF >> "/etc/rancher/rke2/config.yaml"
172-
tls-san:
173-
- ${server_url}
174-
EOF
181+
append_config_san
175182

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

0 commit comments

Comments
 (0)