mirror of
https://gitea.com/gitea/helm-actions.git
synced 2026-04-05 17:23:13 +00:00
Compare commits
8 Commits
a21154e3a6
...
43e1080cd7
| Author | SHA1 | Date | |
|---|---|---|---|
| 43e1080cd7 | |||
| 6945a48d11 | |||
| 91348eb00b | |||
| 24863ef249 | |||
| 62c14d7877 | |||
| 3625cf2ff2 | |||
| 4a82e5d96d | |||
| 86c8067beb |
@ -2,6 +2,8 @@ on: pull_request
|
|||||||
jobs:
|
jobs:
|
||||||
k8s-test:
|
k8s-test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
CLUSTER_NAME: test-cluster
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@ -17,90 +19,58 @@ 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'
|
kind delete cluster test-cluster2
|
||||||
# three node (two workers) cluster config
|
|
||||||
kind: Cluster
|
docker inspect ${CLUSTER_NAME}-control-plane && mkdir -p ~/.kube && kind get kubeconfig --name ${CLUSTER_NAME} > ~/.kube/config || kind create cluster --name ${CLUSTER_NAME} --wait 5m
|
||||||
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}}')
|
||||||
|
|
||||||
JOB_CONTAINER_ID="$(hostname)"
|
echo "NETWORK_NAME=$NETWORK_NAME" >> $GITHUB_ENV
|
||||||
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"
|
echo "Job container network: $NETWORK_NAME"
|
||||||
docker network connect "$NETWORK_NAME" "$CONTROL_PLANE" || true
|
|
||||||
|
|
||||||
KIND_IP="$(docker inspect "$CONTROL_PLANE" --format "{{(index .NetworkSettings.Networks \"$NETWORK_NAME\").IPAddress}}")"
|
# 2. Get the kind control-plane container name
|
||||||
echo "Kind IP: $KIND_IP"
|
KIND_CONTAINER="${CLUSTER_NAME}-control-plane"
|
||||||
|
|
||||||
# Point kubectl at the control-plane directly
|
echo "KIND_CONTAINER=$KIND_CONTAINER" >> $GITHUB_ENV
|
||||||
kubectl config set-cluster kind-test-cluster-2 --server="https://${KIND_IP}:6443"
|
|
||||||
kubectl config set-cluster kind-test-cluster-2 --insecure-skip-tls-verify=true
|
|
||||||
|
|
||||||
# Wait for API and nodes
|
# 3. Connect the kind container to the same network
|
||||||
for i in $(seq 1 120); do
|
docker network connect "$NETWORK_NAME" "$KIND_CONTAINER"
|
||||||
if kubectl get nodes >/dev/null 2>&1; then
|
|
||||||
break
|
# 4. Get the kind container's IP on that network
|
||||||
fi
|
KIND_IP=$(docker inspect "$KIND_CONTAINER" \
|
||||||
echo "Waiting for kind API... ($i/120)"
|
--format "{{(index .NetworkSettings.Networks \"$NETWORK_NAME\").IPAddress}}")
|
||||||
sleep 2
|
|
||||||
done
|
echo "Kind container IP on shared network: $KIND_IP"
|
||||||
kubectl get nodes
|
|
||||||
|
# 5. Rewrite the kubeconfig to use the kind container's IP
|
||||||
|
# kind's API server listens on port 6443 inside the container
|
||||||
|
kubectl config set-cluster kind-${CLUSTER_NAME} \
|
||||||
|
--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-${CLUSTER_NAME} \
|
||||||
|
--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
|
- name: Disconnect Kind Network
|
||||||
if: always()
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
docker ps -a
|
docker network disconnect "$NETWORK_NAME" "$KIND_CONTAINER"
|
||||||
docker network ls
|
|
||||||
docker volume ls
|
|
||||||
|
|
||||||
- name: Delete Kind Cluster
|
|
||||||
if: always()
|
|
||||||
run: |
|
|
||||||
kind delete cluster --name test-cluster-2
|
|
||||||
|
|
||||||
- name: Debug All
|
|
||||||
if: always()
|
|
||||||
run: |
|
|
||||||
docker ps -a
|
|
||||||
docker network ls
|
|
||||||
docker volume ls
|
|
||||||
|
|||||||
Reference in New Issue
Block a user