Keep cluster alive?

This commit is contained in:
ChristopherHX
2026-03-19 10:31:35 +00:00
parent a21154e3a6
commit 86c8067beb

View File

@ -17,90 +17,56 @@ jobs:
# Install kubectl # Install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
install kubectl /usr/local/bin/ install kubectl /usr/local/bin/
- name: Debug All
run: |
docker ps -adocker network rm kind || true
docker network ls
docker volume ls
- name: Delete Kind Cluster
run: |
kind delete cluster --name test-cluster-2
- name: Sleep 5s
run: sleep 5
- name: Delete kind network
run: |
docker network rm kind || true
- name: Debug All
run: |
docker ps -a
docker network ls
docker volume ls
- name: Create kind cluster - name: Create kind cluster
run: | run: |
cat > cluster.yml << 'EOF' docker inspect "$KIND_CONTAINER" || kind create cluster --name test-cluster --wait 5m
# three node (two workers) cluster config
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
EOF
kind create cluster --name test-cluster-2 --config cluster.yml
- name: Attach kind control-plane to job network and wait - name: Connect kind to the job container's network and fix kubeconfig
if: always()
run: | run: |
apt-get update && apt-get install -y jq docker.io # 1. Find the Docker network the job container is on
# The job container's hostname is the container ID
JOB_CONTAINER_ID=$(hostname)
NETWORK_NAME=$(docker inspect "$JOB_CONTAINER_ID" \
--format '{{range $k, $v := .NetworkSettings.Networks}}{{$k}}{{end}}')
echo "NETWORK_NAME=$NETWORK_NAME" >> $GITHUB_ENV
JOB_CONTAINER_ID="$(hostname)" echo "Job container network: $NETWORK_NAME"
NETWORK_NAME="$(docker inspect "$JOB_CONTAINER_ID" --format '{{range $k, $v := .NetworkSettings.Networks}}{{$k}}{{end}}')"
echo "Job network: $NETWORK_NAME"
CONTROL_PLANE="test-cluster-2-control-plane" # 2. Get the kind control-plane container name
docker network connect "$NETWORK_NAME" "$CONTROL_PLANE" || true KIND_CONTAINER="test-cluster-control-plane"
KIND_IP="$(docker inspect "$CONTROL_PLANE" --format "{{(index .NetworkSettings.Networks \"$NETWORK_NAME\").IPAddress}}")" echo "KIND_CONTAINER=$KIND_CONTAINER" >> $GITHUB_ENV
echo "Kind IP: $KIND_IP"
# Point kubectl at the control-plane directly # 3. Connect the kind container to the same network
kubectl config set-cluster kind-test-cluster-2 --server="https://${KIND_IP}:6443" docker network connect "$NETWORK_NAME" "$KIND_CONTAINER"
kubectl config set-cluster kind-test-cluster-2 --insecure-skip-tls-verify=true
# Wait for API and nodes # 4. Get the kind container's IP on that network
for i in $(seq 1 120); do KIND_IP=$(docker inspect "$KIND_CONTAINER" \
if kubectl get nodes >/dev/null 2>&1; then --format "{{(index .NetworkSettings.Networks \"$NETWORK_NAME\").IPAddress}}")
break
fi echo "Kind container IP on shared network: $KIND_IP"
echo "Waiting for kind API... ($i/120)"
sleep 2 # 5. Rewrite the kubeconfig to use the kind container's IP
done # kind's API server listens on port 6443 inside the container
kubectl get nodes kubectl config set-cluster kind-test-cluster \
--server="https://${KIND_IP}:6443"
# 6. Since the TLS cert won't match the new IP, use insecure mode
# OR set insecure-skip-tls-verify
kubectl config set-cluster kind-test-cluster \
--insecure-skip-tls-verify=true
- name: Verify cluster access - name: Verify cluster access
if: always()
run: | run: |
kubectl cluster-info kubectl cluster-info
kubectl get nodes kubectl get nodes
kubectl get pods -A kubectl get pods -A
- name: Debug All
if: always()
run: |
docker ps -a
docker network ls
docker volume ls
- name: Delete Kind Cluster - name: Disconnect Kind Network
if: always() if: always()
run: | run: |
kind delete cluster --name test-cluster-2 docker network connect "$NETWORK_NAME" "$KIND_CONTAINER"
- name: Debug All
if: always()
run: |
docker ps -a
docker network ls
docker volume ls