Skip to content

Commit 4ca4d2b

Browse files
author
secus217
authored
feat(ci): add Kubernetes support to integration test workflow - Install kubectl and Minikube in CI environment - Configure Minikube cluster with Docker driver - Create test namespace and configure kubeconfig - Add Kubernetes environment variables for tests - Add verification step for K8s connectivity - Include Minikube cleanup in post-test steps - Add debug logs for K8s troubleshooting on failure
1 parent 3fe4a75 commit 4ca4d2b

1 file changed

Lines changed: 103 additions & 1 deletion

File tree

.github/workflows/integration-tests.yml

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Here's the updated workflow with English comments only:
2+
3+
```yaml
14
name: Integration Tests
25
36
on:
@@ -60,7 +63,12 @@ jobs:
6063
${{ runner.os }}-cargo-
6164
6265
- name: Install SQLx CLI
63-
run: cargo install sqlx-cli --no-default-features --features postgres
66+
run: |
67+
if ! command -v sqlx &> /dev/null; then
68+
cargo install sqlx-cli --no-default-features --features postgres
69+
else
70+
echo "SQLx CLI already installed"
71+
fi
6472
6573
- name: Set up Python
6674
uses: actions/setup-python@v4
@@ -73,6 +81,62 @@ jobs:
7381
pip install --upgrade pip
7482
pip install -r tests/requirements.txt
7583
84+
# ===== KUBERNETES SETUP SECTION =====
85+
- name: Install kubectl
86+
run: |
87+
echo "Installing kubectl..."
88+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
89+
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
90+
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
91+
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
92+
kubectl version --client
93+
rm -f kubectl kubectl.sha256
94+
95+
- name: Install Minikube
96+
run: |
97+
echo "Installing Minikube..."
98+
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
99+
sudo install minikube-linux-amd64 /usr/local/bin/minikube
100+
rm -f minikube-linux-amd64
101+
minikube version
102+
103+
- name: Start Minikube
104+
run: |
105+
echo "Starting Minikube with Docker driver..."
106+
# Start minikube with specific configuration for CI
107+
minikube start \
108+
--driver=docker \
109+
--kubernetes-version=v1.28.3 \
110+
--memory=4096 \
111+
--cpus=2 \
112+
--disk-size=20g \
113+
--wait=all \
114+
--wait-timeout=5m
115+
116+
# Wait for cluster to be ready
117+
echo "Waiting for Minikube cluster to be ready..."
118+
minikube status
119+
kubectl cluster-info
120+
kubectl get nodes
121+
122+
- name: Configure Kubernetes environment
123+
run: |
124+
echo "Configuring Kubernetes environment..."
125+
# Set kubeconfig
126+
export KUBECONFIG=$HOME/.kube/config
127+
echo "KUBECONFIG=$HOME/.kube/config" >> $GITHUB_ENV
128+
129+
# Create test namespace
130+
kubectl create namespace test || true
131+
kubectl config set-context --current --namespace=test
132+
133+
# Show cluster info
134+
echo "Kubernetes cluster info:"
135+
kubectl version
136+
kubectl get namespaces
137+
kubectl get pods --all-namespaces
138+
# ===== END KUBERNETES SETUP =====
139+
76140
- name: Build Rust application
77141
run: |
78142
# Use offline mode for SQLx to avoid database dependency during compilation
@@ -97,11 +161,21 @@ jobs:
97161
# Override specific variables for GitHub Actions environment
98162
echo "DATABASE_URL=postgresql://postgres:password@localhost:5432/container_engine_test" >> $GITHUB_ENV
99163
echo "REDIS_URL=redis://localhost:6379" >> $GITHUB_ENV
164+
165+
# Add Kubernetes-specific environment variables
166+
echo "KUBERNETES_ENABLED=true" >> $GITHUB_ENV
167+
echo "KUBERNETES_NAMESPACE=test" >> $GITHUB_ENV
168+
echo "KUBERNETES_IN_CLUSTER=false" >> $GITHUB_ENV
100169
101170
- name: Run database migrations
102171
run: |
103172
sqlx migrate run --database-url postgresql://postgres:password@localhost:5432/container_engine_test
104173
174+
- name: Prepare SQLx offline data
175+
run: |
176+
export DATABASE_URL=postgresql://postgres:password@localhost:5432/container_engine_test
177+
cargo sqlx prepare
178+
105179
- name: Start Container Engine server in background
106180
run: |
107181
# Use offline mode for SQLx and start server
@@ -112,11 +186,32 @@ jobs:
112186
# Wait for server to be ready (using port 3001 for integration tests)
113187
timeout 60 bash -c 'until curl -f http://localhost:3001/health; do sleep 2; done'
114188
189+
- name: Verify Kubernetes connectivity
190+
run: |
191+
echo "Verifying Container Engine can connect to Kubernetes..."
192+
# This would be where you verify your app can talk to K8s
193+
kubectl auth can-i get pods --namespace=test
194+
115195
# - name: Run integration tests
116196
# run: |
117197
# python -m pytest tests/integrate/ -v --tb=short --durations=10
118198
# timeout-minutes: 15
119199
200+
- name: Show logs on failure
201+
if: failure()
202+
run: |
203+
echo "=== Server logs ==="
204+
if [ -f server.pid ]; then
205+
ps aux | grep $(cat server.pid) || echo "Server process not found"
206+
fi
207+
208+
echo "=== Minikube logs ==="
209+
minikube logs --lines=50
210+
211+
echo "=== Kubernetes pod logs ==="
212+
kubectl get pods --all-namespaces
213+
kubectl describe pods --all-namespaces
214+
120215
- name: Stop server
121216
if: always()
122217
run: |
@@ -125,6 +220,12 @@ jobs:
125220
rm server.pid
126221
fi
127222
223+
- name: Stop Minikube
224+
if: always()
225+
run: |
226+
minikube stop || true
227+
minikube delete || true
228+
128229
# - name: Upload test results
129230
# if: always()
130231
# uses: actions/upload-artifact@v4
@@ -145,3 +246,4 @@ jobs:
145246
# else
146247
# echo "❌ Some tests failed. Check the logs above." >> $GITHUB_STEP_SUMMARY
147248
# fi
249+
```

0 commit comments

Comments
 (0)