Skip to content

Commit

Permalink
feat: implement the functionality of kubeadm reset using a script
Browse files Browse the repository at this point in the history
Signed-off-by: baoyinghai_yewu <[email protected]>
  • Loading branch information
OrangeBao committed Dec 24, 2024
1 parent a2b1928 commit ff900de
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 93 deletions.
2 changes: 2 additions & 0 deletions deploy/virtual-cluster-operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ spec:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
- name: WEB_PORT
value: "5678"
command: ["/bin/bash"]
args:
- "/app/init.sh"
Expand Down
23 changes: 17 additions & 6 deletions hack/k8s-in-k8s/generate_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function GetDirectory() {
}

function GetMasterNodeIPs() {
kubectl get nodes -l node-role.kubernetes.io/master="" -o jsonpath='{range .items[*]}{.status.addresses[?(@.type=="InternalIP")].address}{" "}{end}'
kubectl get nodes -l node-role.kubernetes.io/$1="" -o jsonpath='{range .items[*]}{.status.addresses[?(@.type=="InternalIP")].address}{" "}{end}'
}

# kubelet config name
Expand All @@ -106,13 +106,25 @@ PATH_KUBERNETES=$(GetDirectory $PATH_KUBERNETES_PKI)
HOST_CORE_DNS=$(GetKubeDnsClusterIP)

DOCKER_IMAGE_NGINX="registry.paas/cmss/nginx:1.21.4"
SERVERS=$(GetMasterNodeIPs)

master_lables=("master", "control-plane")

for mlabel in "${master_lables[@]}"; do
SERVERS=$(GetMasterNodeIPs $mlabel)
if [ -z "$SERVERS" ]; then
echo "Warning: No master nodes labeled $mlabel."
else
break
fi
done
if [ -z "$SERVERS" ]; then
echo "Error: No master nodes found or failed to retrieve node IPs."
exit 1
fi

LOCAL_PORT="6443"
LOCAL_IP="127.0.0.1" # [::1]
CRI_SOCKET=$(ps -aux | grep kubelet | grep -- '--container-runtime-endpoint' | awk -F'--container-runtime-endpoint=' '{print $2}' | awk '{print $1}' | sed 's/^unix:\/\///')

echo "#!/usr/bin/env bash
Expand Down Expand Up @@ -140,8 +152,6 @@ PATH_KUBELET_CONF=$PATH_KUBELET_CONF
# name for config file of kubelet
KUBELET_CONFIG_NAME=$KUBELET_CONFIG_NAME
HOST_CORE_DNS=$HOST_CORE_DNS
# kubeadm switch
USE_KUBEADM=false
# Generate kubelet.conf TIMEOUT
KUBELET_CONF_TIMEOUT=30
Expand All @@ -151,6 +161,7 @@ SERVERS=($SERVERS)
LOCAL_PORT="6443"
LOCAL_IP="127.0.0.1" # [::1]
USE_NGINX=true
CRI_SOCKET=$CRI_SOCKET
function GenerateKubeadmConfig() {
echo \"---
Expand All @@ -163,10 +174,10 @@ discovery:
unsafeSkipCAVerification: true
kind: JoinConfiguration
nodeRegistration:
criSocket: /run/containerd/containerd.sock
criSocket: $CRI_SOCKET
kubeletExtraArgs:
container-runtime: remote
container-runtime-endpoint: unix:///run/containerd/containerd.sock
container-runtime-endpoint: unix://$CRI_SOCKET
taints: null\" > \$2/kubeadm.cfg.current
}
Expand Down
Loading

0 comments on commit ff900de

Please sign in to comment.