mirror of
https://gitea.com/gitea/helm-actions.git
synced 2026-04-05 09:10:46 +00:00
72 lines
2.7 KiB
YAML
72 lines
2.7 KiB
YAML
on: pull_request
|
|
jobs:
|
|
k8s-test:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Install Docker CLI, kind, and kubectl
|
|
run: |
|
|
# Install Docker CLI (to talk to the host daemon via the mounted socket)
|
|
apt-get update && apt-get install -y docker.io jq
|
|
|
|
# Install kind
|
|
curl -Lo /usr/local/bin/kind https://kind.sigs.k8s.io/dl/v0.24.0/kind-linux-amd64
|
|
chmod +x /usr/local/bin/kind
|
|
|
|
# Install 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/
|
|
|
|
- name: Cleanup any previous kind cluster (best-effort)
|
|
if: always()
|
|
run: |
|
|
kind delete cluster --name test-cluster || true
|
|
docker ps -a --filter "name=test-cluster" -q | xargs -r docker rm -f || true
|
|
docker network ls --filter "name=kind" -q | xargs -r docker network rm || true
|
|
|
|
- name: Create kind cluster
|
|
run: |
|
|
kind create cluster --name test-cluster
|
|
|
|
- name: Attach kind control-plane to job network and wait
|
|
run: |
|
|
apt-get update && apt-get install -y jq docker.io
|
|
|
|
JOB_CONTAINER_ID="$(hostname)"
|
|
NETWORK_NAME="$(docker inspect "$JOB_CONTAINER_ID" --format '{{range $k, $v := .NetworkSettings.Networks}}{{$k}}{{end}}')"
|
|
echo "Job network: $NETWORK_NAME"
|
|
|
|
CONTROL_PLANE="test-cluster-control-plane"
|
|
docker network connect "$NETWORK_NAME" "$CONTROL_PLANE" || true
|
|
|
|
KIND_IP="$(docker inspect "$CONTROL_PLANE" --format "{{(index .NetworkSettings.Networks \"$NETWORK_NAME\").IPAddress}}")"
|
|
echo "Kind IP: $KIND_IP"
|
|
|
|
# Point kubectl at the control-plane directly
|
|
kubectl config set-cluster kind-test-cluster --server="https://${KIND_IP}:6443"
|
|
kubectl config set-cluster kind-test-cluster --insecure-skip-tls-verify=true
|
|
|
|
# Wait for API and nodes
|
|
for i in $(seq 1 120); do
|
|
if kubectl get nodes >/dev/null 2>&1; then
|
|
break
|
|
fi
|
|
echo "Waiting for kind API... ($i/120)"
|
|
sleep 2
|
|
done
|
|
kubectl get nodes
|
|
|
|
- name: Verify cluster access
|
|
run: |
|
|
kubectl cluster-info
|
|
kubectl get nodes
|
|
kubectl get pods -A
|
|
|
|
- name: Cleanup kind cluster (best-effort)
|
|
if: always()
|
|
run: |
|
|
kind delete cluster --name test-cluster || true
|
|
docker ps -a --filter "name=test-cluster" -q | xargs -r docker rm -f || true
|
|
docker network ls --filter "name=kind" -q | xargs -r docker network rm || true
|