Skip to content

Commit 60a832f

Browse files
shankarsrinivas1ipsita-npgsybacharan
authored
changes to support rke2 start only first time (#22)
Co-authored-by: ipsita-npg <[email protected]> Co-authored-by: sybacharan <[email protected]>
1 parent b2c921d commit 60a832f

File tree

8 files changed

+125
-58
lines changed

8 files changed

+125
-58
lines changed

.github/workflows/pre-merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
fail-fast: false
7272
matrix:
7373
project_folder: ${{ fromJson(needs.pre-checks.outputs.filtered_projects) }}
74-
uses: open-edge-platform/orch-ci/.github/workflows/pre-merge.yml@main
74+
uses: open-edge-platform/orch-ci/.github/workflows/pre-merge.yml@zizmor_test
7575
with:
7676
run_security_scans: false
7777
run_version_check: true

common.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ $(VENV_NAME): requirements.txt
4444
SH_FILES := $(shell find . -type f \( -name '*.sh' \) ! -path './cluster_installers/install.sh' -print)
4545
shellcheck: ## lint shell scripts with shellcheck
4646
shellcheck --version
47-
shellcheck -x -S style $(SH_FILES) >> shellcheck_report.txt
47+
shellcheck -x -S style $(SH_FILES)
4848

4949
# https://pypi.org/project/reuse/
5050
license: $(VENV_NAME) ## Check licensing with the reuse tool

standalone-node/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.36
1+
1.0.37

standalone-node/cluster_installers/sen-rke2-installer.sh

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# SPDX-FileCopyrightText: (C) 2025 Intel Corporation
33
# SPDX-License-Identifier: Apache-2.0
4-
4+
# shellcheck disable=all
55

66
RKE_INSTALLER_PATH=/"${1:-/tmp/rke2-artifacts}"
77
# for basic testing on a coder setup
@@ -116,42 +116,6 @@ else
116116
fi
117117

118118
# Start RKE2
119-
# Check RKE2 start first time or after reboot
120-
IPCHECK="/var/lib/rancher/ip.log"
121-
if [ -f "$IPCHECK" ]; then
122-
# Check if the IP address changes, if changes print the banner
123-
host_prev_ip=$(cat "$IPCHECK")
124-
125-
# Get the system ip
126-
pub_inerface_name=$(route | grep '^default' | grep -o '[^ ]*$')
127-
host_ip=$(ifconfig "${pub_inerface_name}" | grep 'inet ' | awk '{print $2}')
128-
129-
if [[ "$host_ip" != "$host_prev_ip" ]]; then
130-
echo "IP changed"
131-
CHANGE_MSG="Warning: The Edge Node IP("$host_ip") has changed since RKE2 install!"
132-
banner="
133-
================================================================================
134-
Edge Microvisor Toolkit - cluster bring up problem
135-
136-
****Looks the IP address of the system chnaged since RKE2 install*****
137-
138-
OLD RKE2 cluster IP "$host_prev_ip"
139-
NEW RKE2 cluster IP "$host_ip"
140-
141-
IP address of the Node:
142-
"$host_prev_ip" - Ensure IP address is persistent across the reboot!
143-
See: https://ranchermanager.docs.rancher.com/getting-started
144-
/installation-and-upgrade/installation-requirements#node-ip-
145-
addresses $CHANGE_MSG
146-
147-
=================================================================================
148-
"
149-
# Print the banner
150-
echo "$banner" | sudo tee /dev/tty0
151-
else
152-
CHANGE_MSG="IP address remained same after reboot."
153-
fi
154-
fi
155119
echo "$(date): Starting RKE2 4/13" | sudo tee -a /var/log/cluster-init.log | sudo tee /dev/tty0
156120
sudo systemctl enable --now rke2-server.service
157121

@@ -243,6 +207,15 @@ IPCHECK="/var/lib/rancher/ip.log"
243207
if [ ! -f "$IPCHECK" ]; then
244208
echo "$IP" | sudo tee "$IPCHECK"
245209
fi
210+
211+
# Add rke2 installation flag, so that on next reboot it will not start again from begining.
212+
213+
RKE2_STATUS="/var/lib/rancher/rke2_status"
214+
215+
if [ ! -f "$RKE2_STATUS" ]; then
216+
echo "success" | sudo tee "$RKE2_STATUS"
217+
fi
218+
246219
# Print banner
247220

248221
banner="
@@ -258,7 +231,7 @@ IP address of the Node:
258231
$IP - Ensure IP address is persistent across the reboot!
259232
See: https://ranchermanager.docs.rancher.com/getting-started
260233
/installation-and-upgrade/installation-requirements#node-ip-
261-
addresses $CHANGE_MSG
234+
addresses
262235
263236
To access and view the cluster's pods run:
264237
source /etc/environment
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
# SPDX-FileCopyrightText: (C) 2025 Intel Corporation
33
# SPDX-License-Identifier: Apache-2.0
4+
# shellcheck disable=all
45

56
# NTP Time Sync Configuration
67
ntp:
@@ -16,23 +17,19 @@ runcmd:
1617
1718
iptables -A INPUT -p tcp -j ACCEPT
1819
19-
# Start the K8* scripts
20-
mkdir -p /tmp/rke2-artifacts/
21-
tar -xf /opt/sen-rke2-package.tar.gz -C /tmp/rke2-artifacts/
20+
# Start the K8* scripts only once
21+
if [ ! -f "/var/lib/rancher/rke2_status" ]; then
22+
mkdir -p /tmp/rke2-artifacts/
23+
tar -xf /opt/sen-rke2-package.tar.gz -C /tmp/rke2-artifacts/
2224
23-
cd /tmp/rke2-artifacts/
25+
cd /tmp/rke2-artifacts/
2426
25-
chmod +x sen-rke2-installer.sh
27+
chmod +x sen-rke2-installer.sh
2628
27-
bash sen-rke2-installer.sh
28-
29-
# Activate the USB device
30-
efibootmgr | grep '^Boot[0-9A-Fa-f]\{4\}' | while read -r line; do
31-
BOOTNUM=$(echo "$line" | cut -c5-8)
32-
HAS_ASTERISK=$(echo "$line" | grep -o '\*')
33-
34-
if [ -z "$HAS_ASTERISK" ]; then
35-
echo "Enabling disabled boot entry: $BOOTNUM"
36-
efibootmgr -b "$BOOTNUM" -a
37-
fi
38-
done
29+
bash sen-rke2-installer.sh
30+
else
31+
echo "RKE2 is already installed and running. Skipping installation."
32+
cd /etc/cloud/
33+
chmod +x rke2-setup-post-reboot.sh
34+
bash rke2-setup-post-reboot.sh
35+
fi

standalone-node/hook_os/files/install-os.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ EOT
238238

239239
# Copy Edge node logs collection script
240240
cp /etc/scripts/collect-logs.sh /mnt/etc/cloud/
241+
cp /etc/scripts/rke2-setup-post-reboot.sh /mnt/etc/cloud/
241242

242243
umount /mnt
243244
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
3+
# SPDX-FileCopyrightText: (C) 2025 Intel Corporation
4+
# SPDX-License-Identifier: Apache-2.0
5+
# shellcheck disable=all
6+
7+
IPCHECK="/var/lib/rancher/ip.log"
8+
# Check if the IP address changes, if changes print the banner
9+
host_prev_ip=$(cat "$IPCHECK")
10+
11+
# Get the system ip
12+
while [ true ]
13+
do
14+
pub_inerface_name=$(route | grep '^default' | grep -o '[^ ]*$')
15+
if [ -z "$pub_inerface_name" ]; then
16+
sleep 3
17+
else
18+
host_ip=$(ifconfig "${pub_inerface_name}" | grep 'inet ' | awk '{print $2}')
19+
break
20+
fi
21+
done
22+
if [[ "$host_ip" != "$host_prev_ip" ]]; then
23+
echo "IP changed"
24+
CHANGE_MSG="Warning: The Edge Node IP($host_ip) has changed since RKE2 install!"
25+
banner="
26+
================================================================================
27+
Edge Microvisor Toolkit - cluster bring up problem
28+
29+
****Looks the IP address of the system chnaged since RKE2 install*****
30+
31+
OLD RKE2 cluster IP $host_prev_ip
32+
NEW RKE2 cluster IP $host_ip
33+
34+
IP address of the Node:
35+
$host_prev_ip - Ensure IP address is persistent across the reboot!
36+
See: https://ranchermanager.docs.rancher.com/getting-started
37+
/installation-and-upgrade/installation-requirements#node-ip-
38+
addresses $CHANGE_MSG
39+
40+
=================================================================================
41+
"
42+
# Print the banner
43+
sleep 10
44+
echo "$banner" | sudo tee /dev/tty0
45+
else
46+
CHANGE_MSG="IP address remained same after reboot."
47+
while [ true ]
48+
do
49+
rke2_status=$(systemctl is-active rke2-server)
50+
if [[ "$rke2_status" == "active" ]]; then
51+
52+
echo "Waiting for all extensions to complete the deployment..." | sudo tee /dev/tty0
53+
while sudo -E KUBECONFIG=/etc/rancher/rke2/rke2.yaml /var/lib/rancher/rke2/bin/kubectl get pods --all-namespaces --field-selector=status.phase!=Running,status.phase!=Succeeded --no-headers | grep -q .; do
54+
echo "Some pods are still not ready. Checking again in 5 seconds..." | sudo tee /dev/tty0
55+
sleep 5
56+
done
57+
break
58+
else
59+
echo "Waiting for rke2 services to running state,please wait checking again in few seconds" | sudo tee /dev/tty0
60+
sleep 30
61+
fi
62+
done
63+
64+
# Print banner
65+
66+
banner="
67+
===================================================================
68+
Edge Microvisor Toolkit - cluster bringup complete
69+
Logs located at:
70+
/var/log/cluster-init.log
71+
72+
For RKE2 logs run:
73+
sudo journalctl -fu rke2-server
74+
75+
IP address of the Node:
76+
$IP - Ensure IP address is persistent across the reboot!
77+
See: https://ranchermanager.docs.rancher.com/getting-started
78+
/installation-and-upgrade/installation-requirements#node-ip-
79+
addresses $CHANGE_MSG
80+
81+
To access and view the cluster's pods run:
82+
source /etc/environment
83+
export KUBECONFIG
84+
kubectl get pods -A
85+
86+
KUBECONFIG available at:
87+
/etc/rancher/rke2/rke2.yaml
88+
===================================================================
89+
"
90+
# Print the banner
91+
echo "$banner" | sudo tee /dev/tty0
92+
fi

standalone-node/hook_os/hook-os.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ files:
195195
source: "files/collect-logs.sh"
196196
mode: "0777"
197197

198+
- path: etc/scripts/rke2-setup-post-reboot.sh
199+
source: "files/rke2-setup-post-reboot.sh"
200+
mode: "0777"
201+
198202
- path: sbin/setup-dns
199203
source: "files/setup-dns.sh"
200204
mode: "0777"

0 commit comments

Comments
 (0)