@@ -15,8 +15,8 @@ proxy_http=$4
1515proxy_https=$5
1616proxy_no=$6
1717
18- export PATH=" $PATH :$root_path / usr/bin"
19- export PATH=" $PATH :$root_path / usr/local/bin"
18+ export PATH=" $PATH :$( join_path " $ root_path" " usr/bin" ) "
19+ export PATH=" $PATH :$( join_path " $ root_path" " usr/local/bin" ) "
2020
2121KUBE_VIP_LOC=" /etc/kubernetes/manifests/kube-vip.yaml"
2222
@@ -26,22 +26,49 @@ MAX_RETRIES=3
2626ETCD_HEALTH_TIMEOUT=60
2727RETRY_DELAY=30
2828
29- restart_containerd () {
30- if systemctl cat spectro-containerd > /dev/null 2< & 1; then
31- systemctl restart spectro-containerd
32- fi
29+ # Function to detect containerd socket path
30+ detect_containerd_socket () {
31+ # Common containerd socket paths across different distributions
32+ local possible_paths=(
33+ " /var/run/containerd/containerd.sock"
34+ " /run/containerd/containerd.sock"
35+ " /var/run/dockershim.sock"
36+ " /run/dockershim.sock"
37+ )
38+
39+ # Check common socket paths
40+ for path in " ${possible_paths[@]} " ; do
41+ if [ -S " $path " ]; then
42+ echo " unix://$path "
43+ return 0
44+ fi
45+ done
3346
34- if systemctl cat containerd > /dev/null 2< & 1; then
35- systemctl restart containerd
36- fi
47+ # If nothing found, return default
48+ echo " unix:///var/run/containerd/containerd.sock"
49+ }
50+
51+ # Function to join paths properly, avoiding double slashes
52+ join_path () {
53+ local base_path=" $1 "
54+ local relative_path=" $2 "
55+
56+ # Remove trailing slash from base_path and leading slash from relative_path
57+ base_path=" ${base_path%/ } "
58+ relative_path=" ${relative_path#/ } "
59+
60+ # Join them with a single slash
61+ echo " ${base_path} /${relative_path} "
3762}
3863
3964# Function to wait for static pods to be created and running
4065wait_for_static_pods () {
4166 local timeout=$1
4267 local start_time=$( date +%s)
68+ local containerd_socket=$( detect_containerd_socket)
4369
4470 echo " Waiting for static pods to be created and running..."
71+ echo " Using containerd socket: $containerd_socket "
4572
4673 # Check if crictl is available
4774 if ! command -v crictl > /dev/null 2>&1 ; then
@@ -63,8 +90,8 @@ wait_for_static_pods() {
6390 # Check if all required static pod manifests exist
6491 if [ -f /etc/kubernetes/manifests/etcd.yaml ] && [ -f /etc/kubernetes/manifests/kube-apiserver.yaml ] && [ -f /etc/kubernetes/manifests/kube-controller-manager.yaml ] && [ -f /etc/kubernetes/manifests/kube-scheduler.yaml ]; then
6592 # Check if etcd container is running
66- local etcd_container_id=$( crictl ps --name etcd --quiet 2> /dev/null)
67- if [ -n " $etcd_container_id " ] && crictl ps --id " $etcd_container_id " --format table | grep -q " Running" ; then
93+ local etcd_container_id=$( crictl --runtime-endpoint= " $containerd_socket " ps --name etcd --quiet 2> /dev/null)
94+ if [ -n " $etcd_container_id " ] && crictl --runtime-endpoint= " $containerd_socket " ps --id " $etcd_container_id " | grep -q " Running" ; then
6895 echo " Static pods are running, waiting additional time for etcd to stabilize..."
6996 sleep 10
7097 return 0
@@ -81,6 +108,7 @@ wait_for_static_pods() {
81108check_etcd_health_if_available () {
82109 local timeout=$1
83110 local start_time=$( date +%s)
111+ local containerd_socket=$( detect_containerd_socket)
84112
85113 # Check if etcdctl is available
86114 if ! command -v etcdctl > /dev/null 2>&1 ; then
@@ -95,11 +123,12 @@ check_etcd_health_if_available() {
95123 fi
96124
97125 echo " Checking etcd health with etcdctl..."
126+ echo " Using containerd socket: $containerd_socket "
98127
99128 while [ $(( $(date +% s) - start_time)) -lt $timeout ]; do
100129 # Check if etcd container is running
101- local etcd_container_id=$( crictl ps --name etcd --quiet 2> /dev/null)
102- if [ -n " $etcd_container_id " ] && crictl ps --id " $etcd_container_id " --format table | grep -q " Running" ; then
130+ local etcd_container_id=$( crictl --runtime-endpoint= " $containerd_socket " ps --name etcd --quiet 2> /dev/null)
131+ if [ -n " $etcd_container_id " ] && crictl --runtime-endpoint= " $containerd_socket " ps --id " $etcd_container_id " | grep -q " Running" ; then
103132 # Try to connect to local etcd directly
104133 if timeout 10s etcdctl endpoint health --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key > /dev/null 2>&1 ; then
105134 echo " etcd is healthy"
@@ -130,32 +159,38 @@ cleanup_cluster_state() {
130159 fi
131160}
132161
162+ restart_containerd () {
163+ if systemctl cat containerd > /dev/null 2< & 1; then
164+ systemctl restart containerd
165+ fi
166+ }
167+
133168do_kubeadm_reset () {
134- if [ -S /run/spectro/containerd/containerd.sock ]; then
135- kubeadm reset -f --cri-socket unix:///run/spectro/containerd/containerd.sock --cleanup-tmp-dir
169+ local containerd_socket=$( detect_containerd_socket)
170+
171+ # Check if the detected socket exists
172+ local socket_path=" ${containerd_socket# unix:// } "
173+ if [ -S " $socket_path " ]; then
174+ kubeadm reset -f --cri-socket " $containerd_socket " --cleanup-tmp-dir
136175 else
137176 kubeadm reset -f --cleanup-tmp-dir
138177 fi
139178 iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X && rm -rf /etc/kubernetes/etcd /etc/kubernetes/manifests /etc/kubernetes/pki
140- rm -rf " $root_path " /etc/cni/net.d
141- if [ -f /run/systemd/system/etc-cni-net.d.mount ]; then
142- mkdir -p " $root_path " /etc/cni/net.d
143- systemctl restart etc-cni-net.d.mount
144- fi
179+ rm -rf " $( join_path " $root_path " " etc/cni/net.d" ) "
145180 systemctl daemon-reload
146181 restart_containerd
147182}
148183
149184backup_kube_vip_manifest_if_present () {
150185 if [ -f " $KUBE_VIP_LOC " ] && [ " $NODE_ROLE " != " worker" ]; then
151- cp $KUBE_VIP_LOC " $root_path " / opt/kubeadm/kube-vip.yaml
186+ cp $KUBE_VIP_LOC " $( join_path " $ root_path" " opt/kubeadm/kube-vip.yaml" ) "
152187 fi
153188}
154189
155190restore_kube_vip_manifest_after_reset () {
156- if [ -f " $root_path / opt/kubeadm/kube-vip.yaml" ] && [ " $NODE_ROLE " != " worker" ]; then
157- mkdir -p " $root_path " / etc/kubernetes/manifests
158- cp " $root_path " / opt/kubeadm/kube-vip.yaml $KUBE_VIP_LOC
191+ if [ -f " $( join_path " $ root_path" " opt/kubeadm/kube-vip.yaml" ) " ] && [ " $NODE_ROLE " != " worker" ]; then
192+ mkdir -p " $( join_path " $ root_path" " etc/kubernetes/manifests" ) "
193+ cp " $( join_path " $ root_path" " opt/kubeadm/kube-vip.yaml" ) " $KUBE_VIP_LOC
159194 fi
160195}
161196
@@ -167,9 +202,9 @@ attempt_kubeadm_join() {
167202 echo " Attempting kubeadm join (attempt $attempt /$max_retries )"
168203
169204 if [ " $PROXY_CONFIGURED " = true ]; then
170- HTTP_PROXY=$proxy_http http_proxy=$proxy_http HTTPS_PROXY=$proxy_https https_proxy=$proxy_https NO_PROXY=$proxy_no no_proxy=$proxy_no kubeadm join --config " $root_path " / opt/kubeadm/kubeadm.yaml --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests -v=5
205+ HTTP_PROXY=$proxy_http http_proxy=$proxy_http HTTPS_PROXY=$proxy_https https_proxy=$proxy_https NO_PROXY=$proxy_no no_proxy=$proxy_no kubeadm join --config " $( join_path " $ root_path" " opt/kubeadm/kubeadm.yaml" ) " --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests -v=5
171206 else
172- kubeadm join --config " $root_path " / opt/kubeadm/kubeadm.yaml --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests -v=5
207+ kubeadm join --config " $( join_path " $ root_path" " opt/kubeadm/kubeadm.yaml" ) " --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests -v=5
173208 fi
174209}
175210
0 commit comments