Skip to content

Commit 5309189

Browse files
committed
feat(check): refactor kernel version check into separate script
Signed-off-by: cuisongliu <[email protected]>
1 parent ad7010d commit 5309189

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

deploy/base/kubernetes/v1.28.15/scripts/check.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,5 @@ arch=$(uname -m)
6363
if [[ "$arch" != "x86_64" && "$arch" != "aarch64" ]]; then
6464
error "Host CPU architecture must be AMD64 (x86_64) or AArch64 (aarch64). Current: $arch"
6565
fi
66-
kernel_full=$(uname -r)
67-
if [ "$(ver_ge "$kernel_full" "4.19.57")" -ne 0 ]; then
68-
if [[ "$kernel_full" != *"el8"* && "$kernel_full" != *"el9"* ]]; then
69-
error "Linux kernel must be >= 4.19.57 or an equivalent supported version (for example RHEL8's 4.18). Current: $kernel_full"
70-
fi
71-
fi
66+
bash kernel.sh
7267
logger "check root,port,cri success"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
source common.sh
3+
ver_ge() {
4+
# usage: ver_ge "4.19.57" "4.18"
5+
awk -v a="$1" -v b="$2" 'BEGIN{
6+
split(a,A,"[.-]"); split(b,B,"[.-]");
7+
for(i=1;i<=3;i++){ if(A[i]=="") A[i]=0; if(B[i]=="") B[i]=0 }
8+
for(i=1;i<=3;i++){ if(A[i]>B[i]){print 0; exit} else if(A[i]<B[i]){print 1; exit} }
9+
print 0
10+
}'
11+
}
12+
kernel_full="$(uname -r)" # e.g. 5.14.0-503.14.1.el9_4.x86_64 / 4.18.0-372.32.1.el8_6.x86_64
13+
kernel_ver="${kernel_full%%-*}" # 只取纯版本号:5.14.0 / 4.18.0
14+
15+
# 读取发行版信息
16+
os_id=""; os_ver="";
17+
if [ -r /etc/os-release ]; then
18+
. /etc/os-release
19+
os_id="${ID:-}"; os_ver="${VERSION_ID:-}" # e.g. 8.6 / 9.4 / 20.03
20+
fi
21+
22+
# 发行版家族
23+
is_rhel_like=false
24+
case "$os_id" in
25+
rhel|rocky|almalinux|centos|ol) is_rhel_like=true ;;
26+
esac
27+
28+
is_euler_like=false
29+
case "$os_id" in
30+
euleros|EulerOS|openEuler) is_euler_like=true ;;
31+
esac
32+
33+
ok=false
34+
35+
# 条件1:通用内核线
36+
if ver_ge "$kernel_ver" "5.10"; then
37+
ok=true
38+
39+
# 条件2:RHEL-like 且 OS 版本 >= 8.6(含 9.x),并且内核 >= 4.18
40+
elif $is_rhel_like && ver_ge "${os_ver:-0}" "8.6" && ver_ge "$kernel_ver" "4.18"; then
41+
ok=true
42+
43+
# 条件3(可选):EulerOS/openEuler 版本 >= 20.03 且内核 >= 4.18
44+
elif $is_euler_like && ver_ge "${os_ver:-0}" "20.03" && ver_ge "$kernel_ver" "4.18"; then
45+
ok=true
46+
fi
47+
48+
if [ "$ok" != true ]; then
49+
error "Linux kernel must be >= 5.10 OR vendor-backed equivalent (e.g., RHEL >= 8.6 with 4.18+, EulerOS/openEuler >= 20.03 with 4.18+). Current: $kernel_full (OS: ${ID:-unknown} ${VERSION_ID:-unknown})"
50+
fi
51+
52+
logger "Kernel check passed: $kernel_full (OS: ${ID:-unknown} ${VERSION_ID:-unknown})"

0 commit comments

Comments
 (0)